CentOS7修改換yum源(最簡安裝)解決默認yum源無法使用

問題:
1.CentOS解決yum命令出現doesn’t have enough cached的問題
One of the configured repositories failed (未知),
and yum doesn’t have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work “fix” this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
2.單純修改源,使得國內更新為國內源,下載軟件更快。
3.報錯:yum 命令報錯 “ There are no enabled repos ” —— yum repolist 為 0
首先修改DNS:
vi /etc/resolv.conf
nameserver: 8.8.8.8(或者國內機器可修改為114.114.114.114)
進入yum源配置目錄: cd /etc/yum.repos.d(yum repolist命令查看可用源數量)
備份原有源:mv /etc/yum.repos.d /etc/yum.repos.d.bak
如果沒有先安裝wget就: yum install wget -y
修改yum源,就是修改CentOS-Base.repo的內容,所以我們要先備份一下原來的: mv CentOS-Base.repo CentOS-Base.repo.backup
下載新的配置文件:
wget下載國內的yum源(即CentOS-Base.repo文件),目前國內主要有三個yum源:(三選一即可)
阿裡雲: wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
網易163: wget -O CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
中科大(推薦):
wget -O CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=3
CentOS 8:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
更新數據:
清除緩存: yum clean all
更新緩存:yum makecache
PS:沒有源安裝wget 顯示倉庫數量為0,.repo文件出現問題,更換默認yum源即可,由於此時,無法通過yum源安裝包括wget在內的任何工具(包括lrzsz等無法安裝),新的.repo文件無法下載。可以使用xshell的sftp上傳下載好的源到vps中。


本文出自快速备案,转载时请注明出处及相应链接。

本文永久链接: https://www.xiaosb.com/beian/50745/