自建YUM源并同步开源镜像站

部署Nginx

[zhupengfei@sh2-svvl-q911 ~]# sudo vim /etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

[zhupengfei@sh2-svvl-q911 ~]# sudo yum clean all
[zhupengfei@sh2-svvl-q911 ~]# sudo yum makecache
[zhupengfei@sh2-svvl-q911 ~]# sudo yum install nginx -y
[zhupengfei@sh2-svvl-q911 ~]# cp /etc/nginx.conf /etc/nginx.conf.bak # 更改默认80运行端口
[zhupengfei@sh2-svvl-q911 ~]# sudo vim /etc/nginx/conf.d/yum.conf
server {
    listen       80;
    #server_name  mirrors.ponfey.com; # 域名仅内部自建DNS解析使用

    location / {
        root   /data/yum;
        autoindex on;
        autoindex_exact_size on;
        autoindex_localtime on;
    }
}
[zhupengfei@sh2-svvl-q911 ~]# sudo systemctl start nginx && sudo systemctl enable nginx

部署YUM源目录

[zhupengfei@sh2-svvl-q911 ~]# sudo mkdir -p /data/yum/epel/7/x86_64
[zhupengfei@sh2-svvl-q911 ~]# sudo mkdir -p /data/yum/centos/7/extras/x86_64
[zhupengfei@sh2-svvl-q911 ~]# sudo mkdir -p /data/yum/centos/7/updates/x86_64
[zhupengfei@sh2-svvl-q911 ~]# sudo mkdir -p /data/yum/centos/7/os/x86_64
[zhupengfei@sh2-svvl-q911 ~]# sudo mkdir -p /data/yum/centos/7/os/x86_64
[zhupengfei@sh2-svvl-q911 ~]# sudo mkdir -p /data/yum/epel/6/x86_64 # CentOS 6 因生命周期结束,停止维护,陆续各镜像站点也停止同步,没有合适的上游同步源就不建议配置了
[zhupengfei@sh2-svvl-q911 ~]# sudo mkdir -p /data/yum/centos/6/extras/x86_64 # CentOS 6 因生命周期结束,停止维护,陆续各镜像站点也停止同步,没有合适的上游同步源就不建议配置了
[zhupengfei@sh2-svvl-q911 ~]# sudo mkdir -p /data/yum/centos/6/updates/x86_64 # CentOS 6 因生命周期结束,停止维护,陆续各镜像站点也停止同步,没有合适的上游同步源就不建议配置了
[zhupengfei@sh2-svvl-q911 ~]# sudo mkdir -p /data/yum/centos/6/os/x86_64 # CentOS 6 因生命周期结束,停止维护,陆续各镜像站点也停止同步,没有合适的上游同步源就不建议配置了

编写同步YUM源(镜像)脚本

从上游镜像站同步源和镜像到本地,建议根据自己所在网络节点就近寻找上游同步源。

[zhupengfei@sh2-svvl-q911 ~]# sudo vim sync.sh
#!/bin/bash
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64/  /data/yum/epel/7/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/7/extras/x86_64/  /data/yum/centos/7/extras/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/7/updates/x86_64/  /data/yum/centos/7/updates/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/  /data/yum/centos/7/os/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/7/isos/x86_64/  /data/yum/centos/7/os/x86_64 && \
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/epel/6/x86_64/  /data/yum/epel/6/x86_64 && \ # CentOS 6 因生命周期结束,停止维护,陆续各镜像站点也停止同步,没有合适的上游同步源就不建议配置了
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/6/extras/x86_64/  /data/yum/centos/6/extras/x86_64 && \ # CentOS 6 因生命周期结束,停止维护,陆续各镜像站点也停止同步,没有合适的上游同步源就不建议配置了
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/6/updates/x86_64/  /data/yum/centos/6/updates/x86_64 && \ # # CentOS 6 因生命周期结束,停止维护,陆续各镜像站点也停止同步,没有合适的上游同步源就不建议配置了
rsync -avrt rsync://rsync.mirrors.ustc.edu.cn/centos/6/os/x86_64/  /data/yum/centos/6/os/x86_64 # CentOS 6 因生命周期结束,停止维护,陆续各镜像站点也停止同步,没有合适的上游同步源就不建议配置了

# 可以根据实际需要同步更多需要的软件源:pypi、maven、monggodb、saltstack、ceph、docker-ce、zabbix、kubernetes、mysql 等

# 也可以根据实际需要同步更多需要的系统源:openwrt、ubuntu、deepin 等

编写定时同步任务

[zhupengfei@sh2-svvl-q911 ~]# sudo crontab -e
0 1 * * * sh /data/sync.sh &> /tmp/yum.log
[zhupengfei@sh2-svvl-q911 ~]# sudo systemctl restart crond

自建YUM源预览

自建YUM源的使用

CentOS7.repo(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
baseurl=http://mirrors.ponfey.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.ponfey.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.ponfey.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.ponfey.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

epel.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.ponfey.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.ponfey.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.ponfey.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

CentOS6.repo(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 - yum.gogen.cn
baseurl=http://mirrors.ponfey.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.ponfey.com/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates - yum.gogen.cn
baseurl=http://mirrors.ponfey.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.ponfey.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - yum.gogen.cn
baseurl=http://mirrors.ponfey.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.ponfey.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - yum.gogen.cn
baseurl=http://mirrors.ponfey.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.ponfey.com/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - yum.gogen.cn
baseurl=http://mirrors.ponfey.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.ponfey.com/centos/RPM-GPG-KEY-CentOS-6

epel.repo

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://mirrors.ponfey.com/epel/6/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
baseurl=http://mirrors.ponfey.com/epel/6/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
baseurl=http://mirrors.ponfey.com/epel/6/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1
上一篇
下一篇