第一步:備份原鏡像文件,以免出錯后可以恢復。
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
第二步:下載新的CentOS-Base.repo到/etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
第三步:運行yum makecache生成緩存
yum makecache
建議在第一步之前,先yum -y install wget以免備份文件后,無法wget下載。
在執行yum命令報錯
http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - “The requested URL returned error: 404 Not Found” Trying other mirror. http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - “couldn’t connect to host” Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - “Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’” Trying other mirror. Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
原因是原centos/6/下已經沒有相關的文件,自然找不到報404,而centos/7/下有相關文件。
解決方法
cd /etc/yum.repos.d vi CentOS-Base.repo :%s/$releasever/7/g #將文件中$releasever全部改成7 yum clean all && yum makecache # 清除和緩存
$releasever是獲取centos的版本號,如centos的版本號為6.8,獲取到的為6,但是已經找不到了,所以直接全局改成7即可。