1.目标要求
yum源服务器要自动更新自身源
使用CentOS官方标准源version6和version7的两个版本保持更新
客户端可以直接使用源
国内速度比较快的源服务器
http://centos.ustc.edu.cn/centos/
2.安装server端
关闭防火墙和selinux
[root@localhost ~]# vim /etc/hostname |
yumserver |
[root@localhost ~]# hostnamectl status |
Static hostname: yumserver Icon name: computer-vm Chassis: vm Machine ID: 06490d1675224b898ac71b9ed141cb39 Boot ID: 2a568995acaa4bb2928bdb8e6330ddd3 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 Architecture: x86-64 |
[root@localhost ~]# su - root [root@yumserver ~]# systemctl stop firewalld.service [root@yumserver ~]# systemctl disable firewalld.service |
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service. |
[root@yumserver ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config [root@yumserver ~]# setenforce 0 |
安装nginx软件包
[root@yumserver ~]# yum -y install epel-release [root@yumserver ~]# yum -y install nginx |
Installed: nginx.x86_64 1:1.12.2-1.el7 Dependency Installed: GeoIP.x86_64 0:1.5.0-11.el7 fontconfig.x86_64 0:2.10.95-11.el7 fontpackages-filesystem.noarch 0:1.44-8.el7 gd.x86_64 0:2.0.35-26.el7 gperftools-libs.x86_64 0:2.4-8.el7 libX11.x86_64 0:1.6.5-1.el7 libX11-common.noarch 0:1.6.5-1.el7 libXau.x86_64 0:1.0.8-2.1.el7 libXpm.x86_64 0:3.5.12-1.el7 libjpeg-turbo.x86_64 0:1.2.90-5.el7 libpng.x86_64 2:1.5.13-7.el7_2 libunwind.x86_64 2:1.2-2.el7 libxcb.x86_64 0:1.12-1.el7 libxslt.x86_64 0:1.1.28-5.el7 lyx-fonts.noarch 0:2.2.3-1.el7 nginx-all-modules.noarch 1:1.12.2-1.el7 nginx-filesystem.noarch 1:1.12.2-1.el7 nginx-mod-http-geoip.x86_64 1:1.12.2-1.el7 nginx-mod-http-image-filter.x86_64 1:1.12.2-1.el7 nginx-mod-http-perl.x86_64 1:1.12.2-1.el7 nginx-mod-http-xslt-filter.x86_64 1:1.12.2-1.el7 nginx-mod-mail.x86_64 1:1.12.2-1.el7 nginx-mod-stream.x86_64 1:1.12.2-1.el7 Dependency Updated: openssl.x86_64 1:1.0.2k-8.el7 openssl-libs.x86_64 1:1.0.2k-8.el7 Complete! |
[root@yumserver ~]# find / -name nginx.conf |
/etc/nginx/nginx.conf |
[root@yumserver ~]# vim /etc/nginx/nginx.conf |
autoindex on; #表示自动在index.html的索引打开 autoindex_exact_size on; #表示如果有文件则显示文件大小; autoindex_localtime on; #表示显示更改时间,以点前系统的时间为准; error_page 404 /404.html; |
安装createrepo软件包
安装建yum源仓库的工具,可以用来建立yum仓库
[root@yumserver ~]# yum -y install createrepo yum-utils |
Installed: createrepo.noarch 0:0.9.9-28.el7 Dependency Installed: deltarpm.x86_64 0:3.6-3.el7 libxml2-python.x86_64 0:2.9.1-6.el7_2.3 python-deltarpm.x86_64 0:3.6-3.el7 Dependency Updated: libxml2.x86_64 0:2.9.1-6.el7_2.3 Complete! |
安装yum-plugin-priorities软件包
安装控制yum源更新优先级工具,这个工具可以用来控制进行yum源检索的先后顺序,建议用在client端。
[root@yumserver ~]# yum -y install yum-plugin-priorities |
Installed: yum-plugin-priorities.noarch 0:1.1.31-42.el7 Complete! |
3.配置server端
[root@yumserver /]# find / -name html |
/usr/share/doc/pam-1.1.8/html /usr/share/nginx/html |
[root@yumserver ~]# mkdir -p /usr/share/nginx/html/CentOS-Yum/CentOS6/x86_64 [root@yumserver ~]# mkdir -p /usr/share/nginx/html/CentOS-Yum/CentOS7/x86_64 [root@yumserver ~]# chmod -R +x /usr/share/nginx/html [root@yumserver ~]# vim /usr/share/nginx/html/index.html |
</head> <body> <h1>Welcome to <strong>nginx</strong> on Fedora!</h1> <div class="content"> <p>This page is used to test the proper operation of the <strong>nginx</strong> HTTP server after it has been installed. If you can read this page, it means that the web server installed at this site is working properly.</p> <div class="alert"> <h2>Website Administrator</h2> <div class="content"> <p style="font-weight:bolder;color:green;font-size:30px;">ALL of the packages in the below:</p> <br/> <a href="http://10.9.254.33/Zabbix-Yum/CentOS6">zabbix3.4-centos6</a><br/> These packagers from of Zabbix3.4-Centos6.<br/> <a href="http://10.9.254.33/Zabbix-Yum/CentOS7">zabbix3.4-centos7</a><br/> These packagers from of Zabbix3.4-Centos7.<br/> <a href="http://10.9.254.33/CentOS-Yum/CentOS6">centos6</a><br/> These packagers from of Centos6.<br/> <a href="http://10.9.254.33/CentOS-Yum/CentOS7">centos7</a><br/> These packagers from of Centos7.<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> </div> </div> <div class="logos"> <a href="http://nginx.net/"><img src="nginx-logo.png" alt="[ Powered by nginx ]" width="121" height="32" /></a> <a href="http://fedoraproject.org/"><img src="poweredby.png" alt="[ Powered by Fedora ]" width="88" height="31" /></a> </div> </div> </body> </html> |
[root@yumserver ~]# service nginx restart |
4.配置当前系统yum来源repo文件
备份现有CentOS-Base.repo文件
[root@yumserver ~]# cp -p /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back [root@yumserver ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [root@yumserver ~]# ll /etc/yum.repos.d/CentOS-Base.repo |
下载并查看CentOS-Base.repo文件
[root@yumserver ~]# vim /etc/yum.repos.d/CentOS-Base.repo |
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
|
目前只能是CentOS7的版本的所有yum源,如果需要同步6版本的yum源,将CentOS-Base.repo文件内的7版本号更改为6就可以了。将$releasever替换为6,将$basearch替换为x86_64,将版本7改为6
:1,$s/$releasever/6/g
5.进行同步脚本的创建并执行同步
[root@yumserver ~]# reposync –p /usr/share/nginx/html/CentOS-Yum/CentOS7/x86_64/ [root@yumserver ~]# ls |
anaconda-ks.cfg base extras updates |
[root@yumserver ~]# mv base/ /usr/share/nginx/html/CentOS-Yum/CentOS7/x86_64/ [root@yumserver ~]# mv extras/ /usr/share/nginx/html/CentOS-Yum/CentOS7/x86_64/ [root@yumserver ~]# mv updates/ /usr/share/nginx/html/CentOS-Yum/CentOS7/x86_64/ [root@yumserver ~]# cd /usr/share/nginx/html/CentOS-Yum/CentOS7/x86_64/ [root@yumserver x86_64]# ls |
base extras updates |
[root@yumserver ~]# createrepo -p /usr/share/nginx/html/CentOS-Yum/CentOS7/x86_64/base/Packages/ |
Spawning worker 0 with 4796 pkgs Spawning worker 1 with 4795 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete |
[root@yumserver ~]# createrepo -p /usr/share/nginx/html/CentOS-Yum/CentOS7/x86_64/extras/Packages/ |
Spawning worker 0 with 163 pkgs Spawning worker 1 with 163 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete |
[root@yumserver ~]# createrepo -p /usr/share/nginx/html/CentOS-Yum/CentOS7/x86_64/updates/Packages/ |
Spawning worker 0 with 770 pkgs Spawning worker 1 with 770 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete |
使用同样方法,同步centos6软件包。
[root@yumserver yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [root@yumserver yum.repos.d]# vim /etc/yum.repos.d/CentOS-Base.repo |
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-6 - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/6/os/x86_64/ http://mirrors.aliyuncs.com/centos/6/os/x86_64/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-6 - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/6/updates/x86_64/ http://mirrors.aliyuncs.com/centos/6/updates/x86_64/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=updates gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-6 - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/6/extras/x86_64/ http://mirrors.aliyuncs.com/centos/6/extras/x86_64/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=extras gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages [centosplus] name=CentOS-6 - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/6/centosplus/x86_64/ http://mirrors.aliyuncs.com/centos/6/centosplus/x86_64/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=centosplus gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-6 - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/6/contrib/x86_64/ http://mirrors.aliyuncs.com/centos/6/contrib/x86_64/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=contrib gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 |
将$releasever替换为6,将$basearch替换为x86_64,将版本7改为6 :1,$s/$releasever/6/g |
[root@yumserver yum.repos.d]# yum clean all [root@yumserver yum.repos.d]# yum makecache [root@yumserver yum.repos.d]# yum repolist |
Loaded plugins: fastestmirror, priorities Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com repo id repo name status base CentOS-6 - Base - mirrors.aliyun.com 6,706 extras CentOS-6 - Extras - mirrors.aliyun.com 46 updates CentOS-6 - Updates - mirrors.aliyun.com 834 repolist: 7,586 |
[root@yumserver yum.repos.d]# cd /usr/share/nginx/html/CentOS-Yum/CentOS6/x86_64/ [root@yumserver x86_64]# reposync -p /usr/share/nginx/html/CentOS-Yum/CentOS6/x86_64/ [root@yumserver x86_64]# ls |
base extras updates |
[root@yumserver ~]# createrepo -p /usr/share/nginx/html/CentOS-Yum/CentOS6/x86_64/base/Packages/ |
Spawning worker 0 with 3457 pkgs Spawning worker 1 with 3457 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete |
[root@yumserver ~]# createrepo -p /usr/share/nginx/html/CentOS-Yum/CentOS6/x86_64/extras/Packages/ |
Spawning worker 0 with 23 pkgs Spawning worker 1 with 23 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete |
[root@yumserver ~]# createrepo -p /usr/share/nginx/html/CentOS-Yum/CentOS6/x86_64/updates/Packages/ |
Spawning worker 0 with 417 pkgs Spawning worker 1 with 417 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete |