redhat服务器更换为centos yum源方式

 更新时间:2025年12月05日 08:58:10   作者:仰望星空下的自己  
该文章主要介绍了如何在CentOS系统中手动下载和配置Yum源,包括下载Yum源文件、修改CentOS-Base.repo文件、验证更新等步骤

请看完全篇文章在决定是否参考该文章

1.卸载原有的yum

# 查看是有安装了yum
rpm -qa|grep yum
# 卸载原有的yum
rpm -qa|grep yum|xargs rpm -e --nodeps

2.找一个自己喜欢的目录新建checkYum.sh(文件名随意)

该文件主要是下载yum源需要的内容并且安装yum

#!/bin/bash
# 7.9.2009 对应的centos的版本号
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
rpm -ivh /pkg/yum-*

3.下载响应的repo源文件

# 建议先将该目录下的文件进行备份
cd /etc/yum.repos.d/CentOS-Base.repo
# 该命令也可以写到上一步的文件中一起下载
# 如果写到文件中可以使用  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

4.修改CentOS-Base.repo文件内容

4.1. 下载后的源文件

# 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 - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

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

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/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-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

4.2. 修改后的文件

将所有的$releasever更改为自己下载.rpm文件对应的版本

eg:

我自己:http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-169.el7.centos.noarch.rpm;

我这里下载的是7.9.2009的所以将$releasever更改为7.9.2009,其他的不需要更改

# 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.9.2009 - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-7.9.2009 - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7.9.2009/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.9.2009 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7.9.2009/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.9.2009 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

5.更新

yum clean all && yum makecache

6.查看是否更新成功

yum repolist all

7.以上命令可以完全写到一个统一shell脚本中

rpm -qa | grep yun | xargs rpm -e --nodeps
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
rpm -ivh /pkg/yum-*
# 下载repo源文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
# 统一将$releasever更改为指定的版本
sed -i "s/\$releasever/7.9.2009/g" /etc/yum.repos.d/CentOS-Base.repo
yum clean all && yum makecache
yum repolist all

总结

以上使用的redhat版本为redhat7.5,请根据自己的版本进行更改

这些仅为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • linux系统之如何禁用usb口

    linux系统之如何禁用usb口

    这篇文章主要介绍了linux系统之如何禁用usb口问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-06-06
  • 在VMware虚拟机里安装Linux操作系统

    在VMware虚拟机里安装Linux操作系统

    这篇文章介绍了在VMware虚拟机里安装Linux操作系统的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-03-03
  • 阿里云OSS访问权限配置(RAM权限控制)实现

    阿里云OSS访问权限配置(RAM权限控制)实现

    这篇文章主要介绍了阿里云OSS访问权限配置(RAM权限控制)实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-08-08
  • Linux安装Python虚拟环境virtualenv的方法

    Linux安装Python虚拟环境virtualenv的方法

    下面小编就为大家带来一篇Linux安装Python虚拟环境virtualenv的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-01-01
  • CentOS 配置无密码登录的实现

    CentOS 配置无密码登录的实现

    这篇文章主要介绍了CentOS 配置无密码登录的实现的相关资料,需要的朋友可以参考下
    2017-06-06
  • 使用 Linux seq 命令生成数字序列(推荐)

    使用 Linux seq 命令生成数字序列(推荐)

    seq命令用于以指定增量从首数开始打印数字到尾数,即产生从某个数到另外一个数之间的所有整数,并且可以对整数的格式、宽度、分割符号进行控制。这篇文章主要介绍了使用 Linux seq 命令生成数字序列,需要的朋友可以参考下
    2020-01-01
  • ubuntu 下JDK环境变量配置方法

    ubuntu 下JDK环境变量配置方法

    这篇文章主要介绍了ubuntu 下JDK环境变量配置方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2018-03-03
  • ubuntu19系统及以下版本安装android studio的教程

    ubuntu19系统及以下版本安装android studio的教程

    这篇文章主要介绍了ubuntu19系统及以下版本安装android studio的教程,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-10-10
  • grub损坏,开机出现GRUB 2 启动提示符的解决方法

    grub损坏,开机出现GRUB 2 启动提示符的解决方法

    下面小编就为大家带来一篇grub损坏,开机出现GRUB 2 启动提示符的解决方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-12-12
  • Linux系统配置网络详细介绍

    Linux系统配置网络详细介绍

    大家好,本篇文章主要讲的是Linux系统配置网络详细介绍,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下,方便下次浏览
    2022-01-01

最新评论