某云服务商的一台CentOS云主机,使用默认源,安装软件非常慢,于是将源改为国内镜像,经过一番折腾,最后成功了。本文记录其过程。
过程
由于有使用阿里云的经历,于是选择阿里云的源,在/etc/yum.repos.d
目录中输入:
1 | wget http://mirrors.aliyun.com/repo/Centos-7.repo |
即可下载。下载的文件名为Centos-7.repo
。
将原来的*.repo
文件拷贝到临时目录备份,或修改后缀名称。
使用yum clean all
清除缓存,再使用yum makecache
生成新的缓存。不过此时提示:
1 | Loaded plugins: ulninfo |
使用浏览器打开出错的URL,的确是404。打开https://mirrors.aliyun.com/centos/
网站,一层一层打开目录,最终找到https://mirrors.aliyun.com/centos/7/os/x86_64/repodata/
。对于出错的URL,发现出错的地址有7Server
,正常打开的地址是7
。根据经验,猜测7Server
、7
是发行版本号,名称不同,导致错误。打开Centos-7.repo
文件,找到相近的URL:baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
,问题出在$releasever
。于是继续搜索,找到redhat官方有关的说明,摘录如下:
$releasever
You can use this variable to reference the release version of Red Hat Enterprise Linux. Yum obtains the value of$releasever
from the distroverpkg=value line in the /etc/yum.conf configuration file. If there is no such line in /etc/yum.conf, then yum infers the correct value by deriving the version number from the redhat-release-server package. The value of $releasever typically consists of the major release number and the variant of Red Hat Enterprise Linux, for example 6Client, or 6Server.
根据提示,在/etc/yum.conf
中添加distroverpkg=7
,失败。
解决
由于不知道如何修改$releasever
的值,只好修改Centos-7.repo
文件,将$releasever
改为7
,这样可正常生成缓存。从而达到目的。
扩展
文中遇到的问题,在网上搜索了一遍,没找到类似的。搜索到的更改源的方法都是十分简单,也带有成功的截图,但这台云主机不行。奇怪的是,在该服务商的另外一台云主机上,同样的方法,却可成功。于是查看这2台主机的差异。可正常更新的主机:
1 | NAME="CentOS Linux" |
不能更新的主机:
1 | NAME="Oracle Linux Server" |
两者的确不同。
参考资料
李迟 2019.5.27 晚