将CentOS系统软件包yum源更新为阿里云

前端之家收集整理的这篇文章主要介绍了将CentOS系统软件包yum源更新为阿里云前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

第一步,备份老的yum源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.old

第二步,下载阿里云的yum源

cd  /etc/yum.repos.d/

wget -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

[root@localhost yum.repos.d]# ls -lrt
total 24
-rw-r--r--. 1 root root 3664 Nov 27  2013 CentOS-Vault.repo
-rw-r--r--. 1 root root  630 Nov 27  2013 CentOS-Media.repo
-rw-r--r--. 1 root root  638 Nov 27  2013 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 1926 Nov 27  2013 CentOS-Base.repo.old
-rw-r--r--. 1 root root 2572 May 14  2015 Centos-6.repo
-rw-r--r--. 1 root root  460 Jul 23 23:28 CentOS-Base.repo

说明:
centos5可以用下面的源:
wget -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

第三步,更新源

[root@localhost yum.repos.d]# mv Centos-6.repo CentOS-Base.repo 
mv: overwrite `CentOS-Base.repo'? y

第四步,清理下载的header和packages

yum clean headers清除header,yum clean packages清除下载的rpm包,yum clean all一全部清除。

[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror,refresh-packagekit,security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors

第五步,生成header和package缓存

yum makecache 是 将服务器上的软件包信息现在本地缓存,以提高搜索安装软件的速度

[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror,security
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                             | 3.7 kB 00:00 
base/group_gz                                    | 226 kB 00:00 
base/filelists_db                                | 6.4 MB 00:06 
base/primary_db                                  | 4.7 MB 00:04 
base/other_db                                    | 2.8 MB 00:02 
extras                                           | 3.4 kB 00:00 
extras/filelists_db                              | 25 kB 00:00 
extras/prestodelta                               | 1.3 kB 00:00 
extras/primary_db                                | 29 kB 00:00 
extras/other_db                                  | 30 kB 00:00 
updates                                          | 3.4 kB 00:00 
updates/filelists_db                             | 1.6 MB 00:01 
updates/prestodelta                              | 66 kB 00:00 
updates/primary_db                               | 2.5 MB 00:02 
updates/other_db                                 | 34 MB 00:33 
Metadata Cache Created
[root@localhost yum.repos.d]# 

第六步,安装一个软件试验一下

[root@localhost yum.repos.d]# yum install vsftpd
Loaded plugins: fastestmirror,security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-24.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================
 Package                                                 Arch                                                    Version                                                         Repository                                             Size
=============================================================================================================================================================================================================================================
Installing:
 vsftpd                                                  x86_64                                                  2.2.2-24.el6                                                    base                                                  156 k

Transaction Summary
=============================================================================================================================================================================================================================================
Install       1 Package(s)

Total download size: 156 k
Installed size: 340 k
Is this ok [y/N]: y
Downloading Packages:
http://mirrors.aliyun.com/centos/6/os/x86_64/Packages/vsftpd-2.2.2-24.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.aliyun.com'"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/6/os/x86_64/Packages/vsftpd-2.2.2-24.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.aliyuncs.com'"
Trying other mirror.


Error Downloading Packages:
  vsftpd-2.2.2-24.el6.x86_64: failure: Packages/vsftpd-2.2.2-24.el6.x86_64.rpm from base: [Errno 256] No more mirrors to try.

我们发现报错Couldn’t resolve host ‘mirrors.aliyun.com,需要更新一下DNS。

第七步,更新DNS

[root@localhost yum.repos.d]# vi /etc/resolv.conf

增加一行
nameserver 8.8.8.8

再次试验

[root@localhost yum.repos.d]# yum install vsftpd
Loaded plugins: fastestmirror,security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-24.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================
 Package                                                 Arch                                                    Version                                                         Repository                                             Size
=============================================================================================================================================================================================================================================
Installing:
 vsftpd                                                  x86_64                                                  2.2.2-24.el6                                                    base                                                  156 k

Transaction Summary
=============================================================================================================================================================================================================================================
Install       1 Package(s)

Total download size: 156 k
Installed size: 340 k
Is this ok [y/N]: y
Downloading Packages:
vsftpd-2.2.2-24.el6.x86_64.rpm                                                                                                                                                                                        | 156 kB     00:00     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature,key ID c105b9de: NOKEY
Retrieving key from http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid: "CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>"
 From  : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : vsftpd-2.2.2-24.el6.x86_64                                                                                                                                                                                                1/1 
  Verifying  : vsftpd-2.2.2-24.el6.x86_64                                                                                                                                                                                                1/1 

Installed:
  vsftpd.x86_64 0:2.2.2-24.el6                                                                                                                                                                                                               

Complete!
[root@localhost yum.repos.d]# 

补充

yum 主要的一下命令如下:

yum search 软件包   搜索软件包
yum install 软件包   安装软件包
yum remove 软件包
yum update  更新系统

我们也可以更新软件包源为163或者中科大的:

http://mirrors.163.com/          163镜像地址
http://centos.ustc.edu.cn/       中科大镜像地址

可以通过更改baseurl的方式进行更新,具体搜索网上资料即可,推荐下面一篇:
http://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html

猜你在找的CentOS相关文章