前言
这次老师突然要我帮忙配一下服务器的镜像源,装一下docker。刚好又在CentOS 7.9 生命周期结束EOL的时候,花了1个小时找了些资料+完成任务😃
环境
- CentOS 7.9 2009
- Xshell 8.0beta(公测)
安装步骤
1. 尝试使用yum(应该是不成功的)
2. 配置阿里镜像源
我从可用镜像源找到了阿里镜像源配置方法,步骤如下(有需要可以配置其他的源):
切换repo目录,备份镜像源
cd /etc/yum.repo.d/
mkdir backup
mv *.repo backup
ls
上述命令执行完毕后应当只有一个backup,我这里是复盘写的文档。
配置阿里源
cat > CentOS-aliyun-lhr.repo << 'EOF'
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
EOF
配置阿里epel源
cat > epel-aliyun.repo <<'EOF'
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
EOF
检查验证
yum clean all
yum makecache fast
yum install vim lrzsz wget curl net-tools
因为之前已有这些软件,所以现在yum可用后显示Nothing to do
阶段性胜利 Yeah🎉🎉🎉!!!
3. 安装DockerCE
这里我参考了阿里云镜像站的文档
#安装必备软件
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
#添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#使用sed命令替换download.docker.com为mirrors.aliyun.com/docker-ce,文件路径在/etc/yum.repos.d/docker-ce.repo
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
#更新yum并安装dockerce
sudo yum makecache fast
sudo yum -y install docker-ce
#启动docker.service
service docker start
4. 检查是否安装成功
docker version
结果应该会和我一样
拉一个镜像试试
docker pull hello-world
成功
🎊🎊🎊完结撒花🎉🎉🎉
或者
卡住Retrying in 1 second.......
#ip已经处理过了,反正是个IP就对了
[root@localhost docker]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
2ec76a50fe7c: Retrying in 1 second
fab7f202453a: Retrying in 1 second
ee59ca42def8: Retrying in 1 second
2ce2282f972f: Waiting
d2a9e456ba82: Waiting
b59edc04016d: Waiting
error pulling image configuration: download failed after attempts=6: dial tcp 255.255.255.255:443: connect: connection refused
修改docker源
#切换目录
cd /etc/docker/
#没有这个文件就创建一个,一般应该都有的
vim daemon.json
网上有很多docker源的推荐,我这里选了可用docker镜像的一部分
{
"registry-mirrors": ["https://dockerhub.icu",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn"]
}
再次 🎊🎊🎊完结撒花🎉🎉🎉
第一次写文档,感谢观看!!!