背景
在安装openshift origin时,经常会出提示无法下载某个包。
而通过手动yum install的时候是可以。
因此决定把openshift使用的centos的包,全部下载到本地,做一个本地源
实现方法:
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)创建需要下载的仓库的list文件,如下所示。
# cat repo.name
centos-openshift-origin
base
updates
extras
注上述的仓库名,请根据步骤2确认,填入自己需要下载的仓库名。
4)创建下载仓库的脚本:update-repo.sh,脚本内容如下
``` 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"--需要确保该目录所在的分区足够大>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)执行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)创建本地镜像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/--创建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)检查创建本地镜像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(按照如下的内容配置)
[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服务
# 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)客户端设置开机自动挂载
# cat /etc/exports
master.example.com:/centos-repo/centos-reponfsdefaults0 0