1、更换 yum 源的原因
国外网站连接响应太慢
国内 yum 源响应速度快
2、国内 yum 源
阿里云 yum 源
清华大学 yum 源
中科大 yum 源
网易 yum 源
3、更换清华大学 yum 源
1)建议先备份 CentOS-Base.repo
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
然后编辑 /etc/yum.repos.d/CentOS-Base.repo 文件,在以 mirrorlist= 开头的行前面加 # 注释掉;
并将以 baseurl= 开头的行取消注释(如果被注释的话),把该行内的域名(例如mirror.centos.org)替换为 mirrors.tuna.tsinghua.edu.cn。
2)实际操作
[root@shell ~]#
[root@shell ~]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
[root@shell ~]#
[root@shell ~]# vi /etc/yum.repos.d/CentOS-Base.repo
修改说明:
yum源配置总共有4项,但是更改方式都一样。都是将每一小块以“mirrorlist=”开头的那一行注释掉,然后将每一小块以“baseurl= ”开头的那一行前面的注释取消,最后将每一小块以“baseurl= ”开头的那一行内的centos官方域名(mirror.centos.org)更换为清华大学的域名(mirrors.tuna.tsinghua.edu.cn)即可
清华大学 yum 源配置实例:
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@shell ~]#
[root@shell ~]# yum clean all #清空yum缓存
[root@shell ~]# yum makecache #更新yum源缓存
[root@shell ~]# yum repolist
[root@shell ~]#
[root@shell ~]# yum list httpd mariadb php