CentOS 搭建内部Yum源同步阿里Yum源
背景:
有這樣的需求,測試環境網段不能上網,但是測試環境centos安裝軟件包每一臺都配置本地yum源很麻煩,也缺少第三方yum源,特此在內網搭建一臺yum源服務器滿足這一需求,同時防火墻層面只允許此yum源服務器每周日晚限時聯網同步阿里云的yum源.
一.yum源服務器的系統環境,最小化安裝
| 1 2 | [root@yumserver?~]#?cat?/etc/redhat-release? CentOS?Linux?release?7.9.2009?(Core) |
? ?yum源服務器地址? 10.8.98.222??
放開系統防火墻,關閉selinux
| 1 2 3 4 | [root@yumserver?~]#?firewall-cmd?--add-port=80/tcp?--permanent? success [root@yumserver?~]#?firewall-cmd?--reload success |
| 1 2 3 4 5 6 7 8 9 10 11 12 | [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
| 1 2 3 4 | [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/ |
| 1 2 3 4 | 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
三.安裝相關軟件
| 1 | 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(自定義目錄)
| 1 2 3 4 5 6 7 8 9 10 | 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 |
五?、創建倉庫索引
| 1 2 3 4 | createrepo?-po?/mirror/base/?/mirror/base/ createrepo?-po?/mirror/extras/?/mirror/extras/ createrepo?-po?/mirror/updates/?/mirror/updates/ createrepo?-po?/mirror/epel/?/mirror/epel/ |
六?、更新數據源
| 1 2 3 4 | createrepo?--update?/mirror/base/ createrepo?--update?/mirror/extras/ createrepo?--update?/mirror/updates/ createrepo?--update?/mirror/epel/ |
七、啟動并配置Apache服務
| 1 2 3 4 5 6 7 8 9 10 11 12 | 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,直接復制粘貼執行
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 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 |
注意:上面
| 1 | xxxx://x.x.x.x/ |
更改為自己對應的
我這里為http? :? //? 10.8.98.222? /?
八、編寫yum源客戶端配置文件
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | [root@yumserver?~]#?mkdir?-p?/mirror/repo/ ###直接復制粘貼執行 cat?<<?EOF?>?/mirror/repo/CentOS-Base.repo [base] name=CentOS-$releasever?-?Base?-?10.8.98.222 failovermethod=priority baseurl= enable=1 gpgcheck=0 ?? #released?updates? [updates] name=CentOS-$releasever?-?Updates?-?10.8.98.222 failovermethod=priority baseurl= enable=1 gpgcheck=0 ?? #additional?packages?that?may?be?useful [extras] name=CentOS-$releasever?-?Extras?-?10.8.98.222 failovermethod=priority baseurl= enable=1 gpgcheck=0 ?? #additional?packages?that?may?be?useful [epel] name=CentOS-$releasever?-?Epel?-?10.8.98.222 failovermethod=priority baseurl= enable=1 gpgcheck=0 EOF |
九、客戶端配置yum源
用戶可以瀏覽器訪問10.8.98.222查看配置客戶端yum源的方法
| 1 2 | curl?-o?/etc/yum.repos.d/CentOS-Base.repo? yum?makecache |
十?、設置定時同步yum源的任務
[root@yumserver ~]# cat? /mirror/script/centos_yum_update.sh
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #!/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點執行
| 1 2 | [root@yumserver?~]#?crontab?-l 0?1?*?*?1?/bin/bash?/mirror/script/centos_yum_update.sh |
總結
以上是生活随笔為你收集整理的CentOS 搭建内部Yum源同步阿里Yum源的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL中除数为0处理情况演示
- 下一篇: 虚拟机磁盘扩容parted