方法一:更改相关文件
(1)先将yum源文件备份
cp CentOS-Base.repo CentOs-Base.repo.backup
(2)转到yum源目录,便于下一步操作
cd /etc/yum.repos.d
(3)更改配置文件
vi CentOS-Base.repo
将文件中的内容改为下面的代码
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
方法二:将国外镜像源改为国内的
(1)首先还是将文件备份
cp CentOS-Base.repo CentOs-Base.repo.backup
(2)转到相关目录
cd /etc/yum.repos.d
(3) 更换yum源 //我这里是将镜像源切换成了阿里云镜像源
sudo curl-o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/CentOS-7.repo
相关镜像源还有
网易开源镜像站:欢迎访问网易开源镜像站https://mirrors.163.com/
中科大开源镜像站:USTC Open Source Software Mirrorhttps://mirrors.ustc.edu.cn/
(4)清除旧的yum缓存
yum clean all
(5)生成新的yum缓存
yum makecache
(6)更新软件包
yum update -y
关于yum的一些指令(以下载nginx为例)
yum install epel-release -y #yum安装拓展yum仓库
yum install nginx -y #下载
yum remove ngnix -y #卸载
yum repolist #查看rpm的数量