*Redhat 8 yum安装报错Error: No available modular metadata for modular package
红帽8,默认是不可以使用yum的,dnf就相当于yum,由于一直使用yum习惯了,所以可以通过命令安装yum
dnf install yum -y
如果不想安装,可以直接使用dnf,和yum用法是一样的!
在公司测试环境使用yum安装时出现这个报错(测试环境是不可以访问外网的),我在网上找了好多关于这个报错的资料,但是都不适用,后来经过不断地尝试,在自己本地虚拟机上做实验(自己电脑可以访问外网),最后锁定是repo源的问题,我这里是使用的国内的阿里源,写出来分享一下。
方法一、二适用于可以访问外网的情况
方法一:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
方法二:
在浏览器输入https://mirrors.aliyun.com/repo/Centos-8.repo直接下载之后放在/etc/yum.repos.d/下。
也可以直接粘贴以下内容使用
# 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-$releasever - Base - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-$releasever - PowerTools - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
yum clean all
yum makecache
问题完美解决!
方法三:
适用于公司电脑不能直接访问外网,通过在DMZ区搭建nexus3实现代理内网机器去外网拉取镜像,nexus默认端口为8081,可以在配置文件中修改
(Nexus3的搭建可参考网上文章,或后续有时间我会更新,需要注意的是,需要防火墙配置设置可以访问的URL,例如国内的阿里源,清华源等。)
将上述下载的repo源url进行替换即可
例:
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/$releasever/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-$releasever - PowerTools - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=http://x.x.x.x:8081/repository/yum-proxy-aliyun/centos/RPM-GPG-KEY-CentOS-Official
有问题欢迎留言探讨!