同步官方yum仓库
[root@yum-server ~]# cat /yum/scripts/
centos6.yum.update.log rsync_centos6_yumrepo.sh
createrepo-wyny.sh rsync_centos6_yumrepo.sh.bak
[root@yum-server yum.repos.d]# cat /yum/scripts/rsync_centos6_yumrepo.sh
#!/bin/bash
/usr/bin/rsync -avrtH --delete --bwlimit=20480 rsync://mirrors.kernel.org/centos/6.9/os/x86_64/Packages/ /yum/repos/centos6/os/x86_64/Packages/ > /yum/log/centos6-os-x86_64.log
createrepo --update /yum/repos/centos6/os/x86_64
/usr/bin/rsync -avrtH --delete --bwlimit=20480 rsync://mirrors.kernel.org/centos/6.9/os/i386/Packages/ /yum/repos/centos6/os/i386/Packages/ > /yum/log/centos6-os-i386.log
createrepo --update /yum/repos/centos6/os/i386
/usr/bin/rsync -avrtH --delete --bwlimit=20480 rsync://mirrors.kernel.org/centos/6.9/updates/x86_64/Packages/ /yum/repos/centos6/updates/x86_64/Packages/ > /yum/log/centos6-updates-x86_64.log
createrepo --update /yum/repos/centos6/updates/x86_64
/usr/bin/rsync -avrtH --delete --bwlimit=20480 rsync://mirrors.kernel.org/centos/6.9/updates/i386/Packages/ /yum/repos/centos6/updates/i386/Packages/ > /yum/log/centos6-updates-i386.log
createrepo --update /yum/repos/centos6/updates/i386
/usr/bin/rsync -avrtH --delete --bwlimit=20480 rsync://mirrors.kernel.org/centos/6.9/extras/x86_64/Packages/ /yum/repos/centos6/extras/x86_64/Packages/ > /yum/log/centos6-extras-x86_64.log
createrepo --update /yum/repos/centos6/extras/x86_64
/usr/bin/rsync -avrtH --delete --bwlimit=20480 rsync://mirrors.kernel.org/centos/6.9/extras/i386/Packages/ /yum/repos/centos6/extras/i386/Packages/ > /yum/log/centos6-extras-i386.log
createrepo --update /yum/repos/centos6/extras/i386
/usr/bin/rsync -avrtH --delete --bwlimit=20480 rsync://mirrors.kernel.org/centos/6.9/centosplus/x86_64/Packages/ /yum/repos/centos6/centosplus/x86_64/Packages/ > /yum/log/centos6-centosplus-x86_64.log
createrepo --update /yum/repos/centos6/centosplus/x86_64
/usr/bin/rsync -avrtH --delete --bwlimit=20480 rsync://mirrors.kernel.org/centos/6.9/centosplus/i386/Packages/ /yum/repos/centos6/centosplus/i386/Packages/ > /yum/log/centos6-centosplus-i386.log
createrepo --update /yum/repos/centos6/centosplus/i386
配置web服务器
显示文件目录
[root@yum-server ~]# cat /etc/nginx/conf.d/yum-server.conf
server {
listen 80;
server_name yum.in.chinawyny.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
root /yum/repos;
location / {
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
编辑yum-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 - hwj
failovermethod=priority
baseurl=http://1.1.1.18/centos6/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates - hwj
failovermethod=priority
baseurl=http://1.1.1.18/centos6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - hwj
failovermethod=priority
baseurl=http://1.1.1.18/centos6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - hwj
failovermethod=priority
baseurl=http://1.1.1.18/centos6/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6
# 自定义包,拷贝至相应目录后需 createrepo --update
[wyny]
name=CentOS-$releasever - Plus - hwj
failovermethod=priority
baseurl=http://1.1.1.18/centos6/wyny/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=0
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6
非官方yum仓库软件包
将软件包下载至相应路径
[root@yum-server ~]# ll /yum/repos/centos6/wyny/x86_64/Packages/
total 916
-rw-r--r--. 1 root root 936884 Apr 13 00:01 nginx-1.12.0-1.el6.ngx.x86_64.rpm
更新repo数据库
[root@yum-server ~]# cat /yum/scripts/createrepo-wyny.sh
#!/bin/bash
createrepo --update /yum/repos/centos6/wyny/i386
createrepo --update /yum/repos/centos6/wyny/x86_64
使用yum源
执行以下命令
#!/bin/bash
cd /etc/yum.repos.d/
gzip ./*
wget http://1.1.1.18/centos6/centos6.repo
yum clean all
yum makecache