本地服務器地址lochost 本地服務器地址


本地服務器地址lochost  本地服務器地址

文章插圖
在企業中或內部數據中心,很多時候由于需要安裝一些軟件,缺乏依賴包,傳統的方式是把原操作系統鏡像掛載到系統中,再使用YUM進行安裝,如果維護量太大就比較痛苦了 。
經過幾天的研究,目前我已經將自建YUM源倉庫服務器做成了一個方便的Shell腳本,只需要1鍵運行即可構建屬于本地的YUM源服務器 。
效果媲美其他公共YUM源服務器 。
之一步,我們先安裝一臺Centos Linux服務器,目前最新的是Centos 7.6 。
第二步,選擇GNOME桌面版作為本次YUM源服務器的操作系統 。
第三步,以root用戶登錄到服務器,在/root目錄下vi新建編輯一個1yum.sh之后:wq保存 。
第四步,將后面的shell腳本復制到1yum.sh中 。
第五步,使用chmod +x /root/1yum.sh
第六步,使用sh -x /root/1yum.sh 執行,完成后會自動重啟 。
客戶端使用時,將client-centos.repo下載到/etc/yum.repos.d/后,使用yum clean all && yum makecache && yum repolist 命令重建本地緩存即可使用 。
下面是命令,必須在命名為1yum.sh,并放在/root目錄下,否則后面會出現錯誤,如果有閱讀能力的也可以自行修改 。
環境:YUM源本地服務器IP地址是10.0.4.48
本YUM源適用于:Centos、Redhat、Oracle等類redhat系的
[root@bogon ~]# cd ~[root@bogon ~]# vi 1yum.sh[root@bogon ~]# chmod +x 1yum.sh[root@bogon ~]# sh -x 1yum.sh下面是腳本,直接復制進1yum.sh里
#!/bin/bashsystemctl disable firewalld #禁用關閉防火墻sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config #禁用SELINUX,需要重啟才會生效echo "30 20 * * * /home/yum-update.sh >>/home/yum/yum-sync.txt 2>&1" >>/var/spool/cron/root #計劃任務每天20點30分腳本自動定時從阿里云YUM源進行更新wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo#安裝nginx需要使用阿里云epel源,下載源文件到目錄另存為epel-7.repo文件yum -y install nginx#YUM安裝nginx HTTP服務器chkconfig --level 2345 nginx on #設置nginx為自啟動服務 tar -cvf /usr/share/nginx/html-dir.tar /usr/share/nginx/html #tar備份原nginx WEB訪問目錄到html-dir.tar文件 rm -rf /usr/share/nginx/html #刪除原nginx WEB訪問目錄 mkdir -p /home/yum && cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak #新建YUM倉庫存放目錄,備份nginx配置文件ln -s /home/yum /usr/share/nginx/html #軟鏈接本次YUM倉庫存放目錄到nginx WEB訪問目錄sed -i 's#location / {#location / { autoindex on;#g' /etc/nginx/nginx.conf#更改nginx配置文件啟用目錄自動索引,否則會報403錯誤crontab -l && systemctl list-unit-files |egrep 'nginx|firewalld' && cat /etc/selinux/config |grep 'SELINUX=disabled' #作為檢查項,檢查設置是否正確sed -n '38,59p' /root/1yum.sh >>/home/yum/client-centos.repo #生成客戶端的repo文件sed -n '60,113p' /root/1yum.sh >>/home/yum-update.sh && chmod +x /home/yum-update.sh#將yum update 另存為腳本,并給予可執行權限 by:stan liu create write date 20181206yum -y install createrepo yum-utils #YUM安裝 createrepo yum-utils配置工具(GNOME桌面環境已安裝)/home/yum-update.sh #執行同步阿里云YUM源更新的腳本ln -s /home/yum/centos/6 /home/yum/centos/6Server && ln -s /home/yum/centos/7 /home/yum/centos/7Server #軟鏈接方便Redhat系統進行更新reboot #執行YUM更新腳本完成后重啟服務器##################### client yum repo ####################### CentOS-Base.repo [base]name=CentOS-$releasever - Base baseurl=http://10.0.4.48/centos/$releasever/$basearch/base/gpgcheck=0 [updates]name=CentOS-$releasever - Updates baseurl=http://10.0.4.48/centos/$releasever/$basearch/updates/gpgcheck=0 [extras]name=CentOS-$releasever - Extras baseurl=http://10.0.4.48/centos/$releasever/$basearch/extras/gpgcheck=0 [epel]name=CentOS-$releasever - Epel baseurl=http://10.0.4.48/centos/$releasever/$basearch/epel/gpgcheck=0################################################################################# yum update shell ##################### #!/bin/bashrm -rf /etc/yum.repos.d/*wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repowget -O /etc/yum.repos.d/epel-6.repo http://mirrors.aliyun.com/repo/epel-6.reposed -i -e 's#$releasever#6#g' -e 's#$basearch#i386#g' /etc/yum.repos.d/CentOS-Base.reposed -i 's#$basearch#i386#g' /etc/yum.repos.d/epel-6.repoyum clean allyum makecacheyum repolistreposync -r base -p /home/yum/centos/6/i386reposync -r extras -p /home/yum/centos/6/i386reposync -r updates -p /home/yum/centos/6/i386reposync -r epel -p /home/yum/centos/6/i386rm -rf /etc/yum.repos.d/*wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repowget -O /etc/yum.repos.d/epel-6.repo http://mirrors.aliyun.com/repo/epel-6.reposed -i 's#$releasever#6#g' /etc/yum.repos.d/CentOS-Base.repoyum clean allyum makecacheyum repolistreposync -r base -p /home/yum/centos/6/x86_64reposync -r extras -p /home/yum/centos/6/x86_64reposync -r updates -p /home/yum/centos/6/x86_64reposync -r epel -p /home/yum/centos/6/x86_64rm -rf /etc/yum.repos.d/*wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repowget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repoyum clean allyum makecacheyum repolistreposync -r base -p /home/yum/centos/7/x86_64reposync -r extras -p /home/yum/centos/7/x86_64reposync -r updates -p /home/yum/centos/7/x86_64reposync -r epel -p /home/yum/centos/7/x86_64echo yum update completecd /home/yum/ls ./*/*/*/base ./*/*/*/extras ./*/*/*/updates ./*/*/*/epel rm -rf ./*/*/*/*/repodata ls ./*/*/*/base ./*/*/*/extras ./*/*/*/updates ./*/*/*/epel createrepo ./centos/7/x86_64/base/createrepo ./centos/7/x86_64/extras/createrepo ./centos/7/x86_64/updates/createrepo ./centos/7/x86_64/epel/createrepo ./centos/6/x86_64/base/createrepo ./centos/6/x86_64/extras/createrepo ./centos/6/x86_64/updates/createrepo ./centos/6/x86_64/epel/createrepo ./centos/6/i386/base/createrepo ./centos/6/i386/extras/createrepo ./centos/6/i386/updates/createrepo ./centos/6/i386/epel/echo yum rpm index complete#############################################################其他注意事項:

推薦閱讀