redhat系统安装好尽管默认带有yum,但是redhat的更新包只对注册用户有效(收费)。所以需要更换yum源。
基本的流程就是:
1.删除redhat7.0系统自带的yum软件包;
2.自行下载所需要的软件包;
3.根据依赖项安装;
4.新建repo配置文件。
一般来说,之后就可以正常使用了。可能还会遇到一些依赖项的问题,后面会提到。
1、查看自带的yum软件包
这下面列出来的软件包,要记住一下,后面要根据其来搜索rpm包来安装新版本。比如”yum-utils”、”yum-langpacks”等等。
2、卸载这些安装包
[root@linuxprobe ~]# rpm -e yum-3.4.3-118.el7.noarch --nodeps
[root@linuxprobe ~]# rpm -e yum-utils-1.1.31-24.el7.noarch --nodeps
[root@linuxprobe ~]# rpm -e yum-rhn-plugin-2.0.1-4.el7.noarch --nodeps
[root@linuxprobe ~]# rpm -e yum-metadata-parser-1.1.4-10.el7.x86_64 --nodeps
[root@linuxprobe ~]# rpm -e yum-langpacks-0.4.2-3.el7.noarch --nodeps
[root@linuxprobe ~]# rpm -e PackageKit-yum-0.8.9-11.el7.x86_64 --nodeps
3、保证上网正常
ping www.baidu.com
4、进入以下网站下载对应的rpm包
阿里云网络源地址:https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
网易163网络源地址:http://mirrors.163.com/
CentOS网络源地址:http://centos.ustc.edu.cn/centos/
使用CTRL+F输入关键字查找对应的安装包即可。
5、找到安装包后下载下来
由于输出结果较多,故省略,下面是输入指令
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-45.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-45.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
本人是直接到上边网站上挨个下载的!
6、安装
输入指令rpm -ivh yum-*,遇到报错,依赖项问题。
[root@192 ~]# rpm -ivh yum-*
警告:yum-3.4.3-161.el7.centos.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4 a80eb5: NOKEY
错误:依赖检测失败:
python-urlgrabber >= 3.10-8 被 yum-3.4.3-161.el7.centos.noarch 需要
rpm >= 0:4.11.3-22 被 yum-3.4.3-161.el7.centos.noarch 需要
yum-plugin-fastestmirror 被 yum-3.4.3-161.el7.centos.noarch 需要
另外再回去找安装包下载下来:
yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
python-urlgrabber-3.10-9.el7.noarch.rpm
rpm-4.11.3-32.el7.x86_64.rpm
输入指令更新rpm:
rpm -Uvh yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm --nodeps
rpm -Uvh python-urlgrabber-3.10-9.el7.noarch.rpm --nodeps
rpm -Uvh rpm-4.11.3-25.el7.x86_64.rpm --nodeps
注意:在安装新版本的rpm包时,使用-Uvh参数,不要用-ivh参数,附加–nodeps
再次运行rpm -ivh yum-* 恢复正常
[root@1 ~]# rpm -ivh yum-*
警告:yum-3.4.3-161.el7.centos.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4 a80eb5: NOKEY
警告:软件包 yum-3.4.3-161.el7.centos.noarch 已被加入,跳过 yum-3.4.3-161.el7.ce ntos.noarch
准备中... ################################# [100%]
正在升级/安装...
1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 17%]
2:yum-plugin-fastestmirror-1.1.31-5################################# [ 33%]
3:yum-3.4.3-161.el7.centos ################################# [ 50%]
4:yum-langpacks-0.4.2-7.el7 ################################# [ 67%]
5:yum-rhn-plugin-2.0.1-10.el7 ################################# [ 83%]
6:yum-utils-1.1.31-50.el7 ################################# [100%]
7、新建repo配置文件
创建repo文件:
vim /etc/yum.repos.d/CentOS-Base.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-7 - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-7 - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
开始在网上找了好多配置文件内容,建立缓存时都有如下报错:
failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
http://mirrors.163.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
后来将文件中所有的**$releasever更换为7**(最新版本号)后才恢复正常!!
最后:
yum -y clean all
yum -y makecache