centos7 更换yum源

teninforxs / 2023-05-03 / 原文

1.先备份系统自带的yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.下载国内yum源配置文件到/etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.如遇:
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 失败:未知的名称或服务。
wget: 无法解析主机地址 “mirrors.aliyun.com”

配置DNS地址:
vim /etc/resolv.conf

按键盘insert键输入以下内容:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 223.5.5.5
nameserver 223.6.6.6

4.再执行第二步:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

5.清理yum缓存,并生成新的缓存
yum clean all

6.执行到这步如果再遇到这样的问题,那么你就是大冤种啦:

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
已加载插件:fastestmirror, langpacks
/var/run/yum.pid 已被锁定,PID 为 29631 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit...
另一个应用程序是:yum
内存: 25 M RSS (1.4 GB VSZ)
已启动: Fri Mar 31 21:04:01 2023 - 10:47之前
状态 :跟踪/停止,进程ID:29631
Another app is currently holding the yum lock; waiting for it to exit...
另一个应用程序是:yum
内存: 25 M RSS (1.4 GB VSZ)
已启动: Fri Mar 31 21:04:01 2023 - 10:49之前
状态 :跟踪/停止,进程ID:29631

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

当然如果你不按Ctrl+c的话会一直执行下去。那么大冤种你执行以下命令就好了:

kill -9 进程数 例如:kill -9 29631

7.在执行一下第五步:
yum clean all

8.编译一下需要等一段时间
yum makecache

9.更新yum源检查是否生效
yum update