参考网站 http://mirrors.163.com/.help/...

1.首先备份CentOS-Base.repo,如果以前未添加过163源,此步可以省略

cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.backup

2.下载163源

wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

3.把下载文件改成源文件

mv CentOS6-Base-163.repo CentOS-Base.repo

4.运行以下命令生成缓存

yum clean all
yum makecache

yum makecache可能出现以下错误:

Loaded plugins: refresh-packagekit, security
http://mirrors.163.com/centos/6Server/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL
ERROR 22 -"The requested URL returned error: 404 Not Found"
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please
verify its path and try again

我们尝试进入http://mirrors.163.com/centos...
发现仍然是:404 Not Found

这时我们进入http://mirrors.163.com/centos/发现:目录下有6 6.0-6.8目录,并没有6Server目录。猜测$releasever被错误地编译为:6Server;正确情况下应为6.4。(我的为CentOs6.4)

我们需要把CentOS-Base.repo中的$releasever全部修改为6.4:

vi CentOS-Base.repo
# 在末行模式下执行以下:
:%s/$releasever/6.4        # Esc -> Shift+: 进入末行模式
# 修改完保存退出:Esc -> Shift+: -> wq

重新运行

yum makecache

哈哈,可能仍然出现与之前相似的错误,如下:

Loaded plugins: refresh-packagekit, security
http://mirrors.163.com/centos/6.4/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL
ERROR 22 -"The requested URL returned error: 404 Not Found"
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please
verify its path and try again

再次进入 http://mirrors.163.com/centos/发现:目录下有6.4下只有readme文件,而6目录下具有完整的文件。所以我们需要再次修改一下:把6.4全部修改为6(如果怕一个个修改麻烦,可以重新下载源文件)如下:

rm -rf CentOS-Base.repo         # 先删除6.4的源文件
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo    # 把下载文件改成源文件
mv CentOS6-Base-163.repo CentOS-Base.repo
yum clean all
yum makecache

Done!!!!!


xiao蜗牛
85 声望20 粉丝

{name: 'Xiao蜗牛',