Linux从入门到精通——Centos 配置国内yum源及epel源

Centos 配置国内yum源及epel源

一、备份原有的yum源配置文件

在进行任何更改之前,建议先备份原有的yum源配置文件,以防止配置过程中出现问题。可以使用以下命令备份CentOS-Base.repo文件:

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# ls -l /etc/yum.repos.d/ && mkdir -pv /etc/yum.repos.d/backup-$(date "+%Y.%m.%d-%H.%M.%S") && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup*
total 40
-rw-r--r--. 1 root root 1664 Oct 23  2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 23  2020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Oct 23  2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Oct 23  2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Oct 23  2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 23  2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 23  2020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 Oct 23  2020 CentOS-x86_64-kernel.repo
mkdir: created directory ‘/etc/yum.repos.d/backup-2024.05.09-16.18.01’
[root@localhost ~]# ls -l /etc/yum.repos.d/
total 0
drwxr-xr-x. 2 root root 220 May  9 16:18 backup-2024.05.09-16.18.01
[root@localhost ~]#

二、常用命令

查看系统发行版本:rpm -qi centos-release(查看Version字段)
进入yum配置目录:cd /etc/yum.repos.d
查看yum配置目录:ll /etc/yum.repos.d
备份yum配置目录:cp -r /etc/yum.repos.d /data/
显示使用中的yum源:yum repolist
清除yum的缓存:yum clean all
生成yum的缓存:yum makecache  

三、阿里云源

下载地址: https://mirrors.aliyun.com/centos/

CentOS过期源(centos-vault):https://developer.aliyun.com/mirror/centos-vault
CentOS arm源(centos-altarch):https://developer.aliyun.com/mirror/centos-altarch/
CentOS Stream源(centos-stream):https://developer.aliyun.com/mirror/centos-stream
CentOS debuginfo源(centos-debuginfo):https://developer.aliyun.com/mirror/centos-debuginfo/

3.1、Centos8(centos8官方源已下线,建议切换centos-vault源)

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

3.2、Centos7

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

3.3、Centos6(centos6官方源已下线,建议切换centos-vault源)

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo

3.4、非阿里云ECS用户需要修改相关配置

[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                  | 3.6 kB  00:00:00
extras                                                                                                | 2.9 kB  00:00:00
updates                                                                                               | 2.9 kB  00:00:00
Metadata Cache Created
[root@localhost ~]#

3.5、运行 yun makecache 生成缓存

如果非阿里云ECS用户不运行2.4部分的命令,直接运行 yum makecache 生成缓存,会报如下错误:

[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                                        | 3.6 kB  00:00:00
extras                                                                                                                                                                                      | 2.9 kB  00:00:00
updates                                                                                                                                                                                     | 2.9 kB  00:00:00
(1/6): extras/7/x86_64/filelists_db                                                                                                                                                         | 305 kB  00:00:00
(2/6): base/7/x86_64/filelists_db                                                                                                                                                           | 7.2 MB  00:00:09
(3/6): updates/7/x86_64/filelists_db                                                                                                                                                        |  14 MB  00:00:18
base/7/x86_64/other_db         FAILED
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/ecaab5cc3b9c10fefe6be2ecbf6f9fcb437231dac3e82cab8d9d2cf70e99644d-other.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/ecaab5cc3b9c10fefe6be2ecbf6f9fcb437231dac3e82cab8d9d2cf70e99644d-other.sqlite.bz2: (28, 'Connection timed out after 30001 milliseconds')
Trying other mirror.
extras/7/x86_64/other_db       FAILED
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/ae8d9246e7015e7ecb91d202d4d042a7247813edf3da40f32d278a9c6ba754d2-other.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/ae8d9246e7015e7ecb91d202d4d042a7247813edf3da40f32d278a9c6ba754d2-other.sqlite.bz2: (28, 'Connection timed out after 30000 milliseconds')
Trying other mirror.
base/7/x86_64/other_db         FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/ecaab5cc3b9c10fefe6be2ecbf6f9fcb437231dac3e82cab8d9d2cf70e99644d-other.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
updates/7/x86_64/other_db      FAILED                                                      84% [====================================================================             ]  38 kB/s |  22 MB  00:01:50 ETA
http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/86dde93e0f467fb45a3140712d908f154a611a3377a2de5b5f4c750881e48f6c-other.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/86dde93e0f467fb45a3140712d908f154a611a3377a2de5b5f4c750881e48f6c-other.sqlite.bz2: (28, 'Connection timed out after 30002 milliseconds')
Trying other mirror.
(4/6): updates/7/x86_64/other_db                                                                                                                                                            | 1.6 MB  00:00:02
(5/6): base/7/x86_64/other_db                                                                                                                                                               | 2.6 MB  00:00:03
extras/7/x86_64/other_db       FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/ae8d9246e7015e7ecb91d202d4d042a7247813edf3da40f32d278a9c6ba754d2-other.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
(6/6): extras/7/x86_64/other_db                                                                                                                                                             | 154 kB  00:00:00
Metadata Cache Created
[root@localhost ~]#

四、腾讯云源

4.1、Centos8 及以上版本

4.2、Centos7

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tencent.com/repo/centos7_base.repo

4.3、Centos6

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.cloud.tencent.com/repo/centos6_base.repo

五、华为云源

六、中科大源

七、epel-release源

[root@localhost ~]# yum install epel-release -y
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                  | 3.6 kB  00:00:00
extras                                                                                                | 2.9 kB  00:00:00
updates                                                                                               | 2.9 kB  00:00:00
(1/4): base/7/x86_64/group_gz                                                                         | 153 kB  00:00:00
(2/4): extras/7/x86_64/primary_db                                                                     | 253 kB  00:00:00
(3/4): base/7/x86_64/primary_db                                                                       | 6.1 MB  00:00:08
(4/4): updates/7/x86_64/primary_db                                                                    |  27 MB  00:00:34
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
 Package                           Arch                        Version                     Repository                   Size
=============================================================================================================================
Installing:
 epel-release                      noarch                      7-11                        extras                       15 k

Transaction Summary
=============================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
epel-release-7-11.noarch.rpm                                                                          |  15 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                                  1/1
  Verifying  : epel-release-7-11.noarch                                                                                  1/1

Installed:
  epel-release.noarch 0:7-11

Complete!
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
Cleaning up list of fastest mirrors
[root@localhost ~]#
posted @ 2024-05-09 16:15  左扬  阅读(1549)  评论(0编辑  收藏  举报
levels of contents