本地制作centos源

背景

在安裝openshift origin時,經(jīng)常會出提示無法下載某個包。

而通過手動yum install的時候是可以。

因此決定把openshift使用的centos的包,全部下載到本地,做一個本地源

實現(xiàn)方法:

1)確保/etc/yum.repos.d/的repo文件是centos安裝時候默認提供的,如下所示

#? ll /etc/yum.repos.d/

total 40

-rw-r--r--. 1 root root 1664 Dec5 15:12 CentOS-Base.repo

-rw-r--r--. 1 root root 1309 Dec5 14:26 CentOS-CR.repo

-rw-r--r--. 1 root root649 Dec5 14:26 CentOS-Debuginfo.repo

-rw-r--r--. 1 root root630 Dec5 14:26 CentOS-Media.repo

-rw-r--r--. 1 root root887 Dec5 14:26 CentOS-OpenShift-Origin.repo

-rw-r--r--. 1 root root 1331 Dec5 14:26 CentOS-Sources.repo

-rw-r--r--. 1 root root 3830 Dec5 14:26 CentOS-Vault.repo

-rw-r--r--. 1 root root314 Dec5 14:26 CentOS-fasttrack.repo


2確認需要下載的倉庫名

#cat/etc/yum.repos.d/CentOS-Base.repo | less

[base]--倉庫名。

name=CentOS-$releasever - Base

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


3)創(chuàng)建需要下載的倉庫的list文件,如下所示。

# cat repo.name

centos-openshift-origin

base

updates

extras

上述的倉庫名,請根據(jù)步驟2確認,填入自己需要下載的倉庫名。


4)創(chuàng)建下載倉庫的腳本:update-repo.sh,腳本內(nèi)容如下

``` disable_all_repo()

{

for repo_file in `find /etc/yum.repos.d/ -maxdepth 1 -type f`

do

sed -i? 's#enabled=1#enabled=0#g' $repo_file

sed -i 's#enabled = 1#enabled? = 0#g' $repo_file

done

}

date=`date +%F`

log_path="/repo_tools/log/$date"

mkdir -p $log_path

ftp_path="/centos-repo"--需要確保該目錄所在的分區(qū)足夠大>10GB

disable_all_repo

repo_list_file="/centos-repo/repo.name"

for repo_id in `cat $repo_list_file`

do

if [ ! -d "$ftp_path/$repo_id" ];then

mkdir $ftp_path/$repo_id

fi

yum-config-manager --enable $repo_id

for((i=0;i<20;i++))

do

cat /dev/null>error.msg

cat /dev/null>tmp.txt

reposync-r $repo_id -p $ftp_path 2>&1 |tee? tmp.txt

grep -a Errno tmp.txt >? error.msg

if [ -s? "./error.msg" ]

then

continue

else

break

fi

done

if [ $i -eq 50 ]

then

touch $log_path/fail

mv error.msg? $log_path/$repo_id

else

createrepo --update? $ftp_path/$repo_id

fi

rm -f error.msg

rm -f tmp.txt

done

if [ ! -f $log_path/fail ]

then

touch $log_path/success

```


5)執(zhí)行update-repo.sh腳本下載倉庫。

# ./update-repo.sh


6)下載完成后確認倉庫是否下載成功。

ll? /centos-repo/

total 12

drwxr-xr-x. 3 root root22 Dec5 14:44 base

drwxr-xr-x. 3 root root 4096 Dec5 14:44 centos-openshift-origin

drwxr-xr-x. 3 root root22 Dec5 15:12 extras

-rw-r--r--. 1 root root44 Dec5 14:25 repo.name

-rw-r--r--. 1 root root 1304 Dec5 14:21 update-repo.sh

drwxr-xr-x. 3 root root22 Dec5 15:05 updates


7)創(chuàng)建本地鏡像repo文件。

#? cd /centos-repo/base/Packages

#rpm -ivh? deltarpm-3.6-3.el7.x86_64.rpm

# rpm? -ivh python-deltarpm-3.6-3.el7.x86_64.rpm

# rpm? -ivh createrepo-0.9.9-28.el7.noarch.rpm

#? createrepo --update /centos-repo/base/--創(chuàng)建repo

Could not find valid repo at:? /centos-repo/base/

Spawning worker 0 with 2398 pkgs

Spawning worker 1 with 2398 pkgs

Spawning worker 2 with 2398 pkgs

Spawning worker 3 with 2397 pkgs

Workers Finished

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs


8檢查創(chuàng)建本地鏡像repo文件。

# cd /centos-repo/base/

# ll

total 664

drwxr-xr-x. 2 root root 532480 Dec5 15:04 Packages

drwxr-xr-x. 2 root root4096 Dec7 06:42repodata

9制作本地yum源,修改/etc/

#? cd /etc/yum.repos.d/

ll(只保留一個)

-rw-r--r--. 1 root root 574 Dec8 05:36 centos.repo

#cat centos.repo(按照如下的內(nèi)容配置)

[base]

name = base

baseurl = file:///centos-repo/base

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]

name = updates

baseurl = file:///centos-repo/updates

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]

name=CentOS-$releasever - Extras

baseurl=file:///centos-repo/extras

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[centos-openshift-origin]

name=CentOS OpenShift Origin

baseurl=file:///centos-repo/centos-openshift-origin/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-PaaS

# yum

cleanall

10)配置nfs服務(wù)

#? cat /etc/exports

/centos-repo/(rw,sync,all_squash,anonuid=99,anongid=99)

#? exportfs

/centos-repo

#? systemctl enable nfs-server

# systemctl start nfs-server

12)在客戶端掛載nfs目錄

#mount -t nfsmaster.example.com:/centos-repo/centos-repo

13)客戶端設(shè)置開機自動掛載

#? cat /etc/exports

master.example.com:/centos-repo/centos-reponfsdefaults0 0

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容