centos安装国内yum源

本文摘自:https://blog.csdn.net/liqz666/article/details/81939181

我们部署docker的时候需要centOs环境,但由于centOs自带的是国外的yum,可能部署docker会产生不稳定的状态,因此我们可以安装国内的yum来替换国外的yum。

1.登录

ssh root@xxx.xxx.xxx.x

2.检查网络状态,因为我们的阿里云yum是需要通过网络下载的,如果没有网,那么一切操作都是白费的,输入命令ifconfig进行查看,如果提示未找到命令,说明没有安装net-tools工具,输入命令yum install net-tools进行安装工具,接下来会出来一大堆东西,直接输入命令y通过即可;接下来输入ifconfig进行查看网络状态,可以看到ens33的ip地址,说明网络状态是已连接的,当然也可以输入ip lingk ,ip addr进行查看也是可以的。

[root@localhost ~]# ifconfig
-bash: ifconfig: 未找到命令

[root@localhost ~]# yum install net-tools

.........

Is this ok [y/d/N]: y

.........

已安装:
  net-tools.x86_64 0:2.0-0.22.20131004git.el7

完毕!

[root@localhost ~]# ifconfig

3.我们通过ll命令列出/etc/yum.repos.d/的默认的yum-->CentOS-Base.repo,首先我们用命令cd /etc/yum.repos.d/进入到里面通过命令 wget http://mirrors.aliyun.com/repo/Centos-7.repo进行下载阿里云yum-->Centos-7.repo,结果发现命令wget用不了,是因为,没有安装wget的插件,我们先用命令cd ~回到家目录下通过yum -y install wget进行安装wget插件,然后重新返回到cd /etc/yum.repos.d/进行下载阿里云yum

[root@localhost ~]# ll /etc/yum.repos.d/
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
-bash: wget: 未找到命令
[root@localhost yum.repos.d]# yum -y install weget
......
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
-bash: wget: 未找到命令
[root@localhost /]# cd ~
[root@localhost ~]# yum -y install wget
......
已安装:
  wget.x86_64 0:1.14-15.el7_4.1
完毕!
[root@localhost ~]# cd /etc/repos.d/
-bash: cd: /etc/repos.d/: 没有那个文件或目录
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo

4.接下来我们通过命令(mv 源文件  备份文件)mv CentOS-Base.repo CetnOs-Base.repo.bak进行CentOs默认的yum进行文件备份,注意一定要先在/yum.repos.d/里通过命令ll进行查看yum,确保文件名正确,Centos-7.repo表示的是阿里云yum.CentOS-Base.repo是centOs默认的yum, 备份成功后再次查看,可以看到yum备份文件CentOS-Base.repo.bak, 备份成功后,要把原来的yum通过命令mv Centos-7.repo CentOs-Base.repo跟阿里云的yum进行替换。

[root@localhost yum.repos.d]# mv CentOs-Base.repo CentOs-Base.repo.bak
mv: 无法获取"CentOs-Base.repo" 的文件状态(stat): 没有那个文件或目录
[root@localhost yum.repos.d]# ll
总用量 36
-rw-r--r--. 1 root root 2523 6月  16 06:22 Centos-7.repo //阿里云yum
-rw-r--r--. 1 root root 1664 4月  29 00:35 CentOS-Base.repo//默认的yum
-rw-r--r--. 1 root root 1309 4月  29 00:35 CentOS-CR.repo
-rw-r--r--. 1 root root  649 4月  29 00:35 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 4月  29 00:35 CentOS-fasttrack.repo
.....
[root@localhost yum.repos.d]#  mv CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# mv Centos-7.repo CentOs-Base.repo
[root@localhost yum.repos.d]# cd ~

5、最后再通过cd ~切换到家目录使用命令yum clean all进行一次彻底的清空,再使用命令yum makecache建立一次缓存,最后再使用命令yum update进行一次yum的更新,就Ok了

[root@localhost yum.repos.d]# cd ~
[root@localhost ~]# yum clean all

...........

[root@localhost ~]# yum makecache
已加载插件:fastestmirror
......
元数据缓存已建立
[root@localhost ~]# yum update
......
完毕!

此时就已经配置完毕了!!!

原文地址:https://www.cnblogs.com/zty1304368100/p/11225215.html