替换redhat的yum安装源

删除 redhat 原有的 yum 源

# rpm -aq | grep yum|xargs rpm -e --nodeps

下载新的 yum 安装包

  • 此处使用 CentOS 的 yum 源
1
2
3
4
# wget http://mirror.centos.org/centos/6.5/os/i386/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
# wget http://mirror.centos.org/centos/6.5/os/i386/Packages/yum-metadata-parser-1.1.2-16.el6.i686.rpm
# wget http://mirror.centos.org/centos/6.5/os/i386/Packages/yum-3.2.29-40.el6.centos.noarch.rpm
# wget http://mirror.centos.org/centos/6.5/os/i386/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm

安装 yum 软件包

1
2
3
# rpm -ivh  python-iniparse-0.3.1-2.1.el6.noarch.rpm
# rpm -ivh yum-metadata-parser-1.1.2-14.1.el6.i686.rpm
# rpm -ivh yum-3.2.27-14.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.26-11.el6.noarch.rpm
  • 注意:最后两个安装包相互依赖,要放在一起同时安装,否则安装失败.

更改 yum 源

  • 使用网易的 CentOS 镜像源
1
2
3
# cd /etc/yum.repos.d/
# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
# vi CentOS6-Base-163.repo
  • 编辑文件,把$releasever全部替换为版本号“6”,
1
`:%s/$releasever/6/g`.
  • 或者直接把以下内容拷贝到CentOS6-Base-163.repo文件中(已修改)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#########################################################################
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-6 - Base - 163.com
baseurl=http://mirrors.163.com/centos/6/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-6 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#########################################################################

清理 yum 缓存

# yum clean all
# yum makecache       //将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度
# yum install vim*    //测试域名是否可用

至此,Redhat6 可以使用 CentOS 的 yum 源在线安装软件.

参考资料