如何使用 yum-cron 自动更新 RHEL/CentOS Linux | Linux 中国
2018-03-18 00:00
1191 查看
我知道如何使用 yum 命令行 更新系统,但是我想用 cron 任务自动更新软件包。-- Vivek Gite
有用的原文链接请访问文末的“原文链接”获得可点击的文内链接、全尺寸原图和相关文章。
致谢编译自 | https://www.cyberciti.biz/faq/fedora-automatic-update-retrieval-installation-with-cron/
作者 | Vivek Gite
译者 | shipsw ? ? 共计翻译:10 篇 贡献时间:1399 天
yum命令是 RHEL / CentOS Linux 系统中用来安装和更新软件包的一个工具。我知道如何使用 yum 命令行[1] 更新系统,但是我想用 cron 任务自动更新软件包。该如何配置才能使得
yum使用 cron 自动更新[2]系统补丁或更新呢?首先需要安装 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 = root@localhost
列出发送到的 email 地址。
email_to = your-it-support@some-domain-name
发送 email 信息的主机名。
email_host = localhost
[CentOS/RHEL 7.x][4] 上不想更新内核的话,添加以下内容:
exclude=kernel*
RHEL/CentOS 6.x 下添加以下内容来禁用内核更新[3]:
YUM_PARAMETER=kernel*
保存并关闭文件[4]。如果想每小时更新系统的话修改文件
/etc/yum/yum-cron-hourly.conf,否则文件
/etc/yum/yum-cron.conf将使用以下命令每天运行一次(使用 cat 命令[5] 查看):
$ 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
[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 0
fi
# Action!
exec /usr/sbin/yum-cron
完成配置。现在你的系统将每天自动更新一次。更多细节请参照 yum-cron 的说明手册。
$ man yum-cron
关于作者作者是 nixCraft 的创始人,一个经验丰富的系统管理员和 Linux/Unix 脚本培训师。他曾与全球客户合作,领域涉及IT,教育,国防和空间研究以及非营利部门等多个行业。请在 Twitter[6]、Facebook[7]、Google+[8] 上关注他。获取更多有关系统管理、Linux/Unix 和开源话题请关注我的 RSS/XML 地址[9]。via: https://www.cyberciti.biz/faq/fedora-automatic-update-retrieval-installation-with-cron/作者:Vivek Gite[11] 译者:shipsw 校对:wxy本文由 LCTT 原创编译,Linux中国 荣誉推出[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/
相关文章推荐
- 如何使用 yum-cron 自动更新 RHEL/CentOS Linux
- CentOS7安全设置 yum-cron系统自动更新,firewalld防火墙简单使用
- RHEL/CentOS/SL Linux 6.x使用EPEL 6的yum软件源
- 在 RHEL/CentOS 系统上使用 YUM history 命令回滚升级操作 | Linux 中国
- RHEL6.0使用centos的YUM更新源
- RHEL 5.3使用Centos 5.3的 yum 源进行更新和安装软件
- 使用YUM自动更新Linux系统
- Linux上yum安装svn并使用钩子实现自动更新
- RHEL/CentOS/SL Linux 6.x使用EPEL 6的yum软件源 .
- 如何在 CentOS 7 / RHEL 7 终端服务器上安装 KVM | Linux 中国
- Linux使用错误小结(CentOS)- yum更新软件失败
- Linux--yum如何在CentOS操作系统使用
- 在 CentOS/RHEL 上查找 yum 安裝的软件的位置 | Linux 中国
- CentOS 7 更新源 – 使用国内 163 yum 源 [日期:2015-09-22] 来源:imcn.me 作者:Linux [字体:大 中 小] 突然想起试试 Docker,在一台计算机上
- 如何在 CentOS 7 / RHEL 7 的 KVM 上启用嵌套虚拟化 | Linux 中国
- 如何使用RHEL/CentOS 7安装创建和管理LXC (Linux Containers)
- Linux/CentOS配置:使用yum update更新时不升级内核的方法
- redhat enterprise 5.0 linux 使用CentOS的更新源
- 使用yum 代替up2date 自动更新升级RedHat AS3
- [Linux]在Centos中yum安装和卸载软件的使用方法