红帽官方手册RHEL7提到添加yum源的两种方式,一种是修改配置文件yum.conf,另一种是新增repo.d文件,并推荐读者使用第二种方式。
To define a new repository, you can either add a [repository]
section to the /etc/yum.conf file, or to a .repo file in the
/etc/yum.repos.d/ directory. All files with the .repo file extension
in this directory are read by yum, and it is recommended to define
your repositories here instead of in /etc/yum.conf.
两行代码添加新的yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all & yum makecache
多个镜像yum如何选择?
系统默认配置了fastestmirror插件,该插件能够告诉yum那个mirror速度最快。
cat /etc/yum/pluginconf.d/fastestmirror.conf
#开启fastestmirror插件
enabled=1
例如,我安装了阿里、网易、腾讯的yum源,系统会选择最快的网易源,帮我安装软件。
[root@VM-0-5-centos yum]# ls -ltr /etc/yum.repos.d/
total 56
-rw-r--r-- 1 root root 1572 Dec 1 2016 CentOS7-Base-163.repo
-rw-r--r-- 1 root root 2523 Jun 16 2018 Centos-7.repo
-rw-r--r-- 1 root root 474 Apr 24 2019 nodesource-el7.repo
-rw-r--r-- 1 root root 616 Nov 23 23:08 CentOS-x86_64-kernel.repo
-rw-r--r-- 1 root root 8515 Nov 23 23:08 CentOS-Vault.repo
-rw-r--r-- 1 root root 1331 Nov 23 23:08 CentOS-Sources.repo
-rw-r--r-- 1 root root 630 Nov 23 23:08 CentOS-Media.repo
-rw-r--r-- 1 root root 314 Nov 23 23:08 CentOS-fasttrack.repo
-rw-r--r-- 1 root root 649 Nov 23 23:08 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root 1309 Nov 23 23:08 CentOS-CR.repo
-rw-r--r-- 1 root root 230 Dec 22 19:06 CentOS-Epel.repo
-rw-r--r-- 1 root root 614 Dec 22 19:06 CentOS-Base.repo