搭建私有化Cenos7,docker的安装镜像源


  最近Centos7结束了服役周期,但是还有些小伙伴们很多还是用的Centos7作为主体,官方安装源已经开始失效,这个时候我们就可以自己做个镜像源来代替原来的镜像源。

1.先下载镜像源

  因为我的服务器操作系统是x86系列的,所以我只下载x86的安装源。这里我找到的是一个欧洲的镜像源下载速度还不错。mirror.nsc.liu.se,在上面我们找到centos7的历史源http://mirror.nsc.liu.se/centos-store/7.9.2009/os/x86_64/。然后开始下载整个目录。当然下载前,要首先确认你有没有wget命令。

yum -y install wget

#下载安装源
wget -c -r -np -k -L -p http://mirror.nsc.liu.se/centos-store/7.9.2009/os/x86_64/

#下载updates,extras,centosplusy
wget -c -r -np -k -L -p http://mirror.nsc.liu.se/centos-store/7.9.2009/updates/
wget -c -r -np -k -L -p http://mirror.nsc.liu.se/centos-store/7.9.2009/extras/
wget -c -r -np -k -L -p http://mirror.nsc.liu.se/centos-store/7.9.2009/centosplus/

在这里插入图片描述

整体下载完后的容量,基本是这样,因为我还另外下载cloud,sclo源,所以整个目录接近68G,但是对于服务器来说,这点容量不算什么,等下我们还会下载docker的下载源。
在这里插入图片描述
下载完源后,我们就要对新下载的源重新建立repodata,先安装工具createrepo

yum install yum-utils createrepo -y
#安装完成后,把原来下载到本地repodata删除,重新建立

rm -rf  mirror.nsc.liu.secentos/7/os/x86_64/repodata
createrepo -v  mirror.nsc.liu.secentos/7/os/x86_64/

rm -rf mirror.nsc.liu.secentos/7/centosplus/x86_64/repodata
createrepo -v  mirror.nsc.liu.secentos/7/centosplus/x86_64/

rm -rf mirror.nsc.liu.secentos/7/extras/x86_64/repodata
createrepo -v  mirror.nsc.liu.secentos/7/extras/x86_64/

rm -rf  mirror.nsc.liu.secentos/7/updates/x86_64/repodata
createrepo -v  mirror.nsc.liu.secentos/7/updates/x86_64/

2.安装Nginx,指向安装新的镜像源

yum -y install nginx

增加上面的centos源的http目录访问,配置文件放在/etc/nginx/conf.d/目录下,命名为CentosBase.conf,内容如下. x.x.x.x代表你的服务器ip地址。当然server_name你可以用域名进行区分,不一定要用ip。root是你刚才下载的整个镜像源的目录地址。

server{
	listen x.x.x.x:91;
	server_name x.x.x.x ;
	location / {
	autoindex on;
	root "/tmp/mirror.nsc.liu.se/";
	}
}

配置完成后,直接访问http的目录地址,可以看到这样的界面。
在这里插入图片描述

3.配置自己的repo文件

上面的配置是已经把镜像源做成了,现在就要自己建立一个自己源的repo文件了,这便是我的repo文件CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
baseurl=http://192.168.124.165:91/centos/$releasever/os/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
baseurl=http://192.168.124.165:91/centos/$releasever/updates/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://192.168.124.165:91/centos/$releasever/extras/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://192.168.124.165:91/centos/$releasever/centosplus/$basearch/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

把CentOS-Base.repo 文件放入 /etc/yum.repos.d/目录下,然后开始验证。

yum clean all
yum makecache

在这里插入图片描述
出现如下画面,整个镜像源就验证正常了,可以开始使用了。

同样的方式,我们把docker的源也下载下来,做成自己的私有源

#下载docker的镜像站点
wget -c -r -np -k -L -p https://download.docker.com/linux/centos/7/x86_64/
wget -c -r -np -k -L -p https://download.docker.com/linux/centos/7/source/
wget -c -r -np -k -L -p https://download.docker.com/linux/centos/7/debug-x86_64/

#重新建立repodata
rm -rf  /mirrorsite/download.docker.com/linux/centos/7/x86_64/stable/repodata
createrepo -v  /mirrorsite/download.docker.com/linux/centos/7/x86_64/stable/

rm -rf   /mirrorsite/download.docker.com/linux/centos/7/x86_64/test/repodata
createrepo -v /mirrorsite/download.docker.com/linux/centos/7/x86_64/test/

rm -rf   /mirrorsite/download.docker.com/linux/centos/7/x86_64/nightly/repodata
createrepo -v /mirrorsite/download.docker.com/linux/centos/7/x86_64/nightly/

rm -rf   /mirrorsite/download.docker.com/linux/centos/7/x86_64/edge/repodata
createrepo -v /mirrorsite/download.docker.com/linux/centos/7/x86_64/edge/

rm -rf  /mirrorsite/download.docker.com/linux/centos/7/source/stable/repodata
createrepo -v  /mirrorsite/download.docker.com/linux/centos/7/source/stable/

rm -rf   /mirrorsite/download.docker.com/linux/centos/7/source/test/repodata
createrepo -v /mirrorsite/download.docker.com/linux/centos/7/source/test/

rm -rf   /mirrorsite/download.docker.com/linux/centos/7/source/nightly/repodata
createrepo -v /mirrorsite/download.docker.com/linux/centos/7/source/nightly/

rm -rf   /mirrorsite/download.docker.com/linux/centos/7/source/edge/repodata
createrepo -v /mirrorsite/download.docker.com/linux/centos/7/source/edge/

配置docker的repo文件,docker-ce.repo,文件内容如下

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=http://192.168.124.165:91/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=http://192.168.124.165:91/linux/centos/gpg

[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=http://192.168.124.165:91/linux/centos/$releasever/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=http://192.168.124.165:91/linux/centos/gpg

[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=http://192.168.124.165:91/linux/centos/$releasever/source/stable
enabled=0
gpgcheck=1
gpgkey=http://192.168.124.165:91/linux/centos/gpg

[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=http://192.168.124.165:91/linux/centos/$releasever/$basearch/test
enabled=0
gpgcheck=1
gpgkey=http://192.168.124.165:91/linux/centos/gpg

[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=http://192.168.124.165:91/linux/centos/$releasever/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=http://192.168.124.165:91/linux/centos/gpg

[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=http://192.168.124.165:91/linux/centos/$releasever/source/test
enabled=0
gpgcheck=1
gpgkey=http://192.168.124.165:91/linux/centos/gpg

[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=http://192.168.124.165:91/linux/centos/$releasever/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=http://192.168.124.165:91/linux/centos/gpg

[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=http://192.168.124.165:91/linux/centos/$releasever/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=http://192.168.124.165:91/linux/centos/gpg

[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=http://192.168.124.165:91/linux/centos/$releasever/source/nightly
enabled=0
gpgcheck=1
gpgkey=http://192.168.124.165:91/linux/centos/gpg

把docker-ce.repo 文件放入 /etc/yum.repos.d/目录下,然后开始验证。

yum clean all
yum makecache

在这里插入图片描述
这样Centos7的私有源和docker的私有源就完全安装完毕。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机核动力

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值