更换官方yum源为国内镜像yum源

安装依赖项

sudo yum -y install wget
sudo yum -y install curl 
sudo yum -y install git

备份默认的yum源

sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak  

使用阿里yum源

cd /etc/yum.repos.d

# 使用wget下载阿里源
sudo wget -nc http://mirrors.aliyun.com/repo/Centos-7.repo
# 使用阿里yum源  
sudo mv Centos-7.repo CentOS-Base.repo

# 使用curl下载阿里源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

使用清华yum源

# 因为网上没找到清华的源文件,所以自己手动输入吧
vi /etc/yum.repos.d/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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

使用网易yum源

# 使用wget下载网易yum源
sudo wget -nc http://mirrors.163.com/.help/CentOS7-Base-163.repo
# 使用网易yum源  
sudo mv CentOS7-Base-163.repo CentOS-Base.repo

# 使用curl下载网易yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

更新本地yum缓存

# 清除yum缓存
sudo yum clean all  

# 更新列表  
sudo yum list  

# 缓存yum包信息到本机,提高搜索速度  
sudo yum makecache

升级系统或者升级包

# 升级所有包同时也升级软件和系统内核
yum -y update
# 只升级所有包,不升级软件和系统内核
yum -y upgrade

删除更新内核后的旧的内核

# 重启
init 6
# 查询当前使用的系统
uname -a
# 查看当前系统所有的内核
rpm -qa | grep kernel
# 移除老版本的内核,不要删除当前正在使用的内核
yum -y remove 要删除的内核
# 重新编译引导
grub2-mkconfig -o /boot/grub2/grub.cfg
# 重启
init 6