yum 源服务器搭建
基础软件安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25//修改主机名
[root@localhost ~]# echo yum |tee /etc/hostname
[root@localhost ~]# hostname yum
[root@localhost ~]# $SHELL
//安装基础软件包
[root@yum ~]# yum -y install epel-release
[root@yum ~]# yum -y install gcc gcc-c++ make cmake bison libtool autoconf automake zip unzip bzip2 zlib zlib-devel openssl openssl-devel pcre pcre-devel bison-devel ncurses-devel tcl tcl-devel perl-Digest-SHA1 GeoIP GeoIP-devel gperftools gperftools-devel libatomic_ops-devel gtest gtest-devel glibc-devel unixODBC-devel fop libperl libpython readline readline-devel python2-pip readline readline-devel readline-static openssl openssl-devel openssl-static sqlite-devel bzip2-devel bzip2-libs openldap-devel
[root@yum ~]# yum -y install git lftp ntpdate vim wget telnet dstat tree lrzsz net-tools nmap-ncat nmap sysstat
//关闭selinux
[root@yum ~]# setenforce 0
[root@yum ~]# sed -i s/'SELINUX=enforcing'/'SELINUX=disabled'/g /etc/selinux/config
//关闭防火墙
[root@yum ~]# systemctl stop firewalld.service
[root@yum ~]# systemctl disable firewalld.service
//关闭ntpd服务,定时同步时间
[root@yum ~]# systemctl stop ntpd
[root@yum ~]# systemctl disable ntpd
[root@yum ~]# echo '1 1 * * * /usr/sbin/ntpdate -s cn.pool.ntp.org' | tee /var/spool/cron/root
//创建基础目录
[root@yum ~]# mkdir -p /mnt/{app,data,log,web,ops/{app,data,cron}}安装createrepo
1
2
3[root@yum ~]# yum -y install createrepo
//createrepo主要用来创建yum仓库安装yum-utils
1
2
3[root@yum ~]# yum -y install yum-utils
//yum-utils主要用来使用reposync命令同步安装nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30[root@yum app]# useradd -s /sbin/nologin nginx
[root@yum app]# tar xzf nginx-1.10.2.tar.gz
[root@yum app]# cd nginx-1.10.2
[root@yum nginx-1.10.2]# ./configure \
> --prefix=/mnt/app/nginx \
> --user=nginx \
> --group=nginx \
> --with-select_module \
> --with-poll_module \
> --with-threads \
> --with-file-aio \
> --with-http_ssl_module \
> --with-http_stub_status_module \
> --with-http_v2_module \
> --with-http_realip_module \
> --with-http_addition_module \
> --with-http_geoip_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_auth_request_module \
> --with-http_degradation_module \
> --with-google_perftools_module \
> --with-pcre \
> --with-libatomic
[root@yum nginx-1.10.2]# make -j 2
[root@yum nginx-1.10.2]# make -j 2 install
[root@yum nginx-1.10.2]# mkdir -p /mnt/log/nginx
[root@yum nginx-1.10.2]# chown -R nginx.nginx /mnt/log/nginx
[root@yum nginx-1.10.2]# mkdir /mnt/data/yum.repo
[root@yum nginx-1.10.2]# chown -R nginx.nginx /mnt/data/yum.repo修改nginx配置文件,调试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43[root@yum ~]# vim /mnt/app/nginx/conf/nginx.conf
user nginx;
worker_processes 2;
worker_cpu_affinity 01 10;
worker_rlimit_nofile 65536;
error_log /mnt/log/nginx/nginx_error.log info;
pid /mnt/log/nginx/nginx.pid;
events {
use epoll;
accept_mutex on;
multi_accept on;
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /mnt/log/nginx/nginx_access.log main;
sendfile on;
keepalive_timeout 65 60;
server {
listen 80;
server_name yum.domain.cn;
location / {
root /mnt/data/yum.repo;
index index.html index.htm;
autoindex on; #nginx打开目录浏览功能
autoindex_exact_size on; #显示文件具体大小
autoindex_localtime on; #显示系统时间
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@yum ~]# /mnt/app/nginx/sbin/nginx -c /mnt/app/nginx/conf/nginx.conf -t
[root@yum ~]# /mnt/app/nginx/sbin/nginx -c /mnt/app/nginx/conf/nginx.conf
使用 rsync 进行同步
建立yum同步目录
1
2[root@yum ~]# mkdir -p /mnt/data/yum.repo/{centos,epel}
[root@yum ~]# chmod -R 755 /mnt/data/yum.repo修改nginx index.html配置文件,指向创建的目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47[root@yum ~]# vim /mnt/data/yum.repo/index.html
<!DOCTYPE html>
<html>
<head>
<title>众荟YUM源</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<br/>
<p style="font-weight:bolder;color:green;font-size:16px;">众荟YUM源仓库:
<!-- <font size="3" color="red">众荟YUM源仓库:</fon> <br/> -->
<ul>
<li><a href="http://{yum.domain.com}/centos"><font size="3" color="blue">centos</font></a></li>
<li><a href="http://{yum.domain.com}/epel"><font size="3" color="blue">epel</font></a></li>
<li><a href="http://{yum.domain.com}/wisdom"><font size="3" color="blue">wisdom</font></a></li>
</ul>
</p>
<br/>
<p style="font-weight:bolder;color:green;font-size:12px;">更新命令:
<ul>
<li>centos 6:
<ul>
<li><font size="1" color="blue">rpm --import http://{yum.domain.com}/epel/RPM-GPG-KEY-EPEL-6</font></li>
<li><font size="1" color="blue">curl -o /etc/yum.repos.d/epel.repo http://{yum.domain.com}/epel-6.repo</font></li>
<li><font size="1" color="blue">rpm --import http://{yum.domain.com}/centos/RPM-GPG-KEY-CentOS-6</font></li>
<li><font size="1" color="blue">curl -o /etc/yum.repos.d/CentOS-Base.repo http://{yum.domain.com}/centos-6.repo</font></li>
</ul>
</li>
<li>centos 7:
<ul>
<li><font size="1" color="blue">rpm --import http://{yum.domain.com}/epel/RPM-GPG-KEY-EPEL-7</font></li>
<li><font size="1" color="blue">curl -o /etc/yum.repos.d/epel.repo http://{yum.domain.com}/epel-7.repo</font></li>
<li><font size="1" color="blue">rpm --import http://{yum.domain.com}/centos/RPM-GPG-KEY-CentOS-7</font></li>
<li><font size="1" color="blue">curl -o /etc/yum.repos.d/CentOS-Base.repo http://{yum.domain.com}/centos-7.repo</font></li>
</ul>
</li>
</ul>
</p>
</body>
</html>创建yum源配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119epel-6:
[root@yum ~]# cat /mnt/data/yum.repo/epel-6.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://{yum.domain.com}/epel/6/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
baseurl=http://{yum.domain.com}/epel/6/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
baseurl=http://{yum.domain.com}/epel/6/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=0
------------------------
epel-7:
[root@yum ~]# cat /mnt/data/yum.repo/epel-7.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://{yum.domain.com}/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://{yum.domain.com}/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://{yum.domain.com}/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
------------------------
centos-6:
[root@yum ~]# cat /mnt/data/yum.repo/centos-6.repo
[base]
name=CentOS-6 - Base - {yum.domain.com}
baseurl=http://{yum.domain.com}/centos/6/os/x86_64/
gpgcheck=1
gpgkey=http://{yum.domain.com}/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-6 - Updates - {yum.domain.com}
baseurl=http://{yum.domain.com}/centos/6/updates/x86_64/
gpgcheck=1
gpgkey=http://{yum.domain.com}/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - {yum.domain.com}
baseurl=http://{yum.domain.com}/centos/6/extras/x86_64/
gpgcheck=1
gpgkey=http://{yum.domain.com}/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - {yum.domain.com}
baseurl=http://{yum.domain.com}/centos/6/centosplus/x86_64/
gpgcheck=1
enabled=0
gpgkey=http://{yum.domain.com}/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - {yum.domain.com}
baseurl=http://{yum.domain.com}/centos/6/contrib/x86_64/
gpgcheck=1
enabled=0
gpgkey=http://{yum.domain.com}/centos/RPM-GPG-KEY-CentOS-6
------------------------
centos-7:
[root@yum ~]# cat /mnt/data/yum.repo/centos-7.repo
[base]
name=CentOS-7 - Base
baseurl=http://{yum.domain.com}/centos/7/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-7 - Updates
baseurl=http://{yum.domain.com}/centos/7/updates/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras
baseurl=http://{yum.domain.com}/centos/7/extras/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus
baseurl=http://{yum.domain.com}/centos/7/centosplus/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7同步yum源脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14[root@yum ~]# cat /mnt/ops/cron/yum.rsync.sh
/usr/bin/rsync -av --delete --exclude=debug --exclude=aarch64 --exclude=i386 --exclude=ppc64 --exclude=ppc64le --exclude=SRPMS rsync://mirrors.ustc.edu.cn/epel/{6,7} /mnt/data/yum.repo/epel/
/usr/bin/rsync -av --delete --exclude=debug --exclude=i386 --exclude=isos rsync://mirrors.ustc.edu.cn/centos/{6*,7*} /mnt/data/yum.repo/centos/
curl -o /mnt/data/yum.repo/epel/RPM-GPG-KEY-EPEL-6 http://mirrors.ustc.edu.cn/epel/RPM-GPG-KEY-EPEL-6
curl -o /mnt/data/yum.repo/epel/RPM-GPG-KEY-EPEL-7 http://mirrors.ustc.edu.cn/epel/RPM-GPG-KEY-EPEL-7
curl -o /mnt/data/yum.repo/centos/RPM-GPG-KEY-CentOS-6 http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
curl -o /mnt/data/yum.repo/centos/RPM-GPG-KEY-CentOS-7 http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
[root@yum ~]# crontab -l|grep yum
3 0 * * 6 /mnt/ops/cron/yum.rsync.sh >/dev/null 2>&1
注意: 使用rsync同步时,没有必要在使用createrepo创建仓库了.同步的时候已经默认将repo仓库同步到本地了客户端设置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17[root@localhost ~]# mkdir –p /etc/yum.repos.d/back
[root@localhost ~]# mv /etc/yum.repos.d/* /etc/yum.repos.d/back/
centos 6:
[root@localhost ~]# rpm --import http://yum.jwops.cn/epel/RPM-GPG-KEY-EPEL-6
[root@localhost ~]# curl -o /etc/yum.repos.d/epel.repo http://yum.jwops.cn/epel-6.repo
[root@localhost ~]# rpm --import http://yum.jwops.cn/centos/RPM-GPG-KEY-CentOS-6
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://yum.jwops.cn/centos-6.repo
centos 7:
[root@localhost ~]# rpm --import http://yum.jwops.cn/epel/RPM-GPG-KEY-EPEL-7
[root@localhost ~]# curl -o /etc/yum.repos.d/epel.repo http://yum.jwops.cn/epel-7.repo
[root@localhost ~]# rpm --import http://yum.jwops.cn/centos/RPM-GPG-KEY-CentOS-7
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://yum.jwops.cn/centos-7.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
使用 reposync 进行同步
建立yum同步目录
1
2
3[root@yum ~]# mkdir -p /mnt/data/yum.repo/wisdom/centos/6
[root@yum ~]# mkdir -p /mnt/data/yum.repo/wisdom/centos/7
[root@yum ~]# chmod -R 755 /mnt/data/yum.repo修改nginx index.html配置文件,指向创建的目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23[root@yum ~]# cp /mnt/data/yum.repo/index.html /mnt/data/yum.repo/index.html.bak
[root@yum ~]# vim /mnt/data/yum.repo/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<p style="font-weight:bolder;color:green;font-size:30px;">ALL of the packages in the below:</p>
<br/>
<a href="http://192.168.13.213/centos/Aliyun">Aliyun</a><br/>
These packagers from of CentOS ISO.<br/>
<p style="font-weight:bolder;color:red;font-size:18px;">Please replace the file and fill in the following content:</p>
<p style="font-weight:bolder;color:blue;font-size:15px;">Way: /etc/yum.repos.d/CentOS-Base.repo</p>
</body>
</html>下载centos repo配置文件
1
2
3
4
5[root@yum ~]# wget -O /mnt/ops/cron/Centos-6.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@yum ~]# sed -i s/\$releasever/6/g /mnt/ops/cron/Centos-6.repo
[root@yum ~]# sed -i s/\$basearch/x86_64/g /mnt/ops/cron/Centos-6.repo
[root@yum ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo同步yum源
1
2[root@yum ~]# reposync -c /mnt/ops/cron/Centos-6.repo -d -n -p /mnt/data/yum.repo/wisdom/centos/6/
[root@yum ~]# reposync -p /mnt/data/yum.repo/wisdom/centos/7/软件包手动同步下来后,yum建立仓库
1
2
3
4
5
6
7[root@yum ~]# createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/6/base/ /mnt/data/yum.repo/wisdom/centos/6/base/
[root@yum ~]# createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/6/extras/ /mnt/data/yum.repo/wisdom/centos/6/extras/
[root@yum ~]# createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/6/updates/ /mnt/data/yum.repo/wisdom/centos/6/updates/
[root@yum ~]# createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/7/base/ /mnt/data/yum.repo/wisdom/centos/7/base/
[root@yum ~]# createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/7/extras/ /mnt/data/yum.repo/wisdom/centos/7/extras/
[root@yum ~]# createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/7/updates/ /mnt/data/yum.repo/wisdom/centos/7/updates/编写同步脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17[root@yum ~]# vim /mnt/ops/cron/yum.reposync.sh
reposync -c /mnt/ops/cron/Centos-6.repo -d -n -p /mnt/data/yum.repo/wisdom/centos/6/
createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/6/base/ /mnt/data/yum.repo/wisdom/centos/6/base/
createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/6/extras/ /mnt/data/yum.repo/wisdom/centos/6/extras/
createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/6/updates/ /mnt/data/yum.repo/wisdom/centos/6/updates/
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
reposync -n -p /mnt/data/yum.repo/wisdom/centos/7/
createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/7/base/ /mnt/data/yum.repo/wisdom/centos/7/base/
createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/7/extras/ /mnt/data/yum.repo/wisdom/centos/7/extras/
createrepo -p -d -o /mnt/data/yum.repo/wisdom/centos/7/updates/ /mnt/data/yum.repo/wisdom/centos/7/updates/
#reposync -c /mnt/ops/cron/Centos-7.repo -d -p /mnt/data/yum.repo/wisdom/centos/7/
[root@yum ~]# chmod +x /mnt/ops/cron/yum.reposync.sh
[root@yum ~]# sh /mnt/ops/cron/yum.reposync.sh
[root@yum ~]# echo '1 2 * * * /mnt/ops/cron/yum.reposync.sh >/dev/null 2>&1' |tee -a /var/spool/cron/root创建repo文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51[root@yum ~]# mkdir /mnt/data/yum.repo/repo
//CentOS-6.repo
[root@yum repo]# cat /mnt/data/yum.repo/repo/centos-6.repo
[CentOS_6_base]
name=centos 6 x64
failovermethod=priority
baseurl=http://yum.domain.cn/centos/6/base
enable=1
gpgcheck=0
priority=1
[CentOS_6_updates]
name=centos 6 x64
failovermethod=priority
baseurl=http://yum.domain.cn/centos/6/updates
enable=1
gpgcheck=0
priority=3
[CentOS_6_extras]
name=centos 6 x64
failovermethod=priority
baseurl=http://yum.domain.cn/centos/6/extras
enable=1
gpgcheck=0
priority=5
[root@yum repo]# cat /mnt/data/yum.repo/repo/wisdom-centos-7.repo
[CentOS_7_base]
name=centos 7 x64
failovermethod=priority
baseurl=http://yum.domain.cn/centos/7/base
enable=1
gpgcheck=0
priority=1
[CentOS_7_updates]
name=centos 7 x64
failovermethod=priority
baseurl=http://yum.domain.cn/centos/7/updates
enable=1
gpgcheck=0
priority=3
[CentOS_7_extras]
name=centos 7 x64
failovermethod=priority
baseurl=http://yum.domain.cn/centos/7/extras
enable=1
gpgcheck=0
priority=5客户端安装 yum-plugin-priorities
1
2
3[root@localhost ~]# yum -y install yum-plugin-priorities
//yum-plugin-priorities主要用来控制yum源更新优先级,控制进行yum源检索的先后顺序客户端配置
1
2
3
4
5
6
7
8[root@localhost ~]# mkdir –p /etc/yum.repos.d/back
[root@localhost ~]# mv /etc/yum.repos.d/* /etc/yum.repos.d/back/
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://yum.domain.cn/repo/CentOS-6.repo
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://yum.domain.cn/repo/CentOS-7.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
[root@localhost ~]# yum repolist
YUM rsync public source
1 | [root@yum ~]# mkdir -p /mnt/data/yum.repo/centos |