为旧版本 CentOS 设置更新源

总有些时候需要操作一些老旧的 CentOS 版本,如果需要更新就比较麻烦了,因为绝大部分更新源都不对老版本提供服务了。

这时我们只好使用 CentOS Vault,从官方接受这最后的支持,慢慢的下载更新。

更新源配置

自己仿照着写了一个更新源配置模板:

[base]
name=CentOS-$releasever - Base
baseurl=http://vault.centos.org/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
[updates]
name=CentOS-$releasever - Updates
baseurl=http://vault.centos.org/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
[extras]
name=CentOS-$releasever - Extras
baseurl=http://vault.centos.org/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://vault.centos.org/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://vault.centos.org/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

具体操作:

cd /etc/yum.repos.d
# 备份原来的 CentOS-Base.repo
mv CentOS-Base.repo CentOS-Base.repo.save

# 自定义一个 CentOS-Base.repo
vi CentOS-Base.repo

# 定义:版本
sed -ie 's/\$releasever/6.5/g' CentOS-Base.repo
# 定义:架构
sed -ie 's/\$basearch/x86_64/g' CentOS-Base.repo

# 更新 yum 缓存
yum clean all
# yum update yum

... do something use yum ...

# 恢复原来的 CentOS-Base.repo
mv CentOS-Base.repo.save CentOS-Base.repo

其他替代更新源

还可以用以下地址替换 http://vault.centos.org/

  • http://ftp.pbone.net/mirror/vault.centos.org/
  • http://mirror.its.sfu.ca/mirror/CentOS-vault/