近日新安装了 redhat 但是没有图形界面,无奈自带的 yum 没法使用(提示:This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.),只有替换为 centos 的 yum 包。
下面是操作步骤:
1、查看现有安装的 yum
[root@localhost ~]# rpm -qa |grep yum PackageKit-yum-0.5.8-21.el6.x86_64 yum-metadata-parser-1.1.2-16.el6.x86_64 yum-plugin-security-1.1.30-14.el6.noarch yum-utils-1.1.30-14.el6.noarch yum-rhn-plugin-0.9.1-48.el6.noarch yum-3.2.29-40.el6.noarch PackageKit-yum-plugin-0.5.8-21.el6.x86_64
2、删除现在自带的 yum
[root@localhost ~]# rpm -qa|grep yum|xargs rpm -e --nodeps
再来查看卸载完没
[root@localhost ~]# rpm -qa |grep yum [root@localhost ~]#
3、下载 centos6 的 yum 安装包
64 位的系统要选择 64 位的安装包,可以在 163 的镜像站去下载 http://tel.mirrors.163.com/centos/ 。
找到对应的包后下载下面 4 个文件:
[root@localhost ~]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-73.el6.centos.noarch.rpm --2017-03-08 16:26:49-- http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-73.el6.centos.noarch.rpm 正在解析主机 mirrors.163.com... 123.58.173.185, 123.58.173.186 正在连接 mirrors.163.com|123.58.173.185|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:1039196 (1015K) [application/x-redhat-package-manager] 正在保存至: “yum-3.2.29-73.el6.centos.noarch.rpm” 100%[============================================================================>] 1,039,196 1.09M/s in 0.9s 2017-03-08 16:26:50 (1.09 MB/s) - 已保存 “yum-3.2.29-73.el6.centos.noarch.rpm” [1039196/1039196]) [root@localhost ~]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm --2017-03-08 16:30:00-- http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm 正在解析主机 mirrors.163.com... 123.58.173.186, 123.58.173.185 正在连接 mirrors.163.com|123.58.173.186|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:27224 (27K) [application/x-redhat-package-manager] 正在保存至: “yum-metadata-parser-1.1.2-16.el6.x86_64.rpm” 100%[============================================================================>] 27,224 --.-K/s in 0.04s 2017-03-08 16:30:00 (623 KB/s) - 已保存 “yum-metadata-parser-1.1.2-16.el6.x86_64.rpm” [27224/27224]) [root@localhost ~]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm --2017-03-08 16:32:17-- http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm 正在解析主机 mirrors.163.com... 123.58.173.185, 123.58.173.186 正在连接 mirrors.163.com|123.58.173.185|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:32844 (32K) [application/x-redhat-package-manager] 正在保存至: “yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm” 100%[============================================================================>] 32,844 --.-K/s in 0.08s 2017-03-08 16:32:19 (402 KB/s) - 已保存 “yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm” [32844/32844]) [root@localhost ~]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm --2017-03-08 16:33:38-- http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm 正在解析主机 mirrors.163.com... 123.58.173.186, 123.58.173.185 正在连接 mirrors.163.com|123.58.173.186|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:37052 (36K) [application/x-redhat-package-manager] 正在保存至: “python-iniparse-0.3.1-2.1.el6.noarch.rpm” 100%[============================================================================>] 37,052 --.-K/s in 0.09s 2017-03-08 16:33:49 (408 KB/s) - 已保存 “python-iniparse-0.3.1-2.1.el6.noarch.rpm” [37052/37052])
安装 yum
首先安装 “python-iniparse-0.3.1-2.1.el6.noarch.rpm”
[root@localhost ~]# rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm warning: python-iniparse-0.3.1-2.1.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] package python-iniparse-0.3.1-2.1.el6.noarch is already installed
再安装 “yum-metadata-parser-1.1.2-16.el6.x86_64.rpm”
[root@localhost ~]# rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm warning: yum-metadata-parser-1.1.2-16.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:yum-metadata-parser ########################################### [100%]
最后两个文件要一起安装
[root@localhost ~]# rpm -ivh yum-3.2.29-40.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm warning: yum-3.2.29-73.el6.centos.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY error: Failed dependencies: python-urlgrabber >= 3.9.1-10 is needed by yum-3.2.29-73.el6.centos.noarch
上面出错,提示依赖更高版本的 python-urlgrabber
[root@localhost ~]# wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm --2017-03-08 16:44:47-- http://mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm 正在解析主机 mirrors.163.com... 123.58.173.185, 123.58.173.186 正在连接 mirrors.163.com|123.58.173.185|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:87660 (86K) [application/x-redhat-package-manager] 正在保存至: “python-urlgrabber-3.9.1-11.el6.noarch.rpm” 100%[============================================================================>] 87,660 --.-K/s in 0.1s 2017-03-08 16:44:48 (627 KB/s) - 已保存 “python-urlgrabber-3.9.1-11.el6.noarch.rpm” [87660/87660]) [root@localhost ~]# rpm -Uvh python-urlgrabber-3.9.1-11.el6.noarch.rpm warning: python-urlgrabber-3.9.1-11.el6.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:python-urlgrabber ########################################### [100%]
再来就成功了
[root@localhost ~]# rpm -ivh yum-3.2.29-73.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm warning: yum-3.2.29-73.el6.centos.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:yum-plugin-fastestmirro########################################### [ 50%] 2:yum ########################################### [100%]
4、更换 yum 源,使用 163 的源。
切换路径
[root@localhost ~]# cd /etc/yum.repos.d/
下载文件
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
编辑文件,把文件里面的 $releasever 全部替换为版本号(sed -i ‘s/\$releasever/6/g’ CentOS6-Base-163.repo),即 “6” 最后保存,参照下面的值。
[root@localhost yum.repos.d]# cat CentOS6-Base-163.repo # 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
5、最后检查
清空原 yum 缓存
[root@localhost yum.repos.d]# yum clean all
重建缓存,将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度
[root@localhost yum.repos.d]# yum makecache
更新 yum
[root@localhost yum.repos.d]# yum update
查看 yum 源
[root@localhost yum.repos.d]# yum list
原创文章,作者:tipak,如若转载,请注明出处:http://www.myqqu.com/backend/redhat_change_to_centos_yum_source.html