CentOS7 中把yum源更换成163源

先查看配置文件目录

[centos01@centos01 ~]$ su root
密码:
[root@centos01 centos01]# 
[root@centos01 centos01]# pwd
/home/centos01
[root@centos01 centos01]# 
[root@centos01 centos01]# cd /etc/yum.repos.d
[root@centos01 yum.repos.d]# pwd
/etc/yum.repos.d
[root@centos01 yum.repos.d]# ll
总用量 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@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# 

 

先备份配置文件

[root@centos01 yum.repos.d]# mkdir /etc/yum.repos.d.bak
[root@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# cd /etc/yum.repos.d.bak
[root@centos01 yum.repos.d.bak]# ll
总用量 0
[root@centos01 yum.repos.d.bak]# cp -R /etc/yum.repos.d/* /etc/yum.repos.d.bak 
[root@centos01 yum.repos.d.bak]# 
[root@centos01 yum.repos.d.bak]# pwd
/etc/yum.repos.d.bak
[root@centos01 yum.repos.d.bak]# ll
总用量 32
-rw-r--r--. 1 root root 1664 8月  14 00:08 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 8月  14 00:08 CentOS-CR.repo
-rw-r--r--. 1 root root  649 8月  14 00:08 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 8月  14 00:08 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 8月  14 00:08 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 8月  14 00:08 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 8月  14 00:08 CentOS-Vault.repo
[root@centos01 yum.repos.d.bak]# 

 

设置163源

[centos01@centos01 ~]$ su root
密码:
[root@centos01 centos01]# 
[root@centos01 centos01]# pwd
/home/centos01
[root@centos01 centos01]# 
[root@centos01 centos01]# cd /etc/yum.repos.d
[root@centos01 yum.repos.d]# pwd
/etc/yum.repos.d
[root@centos01 yum.repos.d]# ll
总用量 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@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# mkdir /etc/yum.repos.d.bak
[root@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# cd /etc/yum.repos.d.bak
[root@centos01 yum.repos.d.bak]# ll
总用量 0
[root@centos01 yum.repos.d.bak]# cp -R /etc/yum.repos.d/* /etc/yum.repos.d.bak 
[root@centos01 yum.repos.d.bak]# 
[root@centos01 yum.repos.d.bak]# ll
总用量 32
-rw-r--r--. 1 root root 1664 8月  14 00:08 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 8月  14 00:08 CentOS-CR.repo
-rw-r--r--. 1 root root  649 8月  14 00:08 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 8月  14 00:08 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 8月  14 00:08 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 8月  14 00:08 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 8月  14 00:08 CentOS-Vault.repo
[root@centos01 yum.repos.d.bak]# pwd
/etc/yum.repos.d.bak
[root@centos01 yum.repos.d.bak]# ll
总用量 32
-rw-r--r--. 1 root root 1664 8月  14 00:08 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 8月  14 00:08 CentOS-CR.repo
-rw-r--r--. 1 root root  649 8月  14 00:08 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 8月  14 00:08 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 8月  14 00:08 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 8月  14 00:08 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 8月  14 00:08 CentOS-Vault.repo
[root@centos01 yum.repos.d.bak]# 
[root@centos01 ~]# cd /etc/yum.repos.d
[root@centos01 yum.repos.d]# ll
总用量 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@centos01 yum.repos.d]# pwd
/etc/yum.repos.d
[root@centos01 yum.repos.d]# mv ./CentOS-Base.repo  ./CentOS-Base.repo.bak
[root@centos01 yum.repos.d]# ll
总用量 32
-rw-r--r--. 1 root root 1664 4月  29 00:35 CentOS-Base.repo.bak
-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@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2018-08-14 00:17:13--  http://mirrors.163.com/.help/CentOS7-Base-163.repo
正在解析主机 mirrors.163.com (mirrors.163.com)... 59.111.0.251
正在连接 mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1572 (1.5K) [application/octet-stream]
正在保存至: “CentOS7-Base-163.repo”

100%[=======================================================================================>] 1,572       --.-K/s 用时 0s      

2018-08-14 00:17:14 (120 MB/s) - 已保存 “CentOS7-Base-163.repo” [1572/1572])

[root@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# ll
总用量 36
-rw-r--r--. 1 root root 1572 12月  1 2016  CentOS7-Base-163.repo
-rw-r--r--. 1 root root 1664 4月  29 00:35 CentOS-Base.repo.bak
-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@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# mv ./CentOS7-Base-163.repo  ./CentOS-Base.repo
[root@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# ll
总用量 36
-rw-r--r--. 1 root root 1572 12月  1 2016 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 4月  29 00:35 CentOS-Base.repo.bak
-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@centos01 yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# yum makecache
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
base                                                                                       | 3.6 kB  00:00:00     
extras                                                                                     | 3.4 kB  00:00:00     
updates                                                                                    | 3.4 kB  00:00:00     
(1/12): base/7/x86_64/group_gz                                                             | 166 kB  00:00:01     
(2/12): base/7/x86_64/filelists_db                                                         | 6.9 MB  00:00:33     
(3/12): extras/7/x86_64/prestodelta                                                        |  68 kB  00:00:05     
(4/12): extras/7/x86_64/primary_db                                                         | 173 kB  00:00:00     
(5/12): extras/7/x86_64/other_db                                                           | 110 kB  00:00:01     
(6/12): extras/7/x86_64/filelists_db                                                       | 588 kB  00:00:07     
(7/12): updates/7/x86_64/prestodelta                                                       | 409 kB  00:00:01     
(8/12): updates/7/x86_64/primary_db                                                        | 4.3 MB  00:00:11     
(9/12): updates/7/x86_64/other_db                                                          | 381 kB  00:00:01     
(10/12): base/7/x86_64/primary_db                                                          | 5.9 MB  00:00:59     
(11/12): updates/7/x86_64/filelists_db                                                     | 2.4 MB  00:00:29     
(12/12): base/7/x86_64/other_db                                                            | 2.5 MB  00:00:42     
元数据缓存已建立
[root@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                                                         源名称                                        状态
base/7/x86_64                                                 CentOS-7 - Base - 163.com                    9,911
extras/7/x86_64                                               CentOS-7 - Extras - 163.com                    369
updates/7/x86_64                                              CentOS-7 - Updates - 163.com                 1,041
repolist: 11,321
[root@centos01 yum.repos.d]# 
[root@centos01 yum.repos.d]# 

 

总结:

1、进入yum源配置文件   cd /etc/yum.repos.d

2、备份一下当前的源,以下载网易163的源 wget http://mirrors.163.com/.help/CentOS7-Base-163.repo 防出错后可以还原回来 mv ./CentOS-Base.repo ./CentOS-Base-repo.bak

3、把下载下来文件 CentOS7-Base-163.repo设置成为默认源 mv CentOS7-Base-163.repo CentOS-Base.repo

4、清理一下旧包 yum clean all

5、生成缓存即可用163源了 yum makecache

 

posted @ 2018-08-14 00:01  茗::流  阅读(789)  评论(0)    收藏  举报
如有雷同,纯属参考。如有侵犯你的版权,请联系我。