RedHat-8.0配置yum仓库(在线安装)

01、测试yum仓库是否能正常使用

【更新】:由于阿里云镜像站内的CentOS 8 结束生命周期,导致本文中的基于CentOS 8配置时会出现问题,所以对原文章进行了重新编辑,使用CentOS 7的镜像。请博友们参照该文章进行配置时将yum源使用其他网站的源,或者将文章中CentOS-8自行更改成CentOS-7.或者查看重新编辑后的基于CentOS-7版本的文章【新版本文章地址:https://blog.csdn.net/sinat_31633205/article/details/124906766

[root@bogon ~]# yum install vsftpd
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Error: There are no enabled repos.
[root@bogon ~]# 

报错:系统未注册。说明该yum仓库功能无法正常使用,而 RedHat自带的仓库又需要付费才能使用,身为技术人,花钱买技术那是不可能的。
解决办法:更换为Centos-8的yum源

02、yum常用命令

yum install -y httpd (功能描述:安装httpd并确认安装)
yum list (功能描述:列出所有可用的package和package组)
yum clean all (功能描述:清除所有缓冲数据)
yum deplist httpd (功能描述:列出一个包所有依赖的包)
yum remove httpd (功能描述:删除httpd) 

03、前期准备工作

1)确定redhat操作系统可以上网,如果是在虚拟机上安装的系统,可以讲系统的网络诺配置器改成NAT模式,如图所示,只要主机能上网,则虚拟机中的操作系统就可以上网。
在这里插入图片描述
2)下载适合redhat版本的repo文件(本文以CentOS-8为例),下载地址:
repo下载地址
下载Centos-8.repo

04、将下载下来的repo拷贝至redhat系统的yum.repos.d文件夹中

[root@bogon ~]#cp /tmp/pkg/Centos-8.repo /etc/yum.repos.d

05、查看系统自身安装的yum软件包

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

06、卸载所有自带yum软件包

[root@bogon ~]# rpm -e 软件包名称 --nodeps  #可以使用简称如 rpm -e yum-* --nodeps

07、修改04步骤中上传的Centos-8.repo文件内容

07-01、首先备份/etc/yum.repos.d/Centos-8.repo

[root@bogon ~]#mv /etc/yum.repos.d/Centos-8.repo /etc/yum.repos.d/Centos-8.repo.backup

07-02、修改Centos-8.repo文件中的内容

查看更改前文件内容:

[root@bogon yum.repos.d]# cat Centos-8.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-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.cloud.aliyuncs.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/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/os/
        http://mirrors.cloud.aliyuncs.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/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
        http://mirrors.cloud.aliyuncs.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/
        http://mirrors.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
        http://mirrors.cloud.aliyuncs.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/
        http://mirrors.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[root@bogon yum.repos.d]# 

更改内容:
1)将无效的网络地址删除掉或者注释(本文中采用删除的方式,将内网地址删除掉)
2)将文中的$releasever 替换成 要采用的redhat系统版本号(本文的为8)
其他版本号可以查看网址:CentOS版本号

[root@bogon ~]# vim /etc/yum.repos.d/Centos-8.repo

更改后的Centos-8.repo文件内容:

[root@bogon ~]# cat /etc/yum.repos.d/Centos-8.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-8- Base - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8/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-8- Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8/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-8- Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8/centosplus/$basearch/os/
       
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
 
[PowerTools]
name=CentOS-8- PowerTools - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8/PowerTools/$basearch/os/
        
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official


[AppStream]
name=CentOS-8- AppStream - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8/AppStream/$basearch/os/
       
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[root@bogon ~]# 

08、清除缓存

[root@bogon ~]# yum clean all
-bash: /usr/bin/yum: No such file or directory

报错:-bash: /usr/bin/yum: No such file or directory 没有文件或者文件夹
解决方法:需要安装yum命令。执行如下命令:

[root@bogon ~]# rpm -ivh --nodeps https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/Packages/yum-4.2.23-4.el8.noarch.rpm 

结果:
在这里插入图片描述
查看可用 yum repolist all 结果如下:
在这里插入图片描述
yum源可以正常访问。
重新执行命令清除缓存。

09、将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度

[root@bogon ~]# yum makecache

10、开始使用yum在线安装软件吧!

(注意:Redhat的注册提示信息仍会出现,但可以正常使用yum功能)

鄙人拙见 , 请不吝赐教!!!

  • 20
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 16
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yang JZ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值