在 CentOS 和 RHEL 系统上安装或自动更新安全补丁

在 Linux 系统上,其中一个最重要的需求就是保持定期更新最新的安全补丁,或者为相应的 Linux 版本更新可用的安全补丁。和它同一家族的其它 Linux 版本(Fedora 或 Scientific Linux)中可以用类似的方法进行配置

  • 在 CentOS/RHEL 系统上配置自动安全更新

在 CentOS/RHEL 7/6 系统上,你需要安装下面的安装包

# yum update -y && yum install yum-cron -y
  • 1,进入ssh敲yum update -y
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
  • 2,更新完成后允许yum install yum-cron -y
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
  • 3,在 CentOS/RHEL 7 系统上启用自动安全更新

然后我们使用vi打开 /etc/yum/yum-cron.conf。修改以下内容为下面的值

在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
  • 4,安全更新
# yum --security upgrade
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
  • 5,然后我们执行命令“systemctl start yum-cron”,启动yum-cron 即可
[root@VM-4-15-centos ~]# systemctl start yum-cron
  • 6,最后我们将yum-cron 加入开机自动启动。执行命令“systemctl enable yum-cron”
[root@VM-4-15-centos ~]# systemctl enable yum-cron
更新系统中已有的软件包 yum -y update
安装gcc、gcc+、wget等 yum -y install gcc gcc-c++ make wget
安装ssh相关 yum -y install openssh-clients openssh-server
安装vim编辑器 yum -y install vim
安装压缩解压缩工具 yum -y install tar
安装网络工具 yum -y install net-tools
字符终端处理库 yum -y install ncurses
yum源数据缓存 yum makecache fast

最后reboot后,在查看一下 yum-cron状态,下图表示已经自动运行了

在 CentOS 和 RHEL 系统上安装或自动更新安全补丁
在 CentOS 和 RHEL 系统上安装或自动更新安全补丁

RHEL / CentOS 6 安裝 yum-plugin-security# yum install yum-plugin-security

CentOS 6 安裝好 yum-plugin-security 套件後, 操作跟 CentOS 7 一樣, 以下是列出所有可用安全性更新:# yum –security check-update

除了安裝性相關套件外, 也可以列出 bugs fix 的套件:

# yum updateinfo list bugzillas

升級安全性相關套件到最近版本:

# yum –security update

升級安全性相關套件到上次升級版本:

# yum –security update-minimal

后补内容linux(centos)禁止升级内核的办法

linux系统如果升级内核,会造成不可预估的问题,因此有必要禁止自动升级内核,方法如下

yum -y install yum-cron
#关闭自动更新
vi /etc/yum/yum-cron.conf
update_messages = no
download_updates = no
#启动yum-cron
systemctl start yum-cron
systemctl enable yum-cron

#忽略更新内核

cp /etc/yum.conf /etc/yum.conf.bak
vi /etc/yum.conf
exclude=kernel*
exclude=centos-release*
部分内容参考:https://cloud.tencent.com/developer/article/1876139?from=15425
https://blog.csdn.net/chaishen10000/article/details/107007984

3 评论

  1. 对于 RHEL 或 CentOS 6 系统,运行下面的 Yum 命令 来安装 yum 安全插件
    # yum -y install yum-plugin-security
    要统计补丁的大约数量,运行下面的命令
    yum updateinfo list available
    要统计补丁的大约数量,运行下面的命令
    # yum updateinfo list available | wc -l
    11269
    想列出全部可用的安全补丁但不安装
    yum updateinfo list security all

回复 4s取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注