yum
命令是 RHEL / CentOS Linux 系統中用來安裝和更新軟體包的一個工具。我知道如何使用 yum 命令列 更新系統,但是我想用 cron 任務自動更新軟體包。該如何配置才能使得 yum
使用 cron 自動更新系統補丁或更新呢?
首先需要安裝 yum-cron 軟體包。該軟體包提供以 cron 命令執行 yum
更新所需的檔案。如果你想要每晚透過 cron 自動更新可以安裝這個軟體包。
CentOS/RHEL 6.x/7.x 上安裝 yum cron
輸入以下 [yum 命令][3]:
$ sudo yum install yum-cron
使用 CentOS/RHEL 7.x 上的 systemctl
啟動服務:
$ sudo systemctl enable yum-cron.service
$ sudo systemctl start yum-cron.service
$ sudo systemctl status yum-cron.service
在 CentOS/RHEL 6.x 系統中,執行:
$ sudo chkconfig yum-cron on
$ sudo service yum-cron start
yum-cron
是 yum
的一個替代方式。使得 cron 呼叫 yum
變得非常方便。該軟體提供了後設資料更新、更新檢查、下載和安裝等功能。yum-cron
的各種功能可以使用配置檔案配置,而不是輸入一堆複雜的命令列引數。
配置 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
可以設定通知 email 的發件地址。注意: localhost將會被
system_name` 的值代替。
email_from = [email protected]
列出傳送到的 email 地址。
email_to = [email protected]
傳送 email 資訊的主機名。
email_host = localhost
[CentOS/RHEL 7.x][4] 上不想更新核心的話,新增以下內容:
exclude=kernel*
RHEL/CentOS 6.x 下新增以下內容來禁用核心更新:
YUM_PARAMETER=kernel*
儲存並關閉檔案。如果想每小時更新系統的話修改檔案 /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 0
fi
# Action!
exec /usr/sbin/yum-cron /etc/yum/yum-cron-hourly.conf
[[email protected] 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 0
fi
# Action!
exec /usr/sbin/yum-cron
完成配置。現在你的系統將每天自動更新一次。更多細節請參照 yum-cron 的說明手冊。
$ man yum-cron
關於作者
作者是 nixCraft 的創始人,一個經驗豐富的系統管理員和 Linux/Unix 指令碼培訓師。他曾與全球客戶合作,領域涉及IT,教育,國防和空間研究以及非營利部門等多個行業。請在 Twitter、Facebook、Google+ 上關注他。獲取更多有關係統管理、Linux/Unix 和開源話題請關注我的 RSS/XML 地址。
via: https://www.cyberciti.biz/faq/fedora-automatic-update-retrieval-installation-with-cron/
作者:Vivek Gite 譯者:shipsw 校對:wxy
[3]:https://www.cyberciti.biz/faq/rhel-centos-fedora-linux-yum-command-howto/ [4]:https://www.cyberciti.biz/faq/yum-update-except-kernel-package-command/
相關文章
- 雲開發與 WePY,快速實現 Linux 命令查詢小程式
- 如何在 Linux 中不輸入密碼執行 sudo 命令
- Linux作業系統中的7功能詳解
- 全新 Kali Linux 系統安裝指南
- 如何在 Debian Linux 上設定和配置網橋
- Linux Deepin 12.12.1釋出
- 一個月內發現的第六起 Linux DDoS 木馬
- 為你的 Linux 應用建立 .desktop 檔案
- linux server設定開機自動連線WIFI
- 如何在 Ubuntu 15.04 / CentOS 7 上安裝 Android Studio
- 2017 年 Linux 的五大痛點
- Linux 3.11正式命名為Linux For Workgroups
- Linux 基金會網站在離線狀態下仍遭受暴力攻擊
- Linux shell中的那些小把戲
- label studio 結合 MMDetection 實現資料集自動標記、模型迭代訓練的閉環
- 檢查 Linux 檔案系統中的錯誤:透過案例學習 FSCK 命令