docker镜像-rsync+nginx公网yum源

rsync+nginx实现公网yum源

rsync+nginx实现公网yum源

整个过程分3步:

1:nginx提供目录浏览功能

nginx直接yum安装,不废话,直接贴配置文件

[root@oldboyedu ~]# cat /etc/nginx/nginx.conf

worker_processes auto;

events {

worker_connections 1024;

}

http {

include mime.types;

charset utf-8;

default_type application/octet-stream;

sendfile on;

 autoindex on; #开启目录浏览功能

keepalive_timeout 65;

server {

listen 80;

listen [::]:80;

server_name localhost;

location / {

root html;

index index.html index.htm;

}

}

}

2:从上游yum源同步yum源到本地

直接贴定时任务

# rsync centos6 repos

30 21 * * * /usr/bin/rsync -zaP --exclude-from  /usr/share/nginx/html/rsync_exclude2.txt  rsync://rsync.mirrors.ustc.edu.cn/centos/7.4.1708  /usr/share/nginx/html/centos

00 22 * * * /usr/bin/rsync -zaP --exclude-from  /usr/share/nginx/html/rsync_exclude.txt  rsync://rsync.mirrors.ustc.edu.cn/centos/6.9  /usr/share/nginx/html/centos

00 21 * * * /usr/bin/rsync -zaP --exclude-from  /usr/share/nginx/html/rsync_exclude.txt  rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64  /usr/share/nginx/html/epel/7/

30 20 * * * /usr/bin/rsync -zaP --exclude-from  /usr/share/nginx/html/rsync_exclude.txt  rsync://rsync.mirrors.ustc.edu.cn/epel/6/x86_64  /usr/share/nginx/html/epel/6/

从定时任务的配置,可以看出,我同步了centos6、7基础源和epel源,有的同学担心,这样会特别占用空间!是的,如果不启用过滤,全部同步,确实很占用空间!

下面我把rsync里面的--exclude-from文件贴出来,centos6和7稍微不同

centos6
[root@oldboyedu ~]# cat /usr/share/nginx/html/rsync_exclude.txt
centosplus/
cloud/
contrib/
cr/
fasttrack/
isos/
sclo/
storage/
virt/
i386/
debug/
drpms/

centos7
[root@oldboyedu ~]# cat /usr/share/nginx/html/rsync_exclude2.txt
atomic/
centosplus/
cloud/
configmanagement/
cr/
dotnet/
fasttrack/
isos/
nfv/
opstools/
paas/
rt/
sclo/
storage/
virt/
debug/
drpms/

最终4个源全部同步完,并且可用只占了60G左右

img

到这里已经能提供yum服务了,但是无法为下游提供同步服务,于是有了第三步

3:开启rsync --daemon模式

[root@oldboyedu ~]# cat /etc/rsyncd.conf
\#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

到这里,一个公网yum该有的功能都有了!

posted @ 2021-03-06 14:45  上善若水~小辉  阅读(366)  评论(0编辑  收藏  举报