请看完全篇文章在决定是否参考该文章
- 卸载原有的yum
rpm -qa|grep yum
rpm -qa|grep yum|xargs rpm -e --nodeps
- 找一个自己喜欢的目录新建checkYum.sh(文件名随意)
该文件主要是下载yum源需要的内容并且安装yum
#!/bin/bash
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源文件
cd /etc/yum.repos.d/CentOS-Base.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
- 修改CentOS-Base.repo文件内容
4.1. 下载后的源文件
[base]
name=CentOS-$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[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,其他的不需要更改
[base]
name=CentOS-7.9.2009 - Base - 163.com
baseurl=http://mirrors.163.com/centos/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-7.9.2009 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-7.9.2009 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
[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
- 更新
yum clean all && yum makecache
- 查看是否更新成功
yum repolist all
- 以上命令可以完全写到一个统一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-*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
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,请根据自己的版本进行更改
|