升级步骤


Centos 7 内核升级需要用到红帽Linux仓库 http://elrepo.org/ ,按照网站提示导入 elrepo 公钥和安装 elrepo。

# 导入 elrepo 公钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# 安装 elrepo 
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
# 加载 elrepo 元数据
yum --disablerepo="*" --enablerepo="elrepo-kernel" repolist
# 查看可用相关内核包
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
# 安装长期支持版内核
yum --enablerepo=elrepo-kernel install kernel-lt
# 或者安装最新稳定主线内核
yum --enablerepo=elrepo-kernel install kernel-ml
# 删除旧版本工具包
yum remove kernel-tools-libs.x86_64 kernel-tools.x86_64 -y
# 安装新版本工具包,长期支持版内核
yum --disablerepo=\* --enablerepo=elrepo-kernel install kernel-lt-tools.x86_64 -y
# 安装新版本工具包,最新稳定主线内核
yum --disablerepo=\* --enablerepo=elrepo-kernel install kernel-ml-tools.x86_64 -y

# 查看内核情况及启动顺序
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
# 内核启动顺序从上至下为从0开始,最新内核在最上面,需要设置默认启动为0
sed -i 's/GRUB_DEFAULT=saved/GRUB_DEFAULT=0/g' /etc/default/grub
#创建内核配置
grub2-mkconfig -o /boot/grub2/grub.cfg

# 重启并检查内核版本
reboot -h now
uname -r

根据上面的步骤提供一个简单的 ansible-playbook

- name: Import ELRepo
  shell: rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org;rpm -Uvh --replacepkgs http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

- name: Install the latest version of  kernel
  shell: yum --enablerepo=elrepo-kernel install kernel-ml -y

- name: Set the default kernel version
  shell: sed -i 's/GRUB_DEFAULT=saved/GRUB_DEFAULT=0/g' /etc/default/grub

- name: Generate the kernel config
  shell: grub2-mkconfig -o /boot/grub2/grub.cfg

# - name: start firewall
#   service: name=firewalld state=started
# - name: Set firewalld tcp port for Controller
#   firewalld: port=6443/tcp permanent=yes state=enabled

- name: Stop firewalld
  shell: systemctl stop firewalld;systemctl disable firewalld

- name: Stop selinux
  shell: setenforce 0;sed "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config