超详细CentOs环境下配置阿里云yum源

引言:我们部署docker的时候需要centOs环境,但由于centOs自带的是国外的yum,可能部署docker会产生不稳定的状态,因此我们可以安装国内的yum来替换国外的yum。
1、打开centOs的终端,切换到root用户,拥有了对目录操作的所有权限。通过命令su - 输入密码******,切换到[root-localhost ~]家目录注意[root@localhost /]是根目录,还是有区别的

[root@localhost ~]#:

2、检查网络状态,因为我们的阿里云yum是需要通过网络下载的,如果没有网,那么一切操作都是白费的,输入命令ifconfig进行查看,如果提示未找到命令,说明没有安装net-tools工具,输入命令yum install net-tools进行安装工具,接下来会出来一大堆东西,直接输入命令y通过即可;接下来输入ifconfig进行查看网络状态,可以看到ens33ip地址,说明网络状态是已连接的,当然也可以输入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
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet
192.168.159.130  netmask 255.255.255.0  broadcast 192.168.159.255
        inet6 fe80::65ae:9fa1:2bc7:506a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:57:6d:76  txqueuelen 1000  (Ethernet)
        RX packets 13067  bytes 13105128 (12.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4994  bytes 419253 (409.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 372  bytes 31280 (30.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 372  bytes 31280 (30.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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/
总用量 32
-rw-r--r--. 1 root root 1664 4月  29 00:35
CentOS-Base.repo
-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
-rw-r--r--. 1 root root  630 4月  29 00:35 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 4月  29 00:35 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 4月  29 00:35 CentOS-Vault.repo
[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
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: centos.ustc.edu.cn
 * updates: mirrors.cn99.com
没有可用软件包 weget。
错误:无须任何处理
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
-bash: wget: 未找到命令
[root@localhost yum.repos.d]# cd ..
[root@localhost etc]# cd /

[root@localhost /]# cd ~
[root@localhost ~]# yum -y install wget
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: centos.ustc.edu.cn
 * updates: mirrors.cn99.com
正在解决依赖关系
--> 正在检查事务

.................

Running transaction
  正在安装    : wget-1.14-15.el7_4.1.x86_64                                                                                                                          1/1
  验证中      : wget-1.14-15.el7_4.1.x86_64                                                                                                                          1/1

已安装:
  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
--2018-08-22 10:01:59--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 118.212.224.105, 118.212.224.104, 118.212.224.106, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|118.212.224.105|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “Centos-7.repo”

100%[===============================================================================================================================>] 2,523       --.-K/s 用时 0s

2018-08-22 10:01:59 (252 MB/s) - 已保存 “Centos-7.repo” [2523/2523])

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
-rw-r--r--. 1 root root  630 4月  29 00:35 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 4月  29 00:35 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 4月  29 00:35 CentOS-Vault.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]# ll
总用量 36

-rw-r--r--. 1 root root 2523 6月  16 06:22 CentOs-Base.repo//已经替换后的yum
-rw-r--r--. 1 root root 1664 4月  29 00:35 CentOS-Base.repo.bak//备份的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
-rw-r--r--. 1 root root  630 4月  29 00:35 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 4月  29 00:35 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 4月  29 00:35 CentOS-Vault.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
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com

..............

元数据缓存已建立
[root@localhost ~]# yum update
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com

.........

结语:希望以上内容能够帮助大家,如有错误欢迎指出。
 


 


 

猜你喜欢

转载自blog.csdn.net/liqz666/article/details/81939181