1、备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
或者`
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3、生成缓存
yum makecache #生成缓存 立即生效
1)先安装wget
yum install -y wget
- 查询国内镜像源
打开阿里镜像http://mirrors.aliyun.com/
点击帮助:
3)下载CentOS 7的repo文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
如果提示报错wget: unable to resolve host address ‘mirrors.aliyun.com’
意思是无法解析主机地址。应该是与DNS解析有关。
DNS的解析配置文件是/etc/resolv.conf
编辑命令:vi /etc/resolv.conf
添加下面的地址(注意:我这里是私有云)
nameserver 183.221.253.100
nameserver 10.101.10.48
nameserver 10.101.51.169
nameserver 211.137.96.205
公有云一般添加google的DNS服务器和移动,电信或联通的DNS服务器,根据自己需要添加。
4)更新镜像源
清除缓存
yum clean all
生成缓存
yum makecache
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror
.......省略