溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎樣使用yum-cron自動更新RHEL/CentOS Linux

發(fā)布時間:2021-09-28 15:14:47 來源:億速云 閱讀:91 作者:柒染 欄目:系統(tǒng)運維

怎樣使用yum-cron自動更新RHEL/CentOS Linux,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

yum 命令是 RHEL / CentOS Linux 系統(tǒng)中用來安裝和更新軟件包的一個工具。我知道如何使用 yum 命令行 更新系統(tǒng),但是我想用 cron 任務(wù)自動更新軟件包。該如何配置才能使得 yum 使用 cron 自動更新系統(tǒng)補丁或更新呢?

首先需要安裝 yum-cron 軟件包。該軟件包提供以 cron 命令運行 yum 更新所需的文件。如果你想要每晚通過 cron 自動更新可以安裝這個軟件包。

CentOS/RHEL 6.x/7.x 上安裝 yum cron

輸入以下 [yum 命令][3]:

$ sudo yum install yum-cron

怎樣使用yum-cron自動更新RHEL/CentOS Linux

使用 CentOS/RHEL 7.x 上的 systemctl 啟動服務(wù):

$ sudo systemctl enable yum-cron.service $ sudo systemctl start yum-cron.service $ sudo systemctl status yum-cron.service

在 CentOS/RHEL 6.x 系統(tǒng)中,運行:

$ sudo chkconfig yum-cron on $ sudo service yum-cron start

怎樣使用yum-cron自動更新RHEL/CentOS Linux

yum-cronyum 的一個替代方式。使得 cron 調(diào)用 yum 變得非常方便。該軟件提供了元數(shù)據(jù)更新、更新檢查、下載和安裝等功能。yum-cron 的各種功能可以使用配置文件配置,而不是輸入一堆復(fù)雜的命令行參數(shù)。

配置 yum-cron 自動更新 RHEL/CentOS Linux

使用 vi 等編輯器編輯文件 /etc/yum/yum-cron.conf/etc/yum/yum-cron-hourly.conf

$ sudo vi /etc/yum/yum-cron.conf

確保更新可用時自動更新:

apply_updates = yes

可以設(shè)置通知 email 的發(fā)件地址。注意: localhost將會被system_name` 的值代替。

email_from = root@localhost

列出發(fā)送到的 email 地址。

email_to = your-it-support@some-domain-name

發(fā)送 email 信息的主機名。

email_host = localhost

[CentOS/RHEL 7.x][4] 上不想更新內(nèi)核的話,添加以下內(nèi)容:

exclude=kernel*

RHEL/CentOS 6.x 下添加以下內(nèi)容來禁用內(nèi)核更新:

YUM_PARAMETER=kernel*

保存并關(guān)閉文件。如果想每小時更新系統(tǒng)的話修改文件 /etc/yum/yum-cron-hourly.conf,否則文件 /etc/yum/yum-cron.conf 將使用以下命令每天運行一次(使用 cat 命令 查看):

$ cat /etc/cron.daily/0yum-daily.cron

示例輸出:

#!/bin/bash # Only run if this flag is set. The flag is created by the yum-cron init# script when the service is started -- this allows one to use chkconfig and# the standard "service stop|start" commands to enable or disable yum-cron.if [[ ! -f /var/lock/subsys/yum-cron ]]; then exit 0fi # Action!exec /usr/sbin/yum-cron /etc/yum/yum-cron-hourly.conf[root@centos7-box yum]# cat /etc/cron.daily/0yum-daily.cron#!/bin/bash # Only run if this flag is set. The flag is created by the yum-cron init# script when the service is started -- this allows one to use chkconfig and# the standard "service stop|start" commands to enable or disable yum-cron.if [[ ! -f /var/lock/subsys/yum-cron ]]; then exit 0fi # Action!exec /usr/sbin/yum-cron

完成配置?,F(xiàn)在你的系統(tǒng)將每天自動更新一次。更多細節(jié)請參照 yum-cron 的說明手冊。

$ man yum-cron

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI