解决centos7 yum失效的问题
# 1. 查看当前有哪些是在使用的
# 查看所有仓库配置文件
ls -l /etc/yum.repos.d/
总用量 56
-rw-r--r--. 1 root root 2523 8月 2 2024 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 10月 23 2020 CentOS-CR.repo
-rw-r--r--. 1 root root 649 10月 23 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 10月 23 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 10月 23 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 10月 23 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 10月 23 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 10月 23 2020 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 2081 8月 2 2024 docker-ce.repo
-rw-r--r--. 1 root root 951 10月 3 2017 epel.repo
-rw-r--r--. 1 root root 1050 10月 3 2017 epel-testing.repo
-rw-r--r--. 1 root root 0 7月 23 2024 jenkins.repo
-rw-r--r--. 1 root root 477 4月 27 2014 nux-dextop.repo
# 查看当前启用的仓库
yum repolist all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 2. 备份配置
# 创建备份目录
mkdir -p /root/yum-repos-backup
# 备份所有仓库配置
cp /etc/yum.repos.d/*.repo /root/yum-repos-backup/
1
2
3
4
5
2
3
4
5
# 安装阿里云yum源
# 删除之前的所有配置
rm -rf /etc/yum.repos.d/*
# 配置阿里云
# 检查阿里云网络是否正常
curl -I http://mirrors.aliyun.com/centos-vault/7.9.2009/os/x86_64/
# 创建新的完整仓库配置
cat > /etc/yum.repos.d/CentOS-Base.repo << 'EOF'
[base]
name=CentOS-7 - Base
baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-7 - Updates
baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/updates/x86_64/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-7 - Extras
baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/extras/x86_64/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-7 - Plus
baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/centosplus/x86_64/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
创建EPEL仓库配置
# 创建EPEL仓库配置
cat > /etc/yum.repos.d/epel.repo << 'EOF'
[epel]
name=Extra Packages for Enterprise Linux 7 - x86_64
baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
EOF
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 清理缓存并测试
# 清理所有缓存
yum clean all
# 重新生成缓存
yum makecache
# 测试仓库连接
yum repolist enabled
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
上次更新: 2025/06/28, 10:25:16