使用环境
- 服务器处于内网,需要更新
- 网络资源紧张,节约带宽
建立yum目录
mkdir -p /opt/opmgmt/yum
rsync服务器列表
同步脚本
/opt/opmgmt/yum/rsync_centos.sh
#!/bin/bash
repo_root='/opt/opmgmt/yum/centos/'
sync_cmd='rsync -arv --delete-after --delete-excluded'
sync_srv='rsync://mirrors.shu.edu.cn/centos/'
exclude='--exclude [23456]/ --exclude [2345].*/ --exclude i386/ --exclude drpms/ --exclude SCL/ --exclude centosplus/ --exclude contrib/ --exclude cr/ --exclude fasttrack/ --exclude isos/ --exclude virt/ --exclude paas/ --exclude 7.[012]*/ --exclude atomic/ --exclude cloud/ --exclude storage/'
[ -d $repo_root ] && mkdir -p $repo_root
$sync_cmd $exclude $sync_srv $repo_root &
/opt/opmgmt/yum/rsync_epel.sh
#!/bin/bash
repo_root='/opt/opmgmt/yum/epel/'
sync_cmd='rsync -arv --delete-after --delete-excluded'
sync_srv='rsync://mirrors.shu.edu.cn/epel/'
exclude='--exclude [45]*/ --exclude testing/ --exclude SRPMS/ --exclude i386/ --exclude ppc64*/ --exclude aarch64/ --exclude debug/ --exclude=repoview'
[ -d $repo_root ] && mkdir -p $repo_root
$sync_cmd $exclude $sync_srv $repo_root &
cd yum
rsync -avzRHP --delete-after --exclude={'debug/','drpms/'} rsync://hkg.mirror.rackspace.com/epel/7/x86_64/ epel/
rsync -avzRHP --delete-after --exclude={'atomic/','cr/','dotnet/','fasttrack/','isos/','nfv/','opstools/','rt/'} rsync://hkg.mirror.rackspace.com/centos/7/ centos/
计划任务
/etc/cron.d/sync-yum-repo
0 1 * * * root /bin/sh /opt/opmgmt/yum/rsync_centos.sh
0 2 * * * root /bin/sh /opt/opmgmt/yum/rsync_epel.sh
自定义源
yum install createrepo
mkdir -p /opt/opmgmt/yum/custom/x86_64
copy *rpm /opt/opmgmt/yum/custom/x86_64
createrepo -p -d --update /opt/opmgmt/yum/custom/x86_64
nginx服务配置
/etc/nginx/conf.d/yum.conf
server {
listen 192.168.0.100:80;
server_name yum.localhost;
#allow 10.0.1.0/24;
#deny all;
charset utf-8;
access_log /var/log/nginx/$server_name.access.log main;
location / {
root /opt/www/yum;
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
repo文件
/opt/opmgmt/yum/repo/centos.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://yum.localhost/centos/$releasever/os/$basearch
gpgcheck=0
enabled=1
priority=1
[updates]
name=CentOS-$releasever - Updates
baseurl=http://yum.localhost/centos/$releasever/updates/$basearch
gpgcheck=0
enabled=1
priority=1
[extras]
name=CentOS-$releasever - Extras
baseurl=http://yum.localhost/centos/$releasever/extras/$basearch
gpgcheck=0
enabled=1
priority=1
[centos-sclo-sclo]
name=CentOS-$releasever - SCLo sclo
baseurl=http://yum.localhost/centos/$releasever/sclo/$basearch/sclo
gpgcheck=0
enabled=1
priority=2
[centos-sclo-rh]
name=CentOS-$releasever - SCLo rh
baseurl=http://yum.localhost/centos/$releasever/sclo/$basearch/rh
gpgcheck=0
enabled=1
priority=2
另外一种方法
yum install yum-utils
reopsync