CentOS 7 rsync+nginx实现公网yum源
1、实验描述
2、实验环境

3、实验工具
4、实验步骤
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
4.1 安装nginx服务
1. 配置官方源
echo '[nginx]
name=Nginx repo by MineGi
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1' >/etc/yum.repos.d/nginx.repo
cat /etc/yum.repos.d/nginx.repo
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
2. 安装与配置
yum install -y nginx &>/dev/null
echo $?
IP=$(ip a|awk -F '[ /]+' '$NF~/eth0/ {print $3}')
cat >/etc/nginx/conf.d/yum.conf <<EOF
server {
listen 80;
listen [::]:80;
server_name $IP;
location / {
root /usr/share/nginx/html;
autoindex on;
}
}
EOF
cat /etc/nginx/conf.d/yum.conf
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
3. 启动自启动
nginx -t
systemctl enable nginx
systemctl start nginx
netstat -lntup|grep -c nginx
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
4.2 同步公网yum源
1. 创建排除文件
cat >/root/.rsync_exclude.txt <<EOF
centosplus/
cloud/
contrib/
cr/
fasttrack/
isos/
sclo/
storage/
virt/
i386/
debug/
drpms/
EOF
cat /root/.rsync_exclude.txt
cat >/root/.rsync_exclude2.txt <<EOF
atomic/
centosplus/
cloud/
configmanagement/
cr/
dotnet/
fasttrack/
isos/
nfv/
opstools/
paas/
rt/
sclo/
storage/
virt/
debug/
drpms/
EOF
cat /root/.rsync_exclude2.txt
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
2. 手动执行
/usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude2.txt \
rsync://rsync.mirrors.ustc.edu.cn/centos/7.6.1810 /usr/share/nginx/html/centos
/usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude.txt \
rsync://rsync.mirrors.ustc.edu.cn/centos/6.10 /usr/share/nginx/html/centos
/usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude.txt \
rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64 /usr/share/nginx/html/epel/7/
/usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude.txt \
rsync://rsync.mirrors.ustc.edu.cn/epel/6/x86_64 /usr/share/nginx/html/epel/6/
/usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude2.txt \
rsync://rsync.mirrors.ustc.edu.cn/centos/7 /usr/share/nginx/html/centos
/usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude.txt \
rsync://rsync.mirrors.ustc.edu.cn/centos/6 /usr/share/nginx/html/centos
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
3. 定时任务
crontab -e
30 21 * * * /usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude2.txt rsync://rsync.mirrors.ustc.edu.cn/centos/7.6.1810 /usr/share/nginx/html/centos &>/dev/null
00 22 * * * /usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude.txt rsync://rsync.mirrors.ustc.edu.cn/centos/6.10 /usr/share/nginx/html/centos &>/dev/null
00 21 * * * /usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude.txt rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64 /usr/share/nginx/html/epel/7/ &>/dev/null
30 20 * * * /usr/bin/rsync -zaP --exclude-from /root/.rsync_exclude.txt rsync://rsync.mirrors.ustc.edu.cn/epel/6/x86_64 /usr/share/nginx/html/epel/6/ &>/dev/null
crontab -l
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
4. 验证结果
1. 文件
rm -f /usr/share/nginx/html/*.html
cd /usr/share/nginx/html/ && ls
du -smh centos epel
cd centos && ll
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
2. 结果
curl -s -o /etc/yum.repos.d/CentOS-Base.repo \
http://mirrors.aliyun.com/repo/Centos-7.repo
curl -s -o /etc/yum.repos.d/epel.repo \
http://mirrors.aliyun.com/repo/epel-7.repo
echo '10.0.0.10 mirrors.aliyun.com' >>/etc/hosts
tail -1 /etc/hosts
rpm -e --nodeps bc
rpm -qa bc
yum install -y bc &>/dev/null
rpm -qa bc
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
4.3 开启下游同步
cat >/etc/rsyncd.conf <<EOF
#rsync server
uid = nginx
gid = nginx
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = true
list = true
hosts allow = 0.0.0.0/0
[centos]
path = /usr/share/nginx/html/centos
[epel]
path = /usr/share/nginx/html/epel
EOF
cat /etc/rsyncd.conf
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
![其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP 其他综合-CentOS 7 rsync+nginx实现公网yum源-LMLPHP]()
今天你学习了吗?若有疑问,请留言、私信或加QQ群:647033350,大家一起进步吧!