修改YUM源为国内源
一、备份原有的源
在做任何对更改系统变量或者设置的时候都应该进行备份,对于Linux系统中的yum源我们换掉的是这个:/etc/yum.repos.d/CentOS-Base.repo,所以我们应该先把源文件给做个备份。使用mv命令即可。
二、找到你要换的源
华为、阿里、清华、南大这些源都是可以的(他们具体有啥区别,还没有深入去了解,这里做一个`todo`)。
这些源可以直接去他们官方的镜像源仓库中去寻找(这里给出他们的官方镜像源地址):
三、下载文件、重建缓存
华为和阿里源:
找到源之后,就是下载下来,然后放到系统的/etc/yum.repos.d/文件夹下。如果你是用win下载的,可以借助传输软件WinSCP上传到Linux中。
各大高校源:
找到高校源(高校源我们找的是RPM-GPG-KEY-CentOS-7这种格式的),这里我们可以选择不下载。高校源一般都是在文件中的地址路径配置gpgkey,下边是南大的centos7,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
baseurl=https://mirrors.nju.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
baseurl=https://mirrors.nju.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
baseurl=https://mirrors.nju.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=https://mirrors.nju.edu.cn/centos/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
baseurl=https://mirrors.nju.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.nju.edu.cn/centos/RPM-GPG-KEY-CentOS-7
重建缓存
yum makecache
这样就大功告成了
注意事项:
yum修改阿里源重启之后本地挂载点可能会消失,然后报错[Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml",这时需要我们重启挂载点,具体启动方法详见下方的参考资料。
参考资料: