首页 > 技术文章 > RedHat7.4最小化安装yum源不可用问题解决

nbartchen 2018-03-15 14:22 原文

本次安装的RedHat7.4是安装在Oracle VM VirtualBox5.2.8虚拟机上面的,本文不对安装虚拟机步骤做详细说明。

工具准备:

  Oracle VM VirtualBox5.2.8

  rhel-server-7.4-x86_64-dvd.iso

安装平台;

  win10_x86_64

解决办法:

1、修改网络配置

在RedHat7之后ifconfig命令查看网络命令受限,在登录系统后,可以使用下面的命令查看当前的一些ip地址等网络信息

[root@localhost ~]# ip addr

如果要修改网络配置,使用下面的命令

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 

 修改BOOTPRTO=static,ONBOOT=yes,然后在最下面加入下面的配置

IPADDR=192.168.3.210
PREFIXO=24
GATEWAY=192.168.3.1
DNS1=114.114.114.114

修改之后的配置文件内容如下图所示:

 

保存并退出之后,使用命令

[root@localhost ~]# service network restart
Restarting network (via systemctl):                        [  OK  ]

 测试外网能否请求:

[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=54 time=42.8 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=54 time=40.9 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=3 ttl=54 time=41.6 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=4 ttl=54 time=40.6 ms
^Z
[1]+  Stopped                 ping www.baidu.com

此时,使用yum命令会出现问题

[root@localhost ~]# yum install lrzsz
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.

2、查看系统中的yum,如果有进行卸载

[root@localhost ~]# rpm -qa |grep yum
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-rhn-plugin-2.0.1-9.el7.noarch
yum-3.4.3-154.el7.noarch

 删除redhat自带的yum包

[root@localhost ~]# rpm -qa|grep yum|xargs rpm -e --nodeps

再进行检查,确认卸载完成

[root@localhost ~]# rpm -qa |grep yum
[root@localhost ~]# 

3、下载163的yum安装包

 在网站:http://mirrors.163.com/有相关的许多开源包下载,我们这儿需要的安装包在路径:http://mirrors.163.com/centos/7.4.1708/os/x86_64/Packages/ 中,需要下载的有下面的内容:

http://mirrors.163.com/centos/7.4.1708/os/x86_64/RPM-GPG-KEY-CentOS-7
http://mirrors.163.com/centos/7.4.1708/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm
http://mirrors.163.com/centos/7.4.1708/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
http://mirrors.163.com/centos/7.4.1708/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-42.el7.noarch.rpm
http://mirrors.163.com/centos/7.4.1708/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm

除了上述文件之外,还需要一个CentOS6-Base-163.repo文件,可以通过百度云盘进行搜索下载,在下载完成后通过WinSCP上传到操作系统中。还需要将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-7.4.1708 - Base - 163.com
baseurl=http://mirrors.163.com/centos/7.4.1708/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7.4.1708&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

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

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

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

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

使用下面的命令开始yum源的安装,本人安装的时候两个都用了,有的资料上只使用了其中的一个,本人安装使用第一个只安装了python相关的包,而且提示有警告,再使用第二个命令之后才安装完yum-抬头的相关包。

[root@localhost ~]# rpm -ivh *.rpm
[root@localhost ~]# rpm -ivh yum-*

如果安装时出现依赖包的问题,有可能会出现Python包安装冲突的问题。所以在此处命令可以加上两个参数强制安装:

  1. --force 即使覆盖属于其它包的文件也强迫安装
  2. --nodeps 如果该RPM包的安装依赖其它包,即使其它包没装,也强迫安装。

安装完成之后需要将上传的CentOS6-Base-163.repo文件以及RPM-GPG-KEY-CentOS-7文件移动到相应的位置中。 

[root@localhost ~]# mv CentOS6-Base-163.repo /etc/yum.repos.d/
[root@localhost ~]# mv RPM-GPG-KEY-CentOS-7 /etc/pki/rpm-gpg/

经过这步之后经测试可以使用yum的相关命令的,可以安装SecureCRT上传下载相关的组件

[root@localhost yum.repos.d]# yum install lrzsz

但是既然有RPM-GPG-KEY-CentOS-7文档,我们应该将它也转入相关的目录下面,虽然现在测试不转好像也没有影响。根据百度查找RPM-GPG-KEY-CentOS-7文件应当放入目录/etc/pki/rpm-gpg/中。查看/etc/pki/rpm-gpg/中的内容并将RPM-GPG-KEY-CentOS-7文件移动到该目录中。

[root@localhost yum.repos.d]# cd
[root@localhost ~]# cd /etc/pki/rpm-gpg/
[root@localhost rpm-gpg]# ls
RPM-GPG-KEY-redhat-beta            RPM-GPG-KEY-redhat-legacy-rhx
RPM-GPG-KEY-redhat-legacy-former   RPM-GPG-KEY-redhat-release
RPM-GPG-KEY-redhat-legacy-release
[root@localhost rpm-gpg]# cd
[root@localhost ~]# mv RPM-GPG-KEY-CentOS-7 /etc/pki/rpm-gpg/
[root@localhost ~]# cd /etc/pki/rpm-gpg/
[root@localhost rpm-gpg]# ls
RPM-GPG-KEY-CentOS-7              RPM-GPG-KEY-redhat-legacy-release
RPM-GPG-KEY-redhat-beta           RPM-GPG-KEY-redhat-legacy-rhx
RPM-GPG-KEY-redhat-legacy-former  RPM-GPG-KEY-redhat-release

 在上述完成之后

[root@localhost ~]# yum clear all
[root@localhost ~]# yum makecache

至此所有的配置完成。

 

推荐阅读