CentOS7搭建局域網(wǎng)YUM倉(cāng)庫(kù)實(shí)戰(zhàn)教程
環(huán)境準(zhǔn)備
準(zhǔn)備兩臺(tái)CentOS 7主機(jī):
- 服務(wù)端:IP地址192.168.1.100,安裝HTTP服務(wù)和存儲(chǔ)空間≥50GB
- 客戶端:IP地址192.168.1.200,需訪問(wèn)本地YUM源
服務(wù)端配置流程
1. 安裝必要組件
yum install -y httpd createrepo
systemctl start httpd
systemctl enable httpd
2. 創(chuàng)建倉(cāng)庫(kù)目錄
mkdir -p /var/www/html/centos/7/{os,epel,updates}
chmod -R 755 /var/www/html/centos
3. 鏡像同步操作
reposync -g -l -d -m --repoid=base --newest-only
--download-path=/var/www/html/centos/7/os/
4. 生成倉(cāng)庫(kù)元數(shù)據(jù)
createrepo /var/www/html/centos/7/os/
createrepo /var/www/html/centos/7/epel/
createrepo /var/www/html/centos/7/updates/
客戶端配置方法
cat > /etc/yum.repos.d/local.repo << EOF
[local-base]
name=Local CentOS Base
baseurl=http://192.168.1.100/centos/7/os/
enabled=1
gpgcheck=0
[local-epel]
name=Local EPEL
baseurl=http://192.168.1.100/centos/7/epel/
enabled=1
gpgcheck=0
EOF
安全策略調(diào)整
# 關(guān)閉SELinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# 防火墻放行HTTP
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
功能驗(yàn)證測(cè)試
yum clean all
yum repolist
yum install -y tree
維護(hù)注意事項(xiàng)
- 定期執(zhí)行
reposync --newest-only
同步更新 - 添加新軟件包后需重新生成元數(shù)據(jù)
- 建議配置定時(shí)任務(wù)自動(dòng)同步官方源
- 存儲(chǔ)空間監(jiān)控建議設(shè)置80%使用預(yù)警