CentOS 搭建內部Yum源同步阿里Yum源
參考文件: https://www.cnblogs.com/zoulongbin/p/5773330.html
背景:
有這樣的需求,測試環境網段不能上網,但是測試環境centos安裝軟體包每一臺都配置本地yum源很麻煩,也缺少第三方yum源,特此在內網搭建一臺yum源伺服器滿足這一需求,同時防火牆層面只允許此yum源伺服器每週日晚限時聯網同步阿里雲的yum源.
一.yum源伺服器的系統環境,最小化安裝
[root@yumserver ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core)
yum源伺服器地址 10.8.98.222
放開系統防火牆,關閉selinux
[root@yumserver ~]# firewall-cmd --add-port=80/tcp --permanent success [root@yumserver ~]# firewall-cmd --reload success
[root@yumserver ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
二.新增阿里雲yum源並檢查
備份好原系統的repo
[root@yumserver yum.repos.d]# pwd /etc/yum.repos.d [root@yumserver yum.repos.d]# mkdir backup [root@yumserver yum.repos.d]# mv *.repo backup/
curl -o /etc/yum.repos.d/CentOS-Base.repo https:999999//mirrors.aliyun.com/repo/Centos-7.repo curl -o /etc/yum.repos.d/epel.repo http:999999//mirrors.aliyun.com/repo/epel-7.repo yum makecache yum repolist
去掉999999
三.安裝相關軟體
yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel httpd yum-utils createrepo
標註:
yum-utils:reposync同步工具
createrepo:編輯yum庫工具
httpd:透過Apache軟體提供web服務,也可以使用nginx
四、同步阿里雲yum源軟體包到本地伺服器指定目錄/mirror(自定義目錄)
mkdir -p /mirror chown -R apache:apache /mirror chmod -R 755 /mirror ###引數-n指下載最新軟體包,-p指定目錄,指定本地的源--repoid(如果不指定就同步本地伺服器所有的源),下載過程比較久 reposync -n --repoid=extras --repoid=updates --repoid=base --repoid=epel -p /mirror [root@yumserver ~]# du -sh /mirror/* 9.0G /mirror/base 16G /mirror/epel 321M /mirror/extras 2.2G /mirror/updates
五 、建立倉庫索引
createrepo -po /mirror/base/ /mirror/base/ createrepo -po /mirror/extras/ /mirror/extras/ createrepo -po /mirror/updates/ /mirror/updates/ createrepo -po /mirror/epel/ /mirror/epel/
六 、更新資料來源
createrepo --update /mirror/base/ createrepo --update /mirror/extras/ createrepo --update /mirror/updates/ createrepo --update /mirror/epel/
七、啟動並配置Apache服務
systemctl start httpd systemctl enable httpd systemctl status httpd [root@yumserver ~]# vim /etc/httpd/conf/httpd.conf DocumentRoot "/mirror/" <Directory "/mirror/"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all Require all granted </Directory>
###修改Apache預設首頁index.html,直接複製貼上執行
cat << EOF > /usr/share/httpd/noindex/index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CentOS 7 映象</title> <script>document.createElement("myHero")</script> <style> myHero { display: block; background-color: #ddd; padding: 10px; font-size: 20px; } </style> </head> <body> <h1>簡介</h1> <hr> <p>CentOS,是基於 Red Hat Linux 提供的可自由使用原始碼的企業級 Linux 發行版本。</p> <hr> <br> <br> <h1>CentOS 7 配置內部YUM源</h1> <br> <h2>1、備份</h2> <myHero>mkdir /etc/yum.repos.d/backup </myHero> <myHero>mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/</myHero> <br> <h2>2、下載新的 CentOS-Base.repo 到 /etc/yum.repos.d/ </h2> <myHero>curl -o /etc/yum.repos.d/CentOS-Base.repo xxxx://x.x.x.x/repo/CentOS-Base.repo</myHero> <br> <h2>3、執行 yum makecache 生成快取</h2> <br> <h2>4、執行 yum repolist 檢視已經生成快取</h2> <br> <br> </body> </html> EOF
注意:上面
xxxx://x.x.x.x/
更改為自己對應的
我這裡為http : // 10.8.98.222 /
八、編寫yum源客戶端配置檔案
[root@yumserver repo]# cat /mirror/repo/CentOS-Base.repo [base] name=CentOS- - Base - 10.8.98.222 failovermethod=priority baseurl=http://*******/base/ enable=1 gpgcheck=0 #released updates [updates] name=CentOS- - Updates - 10.8.98.222 failovermethod=priority baseurl=http://*******/updates/ enable=1 gpgcheck=0 #additional packages that may be useful [extras] name=CentOS- - Extras - 10.8.98.222 failovermethod=priority baseurl=http://*******/extras/ enable=1 gpgcheck=0 #additional packages that may be useful [epel] name=CentOS- - Epel - 10.8.98.222 failovermethod=priority baseurl=http://*******/epel/ enable=1 gpgcheck=0 [root@yumserver repo]#
*******此處為自己的ip
九、客戶端配置yum源
使用者可以瀏覽器訪問10.8.98.222檢視配置客戶端yum源的方法
curl -o /etc/yum.repos.d/CentOS-Base.repo http:/ /10.8.98.222/repo/CentOS-Base.repo yum makecache
十 、設定定時同步yum源的任務
[root@yumserver ~]# cat /mirror/script/centos_yum_update.sh
#!/bin/bash echo 'Updating Aliyum Source' DATETIME=`date +%F_%T` exec > /var/log/aliyumrepo_$DATETIME.log reposync -np /mirror if [ $? -eq 0 ];then createrepo --update /mirror/base createrepo --update /mirror/extras createrepo --update /mirror/updates createrepo --update /mirror/epel echo "SUCESS: $DATETIME aliyum_yum update successful" else echo "ERROR: $DATETIME aliyum_yum update failed" fi
新增定時任務,每週一凌晨1點執行
[root@yumserver ~]# crontab -l 0 1 * * 1 /bin/bash /mirror/script/centos_yum_update.sh
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70004783/viewspace-2790196/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- CentOS7.9 搭建內部yum源伺服器同步阿里yum源CentOS伺服器阿里
- centos同步yum源到本地,建立本地網路yum源CentOS
- Centos-7修改yum源為國內的yum源CentOS
- Centos-Stream 配置本地yum源和配置阿里雲yum源CentOS阿里
- 搭建企業內部yum倉庫(centos6+centos7+epel源)CentOS
- Centos7配置阿里epel源|yum源CentOS阿里
- centos6-增加阿里yum源CentOS阿里
- CentOS 7 配置 阿里雲 yum源CentOS阿里
- CentOS 更改 yum 映象源為阿里雲映象源CentOS阿里
- CentOS8配置阿里雲YUM源CentOS阿里
- CentOS 配置yum源CentOS
- CentOS修改yum源CentOS
- CentOS7 yum源修改為阿里,配置阿里epel源CentOS阿里
- CentOS7配置yum國內源CentOS
- 將Centos的yum源更換為國內的阿里雲(163)源CentOS阿里
- 本地yum源搭建
- centos 替換yum源CentOS
- 修改Centos7預設yum源為阿里雲源CentOS阿里
- centos7替換yum源為阿里雲CentOS阿里
- CentOS8使用阿里雲yum源異常CentOS阿里
- centos7 更換yum為阿里源或者別的源CentOS阿里
- centos7.5利用yum快取搭建本地源CentOS快取
- Linux CentOS 7 更新yum源LinuxCentOS
- CentOS6.9配置yum源CentOS
- CentOS7 修改 yum 源CentOS
- Centos 7 常用yum源配置CentOS
- Centos系統配置yum源CentOS
- CentOS6.8配置yum源CentOS
- centos7.5配置yum源CentOS
- CentOS7--配置yum源CentOS
- 小知識:CentOS配置yum源/解決yum源失效問題CentOS
- 將Centos 的預設yum源改為阿里雲的yum源後出現的問題CentOS阿里
- centos系統配置yum的國內映象源CentOS
- yum源伺服器搭建伺服器
- centos-7.6配置本地yum源CentOS
- CentOS7 配置 163 yum 源CentOS
- linux CentOS更換 ali YUM源LinuxCentOS
- Centos8.x yum 源配置 解決 yum 不可用CentOS