当前位置: 代码网 > 服务器>服务器>Linux > redhat服务器更换为centos yum源方式

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

2025年12月05日 Linux 我要评论
请看完全篇文章在决定是否参考该文章1.卸载原有的yum# 查看是有安装了yumrpm -qa|grep yum# 卸载原有的yumrpm -qa|grep yum|xargs rpm -e --nod

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

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

这些仅为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com