随着国内使用Linux的氛围日渐浓郁,各个大厂的源也如雨后春笋一般纷纷出现,下载速度也是越来越快。不过,在我司内部因为安全制度的限制,生产环境是不能直接连接互联网的,因此需要建立本地的源服务器。

建立服务环境

软件镜像需要通过HTTP/HTTPS环境来提供服务。

# 系统更新
yum update -y
# 安装RPM相关包
yum install -y zlib-devel openssl-devel gcc perl-devel pam-devel make autoconf
yum install -y rpm-build unzip rsync createrepo
# 安装HTTP服务器
yum install -y httpd mod_security
# 修改配置文件
touch /etc/httpd/conf.d/repos.conf
cat>>/etc/httpd/conf.d/repos.conf<<EOF
Alias /repos /var/www/repos
<directory /var/www/repos>
Options +Indexes
Require all granted
</directory>
EOF
#开启端口
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
systemctl enable httpd --now
# 配置环境
mkdir -p /var/www/repos/{centos,epel,docker-ce,remi,mongodb,zabbix}
chown -R apache:apche /var/www/repos

同步官方安装源

下载脚本如下,其中使用到了清华大学的镜像源和中科大的镜像源,其中包含了CentOS、epel、Zabbix、MongoDB、PHP的镜像,整个占用存储空间不到800G。

#!/bin/bash
# CentOS
rsync -avrt --delete --exclude=isos --exclude=aarch64 --exclude=ppc64 --exclude=drpms/ --exclude=debug/ rsync://mirrors.ustc.edu.cn/centos/ /var/www/repos/centos/

#EPEL
rsync -avrt --delete --exclude=isos --exclude=aarch64 --exclude=ppc64 --exclude=drpms/ --exclude=debug/ rsync://mirrors.ustc.edu.cn/epel/ /var/www/repos/epel/

#Docker_CE
rsync -avrt --delete --exclude=test --exclude=nightly --exclude=edge --exclude=aarch64 --exclude=drpms/ --exclude=debug/ --exclude=source/ --exclude=debug-*/ rsync://mirrors.ustc.edu.cn/repo/docker-ce/linux/centos/ /var/www/repos/docker-ce/linux/centos/

#Zabbix
rsync -avrt --delete rsync://mirror.tuna.tsinghua.edu.cn/zabbix/ /var/www/repos/zabbix/

#Mongodb
rsync -avrt --delete rsync://mirror.tuna.tsinghua.edu.cn/mongodb/yum/ /var/www/repos/mongodb/yum/

#Remi
rsync -avrt --delete rsync://mirror.tuna.tsinghua.edu.cn/remi/ /var/www/repos/remi/

设置本地打包软件源

由于官方软件的更新策略和时间限制,我们需要给部分软件进行自打包和更新升级,所以需要建立单独的本地仓库

cd /var/www/repos
mkdir -p /var/www/repos/local/{6,7,8}/x86_64
creatrepo /var/www/repos/local/6/x86_64/
creatrepo /var/www/repos/local/7/x86_64/
creatrepo /var/www/repos/local/8/x86_64/