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,请根据自己的版本进行更改

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

相关文章

  • PHP程序员玩转Linux系列 lnmp环境搭建

    PHP程序员玩转Linux系列 lnmp环境搭建

    这篇文章主要为大家详细介绍了PHP程序员玩转Linux系列文章,lnmp环境搭建教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-04-04
  • linux中$符号的基础用法总结

    linux中$符号的基础用法总结

    这篇文章主要给大家介绍了关于linux中$符号的基础用法,文中通过示例代码介绍的非常详细,对大家学习或者使用linux系统具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-11-11
  • Linux系统下Squid代理服务器的配置详细指南

    Linux系统下Squid代理服务器的配置详细指南

    Squid作为Linux系统上广泛使用的开源代理服务器,能够缓存网页内容以提升网络访问速度,本文将为大家详细介绍Linux系统下Squid代理服务器的配置的详细步骤,需要的可以了解下
    2025-09-09
  • Linux系统利用cp命令实现强制覆盖功能的方法

    Linux系统利用cp命令实现强制覆盖功能的方法

    cp命令是我日常学习中经常会遇到的一个命令,下面这篇文章主要给大家介绍了关于Linux系统利用cp命令实现强制覆盖功能的方法,并且给大家简单的介绍了cp命令的基础知识,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧。
    2017-11-11
  • Linux之死锁与解决方式

    Linux之死锁与解决方式

    这篇文章主要介绍了Linux之死锁与解决方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-02-02
  • 在RHEL 6.5上使用yum更新/安装软件的操作方法

    在RHEL 6.5上使用yum更新/安装软件的操作方法

    下面小编就为大家带来一篇在RHEL 6.5上使用yum更新/安装软件的操作方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-12-12
  • Linux passwd 命令的使用

    Linux passwd 命令的使用

    这篇文章主要介绍了Linux passwd 命令的使用,帮助大家更好的理解和学习Linux,感兴趣的朋友可以了解下
    2020-08-08
  • Centos 6.5 服务器优化配置备忘(一些基础优化和安全设置)

    Centos 6.5 服务器优化配置备忘(一些基础优化和安全设置)

    这篇文章主要介绍了Centos 6.5 服务器优化(一些基础优化和安全设置),需要的朋友可以参考下
    2016-10-10
  • Centos7添加静态路由的方法

    Centos7添加静态路由的方法

    本篇文章主要介绍了Centos7添加静态路由的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-02-02
  • 阿里云服务器ubuntu 配置教程

    阿里云服务器ubuntu 配置教程

    这篇文章主要介绍了阿里云服务器ubuntu 配置方法,本文分步骤给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-10-10

最新评论