YouTube Icon

Code Playground.

Configure Automatic Updates with yum-cron on CentOS 7

CFG

Configure Automatic Updates with yum-cron on CentOS 7

Consistently refreshing your CentOS framework is one of the main parts of in general framework security. On the off chance that you don't refresh your working framework's bundles with the most recent security patches, you are leaving your machine helpless against assaults. 

On the off chance that you deal with different CentOS machines, physically refreshing the framework bundles might be tedious. Regardless of whether you deal with a solitary CentOS establishment some of the time you may ignore a significant update. This is the place where programmed refreshes come convenient. 

In this instructional exercise, we will experience the way toward designing programmed reports on CentOS 7. Similar guidelines apply for CentOS 6. 

Prerequisites

Prior to proceeding with this instructional exercise, ensure you are signed in as a client with sudo advantages . 

Installing yum-cron Package

The yum-cron bundle permits you to naturally run the yum order as a cron task to check for, download, and apply refreshes. Odds are that this bundle is now introduced on your CentOS framework. If not introduced you can introduce the bundle by running the accompanying order: 

sudo yum install yum-cron

When the establishment is finished, empower and start the administration: 

sudo systemctl enable yum-cron
sudo systemctl start yum-cron

To check that the administration is running, type the accompanying order: 

systemctl status yum-cron

Data about the yum-cron administration status will be shown on the screen: 

? yum-cron.service - Run automatic yum updates as a cron job
   Loaded: loaded (/usr/lib/systemd/system/yum-cron.service; enabled; vendor preset: disabled)
   Active: active (exited) since Sat 2019-05-04 21:49:45 UTC; 8min ago
  Process: 2713 ExecStart=/bin/touch /var/lock/subsys/yum-cron (code=exited, status=0/SUCCESS)
 Main PID: 2713 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/yum-cron.service

Configuring yum-cron

yum-cron accompanies two arrangement documents that are put away in the/and so on/yum index, the hourly setup record yum-cron-hourly.conf and the every day design document yum-cron.conf. 

The yum-cron administration just controls whether the cron occupations will run. The yum-cron utility is called by the/and so on/cron.hourly/0yum-hourly.cron and/and so on/cron.daily/0yum-daily.cron cron documents. 

As a matter of course, the hourly cron is arranged to sit idle. On the off chance that there are refreshes accessible the day by day cron is set to download yet not introduce the accessible updates and send messages to stdout. The default arrangement is adequate for basic creation frameworks where you need to get notices and do the update physically in the wake of testing the reports on test workers. 

The arrangement record is organized in areas and each segment contains remarks that depict what every setup line does. 

To alter the yum-cron design document, open the record in your content tool: 

sudo nano /etc/yum/yum-cron-hourly.conf

In the main segment, [commands] you can characterize the kinds of bundles that you need to be refreshed, empower messages and downloads and set to consequently apply refreshes when they are accessible. Of course, the update_cmd is set to default which will refresh all bundles. In the event that you need to set programmed unattended updates it is prescribed to change the incentive to security which will advise yum to refresh bundles that lone fix a security issue. 

In the accompanying model we changed the update_cmd to security and empowered unattended updates by setting apply_updates to yes: 

/etc/yum/yum-cron-hourly.conf

[commands]
update_cmd = security
update_messages = yes
download_updates = yes
apply_updates = no
random_sleep = 360

The subsequent areas characterizes how to send messages. To send messages to both stdout and email change the estimation of emit_via to stdio,email. 

/etc/yum/yum-cron-hourly.conf

[emitters]
system_name = None
emit_via = stdio,email
output_width = 80

In the [email] area you can set the sender and collector email address. Ensure that you have an instrument that can send messages introduced on your framework, for example, mailx or postfix. 

/etc/yum/yum-cron-hourly.conf

[email]
email_from = root@centos.host
email_to = me@example.com
email_host = localhost

The [base] segment permits you to supersede the settings characterized in the yum.conf record. On the off chance that you need to bar explicit bundles from being refreshed you can utilize the bar boundary. In the accompanying model, we are barring the [mongodb] bundle. 

/etc/yum/yum-cron-hourly.conf

[base]
debuglevel = -2
mdpolicy = group:main
exclude = mongodb*

You don't have to restart the yum-cron administration for changes to produce results. 

Viewing logs

Use grep to check whether the cron occupations related with yum are executed: 

sudo grep yum /var/log/cron
May  4 22:01:01 localhost run-parts(/etc/cron.hourly)[5588]: starting 0yum-hourly.cron
May  4 22:32:01 localhost run-parts(/etc/cron.daily)[5960]: starting 0yum-daily.cron
May  4 23:01:01 localhost run-parts(/etc/cron.hourly)[2121]: starting 0yum-hourly.cron
May  4 23:01:01 localhost run-parts(/etc/cron.hourly)[2139]: finished 0yum-hourly.c

The historical backdrop of the yum refreshes is signed in the/var/log/yum record. You can see the most recent updates utilizing the tail order : 

sudo tail -f  /var/log/yum.log
May 04 23:47:28 Updated: libgomp-4.8.5-36.el7_6.2.x86_64
May 04 23:47:31 Updated: bpftool-3.10.0-957.12.1.el7.x86_64
May 04 23:47:31 Updated: htop-2.2.0-3.el7.x86_64

Conclusion

In this instructional exercise, you have figured out how to design programmed updates and stay up with the latest. 

On the off chance that you have any inquiries or criticism, don't hesitate to leave a remark.




CFG