在企業(yè)中或內(nèi)部數(shù)據(jù)中心,很多時(shí)候由于需要安裝一些軟件,缺乏依賴包,傳統(tǒng)的方式是把原操作系統(tǒng)鏡像掛載到系統(tǒng)中,再使用YUM進(jìn)行安裝,如果維護(hù)量太大就比較痛苦了。
經(jīng)過(guò)幾天的研究,目前我已經(jīng)將自建YUM源倉(cāng)庫(kù)服務(wù)器做成了一個(gè)方便的Shell腳本,只需要1鍵運(yùn)行即可構(gòu)建屬于本地的YUM源服務(wù)器。
效果媲美其他公共YUM源服務(wù)器。
第一步,我們先安裝一臺(tái)CentosLinux服務(wù)器,目前最新的是Centos7.6。
第二步,選擇GNOME桌面版作為本次YUM源服務(wù)器的操作系統(tǒng)。
第三步,以root用戶登錄到服務(wù)器,在/root目錄下vi新建編輯一個(gè)1yum.sh之后:wq保存。
第四步,將后面的shell腳本復(fù)制到1yum.sh中。
第五步,使用chmod+x/root/1yum.sh
第六步,使用sh-x/root/1yum.sh執(zhí)行,完成后會(huì)自動(dòng)重啟。
客戶端使用時(shí),將client-centos.repo下載到/etc/yum.repos.d/后,使用yumcleanall&&yummakecache&&yumrepolist命令重建本地緩存即可使用。
下面是命令,必須在命名為1yum.sh,并放在/root目錄下,否則后面會(huì)出現(xiàn)錯(cuò)誤,如果有閱讀能力的也可以自行修改。
環(huán)境:YUM源本地服務(wù)器IP地址是10.0.4.48
本YUM源適用于:Centos、Redhat、Oracle等類redhat系的
[root@bogon~]#cd~[root@bogon~]#vi1yum.sh[root@bogon~]#chmod+x1yum.sh[root@bogon~]#sh-x1yum.sh下面是腳本,直接復(fù)制進(jìn)1yum.sh里
#!/bin/bashsystemctldisablefirewalld#禁用關(guān)閉防火墻sed-i's#SELINUX=enforcing#SELINUX=disabled#g'/etc/selinux/config#禁用SELINUX,需要重啟才會(huì)生效echo"3020***/home/yum-update.sh>>/home/yum/yum-sync.txt2>&1">>/var/spool/cron/root#計(jì)劃任務(wù)每天20點(diǎn)30分腳本自動(dòng)定時(shí)從阿里云YUM源進(jìn)行更新wget-O/etc/yum.repos.d/epel-7.repohttp://mirrors.aliyun.com/repo/epel-7.repo#安裝nginx需要使用阿里云epel源,下載源文件到目錄另存為epel-7.repo文件yum-yinstallnginx#YUM安裝nginxHTTP服務(wù)器chkconfig--level2345nginxon#設(shè)置nginx為自啟動(dòng)服務(wù)tar-cvf/usr/share/nginx/html-dir.tar/usr/share/nginx/html#tar備份原nginxWEB訪問(wèn)目錄到html-dir.tar文件rm-rf/usr/share/nginx/html#刪除原nginxWEB訪問(wèn)目錄mkdir-p/home/yum&&cp/etc/nginx/nginx.conf/etc/nginx/nginx.conf.bak#新建YUM倉(cāng)庫(kù)存放目錄,備份nginx配置文件ln-s/home/yum/usr/share/nginx/html#軟鏈接本次YUM倉(cāng)庫(kù)存放目錄到nginxWEB訪問(wèn)目錄sed-i's#location/{#location/{autoindexon;#g'/etc/nginx/nginx.conf#更改nginx配置文件啟用目錄自動(dòng)索引,否則會(huì)報(bào)403錯(cuò)誤crontab-l&&systemctllist-unit-files|egrep'nginx|firewalld'&&cat/etc/selinux/config|grep'SELINUX=disabled'#作為檢查項(xiàng),檢查設(shè)置是否正確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#將yumupdate另存為腳本,并給予可執(zhí)行權(quán)限by:stanliucreatewritedate20181206yum-yinstallcreaterepoyum-utils#YUM安裝createrepoyum-utils配置工具(GNOME桌面環(huán)境已安裝)/home/yum-update.sh#執(zhí)行同步阿里云YUM源更新的腳本ln-s/home/yum/centos/6/home/yum/centos/6Server&&ln-s/home/yum/centos/7/home/yum/centos/7Server#軟鏈接方便Redhat系統(tǒng)進(jìn)行更新reboot#執(zhí)行YUM更新腳本完成后重啟服務(wù)器#####################clientyumrepo#######################CentOS-Base.repo[base]name=CentOS-$releasever-Basebaseurl=http://10.0.4.48/centos/$releasever/$basearch/base/gpgcheck=0[updates]name=CentOS-$releasever-Updatesbaseurl=http://10.0.4.48/centos/$releasever/$basearch/updates/gpgcheck=0[extras]name=CentOS-$releasever-Extrasbaseurl=http://10.0.4.48/centos/$releasever/$basearch/extras/gpgcheck=0[epel]name=CentOS-$releasever-Epelbaseurl=http://10.0.4.48/centos/$releasever/$basearch/epel/gpgcheck=0#################################################################################yumupdateshell######################!/bin/bashrm-rf/etc/yum.repos.d/*wget-O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repowget-O/etc/yum.repos.d/epel-6.repohttp://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.repoyumcleanallyummakecacheyumrepolistreposync-rbase-p/home/yum/centos/6/i386reposync-rextras-p/home/yum/centos/6/i386reposync-rupdates-p/home/yum/centos/6/i386reposync-repel-p/home/yum/centos/6/i386rm-rf/etc/yum.repos.d/*wget-O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repowget-O/etc/yum.repos.d/epel-6.repohttp://mirrors.aliyun.com/repo/epel-6.reposed-i's#$releasever#6#g'/etc/yum.repos.d/CentOS-Base.repoyumcleanallyummakecacheyumrepolistreposync-rbase-p/home/yum/centos/6/x86_64reposync-rextras-p/home/yum/centos/6/x86_64reposync-rupdates-p/home/yum/centos/6/x86_64reposync-repel-p/home/yum/centos/6/x86_64rm-rf/etc/yum.repos.d/*wget-O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repowget-O/etc/yum.repos.d/epel-7.repohttp://mirrors.aliyun.com/repo/epel-7.repoyumcleanallyummakecacheyumrepolistreposync-rbase-p/home/yum/centos/7/x86_64reposync-rextras-p/home/yum/centos/7/x86_64reposync-rupdates-p/home/yum/centos/7/x86_64reposync-repel-p/home/yum/centos/7/x86_64echoyumupdatecompletecd/home/yum/ls./*/*/*/base./*/*/*/extras./*/*/*/updates./*/*/*/epelrm-rf./*/*/*/*/repodatals./*/*/*/base./*/*/*/extras./*/*/*/updates./*/*/*/epelcreaterepo./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/echoyumrpmindexcomplete#############################################################其他注意事項(xiàng):
#如果nginx的配置文件在/etc/nginx/conf.d/default.conf里,則將“l(fā)ocation/{”改為“l(fā)ocation/{autoindexon;”
#如果/etc/nginx/nginx.conf里用戶是"usernoboby;"或者"usernginx;"報(bào)403錯(cuò)誤則改為userroot;
#改完之后nginx-sreload就可以訪問(wèn)了。
#本腳本是基于centos7.5構(gòu)建的,如果實(shí)在嫌麻煩可以直接使用centos7.5
#這個(gè)腳本最大的方便之處可以將阿里云源鏈接改為其他源且每天自動(dòng)更新,更新后的記錄也可以方便的在yum-sync.txt里查看。
#第一次運(yùn)行可能需要10多個(gè)小時(shí)(我這邊64G左右),視網(wǎng)速而定,第二次或之后視更新數(shù)量而定。
源碼參考一下圖片,主要是行一致就可以