CentOS 7 で、システムアップデートをメール通知や、自動ダウンロード、自動適用したいとき、yum-cron
を使って実現する方法を説明します。
この方法では、1日1回夜間にそれらの機能が実行されます。
ステップ ガイド
- VPSに SSH でログインします。
yum-cron
パッケージをインストールします。sudo yum install yum-cron
/etc/yum/yum-cron.conf
を root 権限で開きます。sudoedit /etc/yum/yum-cron.conf
システムアップデートが利用可能になったときや、自動ダウンロードしたとき、自動アップデートしたときにメール通知するには、update_messages から始まる行を次のように変更します。
# Whether a message should be emitted when updates are available, # were downloaded, or applied. update_messages = yes
メール通知したくない場合は、yes の部分を no にします。
システムアップデートを自動ダウンロードするには、download_updates から始まる行を次のように変更します。
# Whether updates should be downloaded when they are available. download_updates = yes
自動ダウンロードしたくない場合は、yes の部分を no にします。
自動ダウンロードしたシステムアップデートを自動適用したいときは、apply_update から始まる行を次のように変更します。
# Whether updates should be applied when they are available. Note # that download_updates must also be yes for the update to be applied. apply_updates = yes
システムアップデートを自動適用したくない場合は、yes の部分を no にします。
4. でメール通知を有効にしたとき、
emit_via, email_from, email_to, email_host
から始まる行を次のように変更します。【~】の部分は、ご自身の環境に合わせて置き換えてください。[emitters] # Name to use for this system in messages that are emitted. If # system_name is None, the hostname will be used. system_name = None # How to send messages. Valid options are stdio and email. If # emit_via includes stdio, messages will be sent to stdout; this is useful # to have cron send the messages. If emit_via includes email, this # program will send email itself according to the configured options. # If emit_via is None or left blank, no messages will be sent. emit_via = email # The width, in characters, that messages that are emitted should be # formatted to. output_width = 80 [email] # The address to send email messages from. # NOTE: 'localhost' will be replaced with the value of system_name. email_from = root@【VPS の管理 FQDN、もしくは登録済のドメイン名】 # List of addresses to send messages to. email_to = 【メール通知を受け取りたいメールアドレス】 # Name of the host to connect to to send email messages. email_host = smtpmail.cis.kit.ac.jp
/etc/yum/yum-cron.conf
を保存して閉じます。自動アップデート機能を有効にします。
sudo systemctl enable yum-cron.service
自動アップデート機能を起動するためのタイマーを有効にして起動します。
sudo systemctl enable yum-cron.timer sudo systemctl start yum-cron.timer
システムアップデートが適用された後も、プログラムによっては適用される前の内容で動作し続ける場合があります。システムアップデートが適用された後の内容で動作させるためには、VPS の再起動が必要です。
yum-utils
パッケージに含まれている needs-restarting
コマンドで、VPS の再起動が必要かどうかを知ることができます。