RHEL8系Linux (CentOS 8, Rocky Linux 8 etc.) で、システムアップデートをメール通知や、自動ダウンロード、自動適用したいとき、dnf-automatic
を使って実現する方法を説明します。
この方法では、1日1回夜間にそれらの機能が実行されます。
ステップ ガイド
- VPSに SSH でログインします。
dnf-automatic
パッケージをインストールします。sudo yum install dnf-automatic
/etc/dnf/automatic.conf
を root 権限で開きます。sudoedit /etc/dnf/automatic.conf
システムアップデートを自動ダウンロードするには、download_updates から始まる行を次のように変更します。
# Whether updates should be downloaded when they are available, by # dnf-automatic.timer. notifyonly.timer, download.timer and # install.timer override this setting. download_updates = yes
自動ダウンロードしたくない場合は、yes の部分を no にします。
自動ダウンロードしたシステムアップデートを自動適用したいときは、apply_update から始まる行を次のように変更します。
# Whether updates should be applied when they are available, by # dnf-automatic.timer. notifyonly.timer, download.timer and # install.timer override this setting. apply_updates = yes
システムアップデートを自動適用したくない場合は、yes の部分を no にします。
メール通知を受け取りたいとき、
emit_via, email_from, email_to, email_host
から始まる行を次のように変更します。【~】の部分は、ご自身の環境に合わせて置き換えてください。[emitters] # Name to use for this system in messages that are emitted. Default is the # hostname. # system_name = my-host # How to send messages. Valid options are stdio, email and motd. 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 includes motd, /etc/motd file will have the messages. if # emit_via includes command_email, then messages will be send via a shell # command compatible with sendmail. # Default is email,stdio. # If emit_via is None or left blank, no messages will be sent. emit_via = email [email] # The address to send email messages from. 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/dnf/automatic.conf
を保存して閉じます。自動アップデート機能を有効にします。システムアップデートが利用可能になったことをメール通知で受け取りたいだけの場合は、
dnf-automatic.service
ではなく、dnf-automatic-notifyonly.service
を有効にします。sudo systemctl enable dnf-automatic.service
システムアップデートが利用可能になったメール通知のみsudo systemctl enable dnf-automatic-notifyonly.service
自動アップデート機能を起動するためのタイマーを起動します。システムアップデートが利用可能になったことをメール通知で受け取りたいだけの場合は、
dnf-automatic.timer
ではなく、dnf-automatic-notifyonly.timer
を有効にします。sudo systemctl enable dnf-automatic.timer sudo systemctl start dnf-automatic.timer
システムアップデートが利用可能になったメール通知のみsudo systemctl enable dnf-automatic-notifyonly.timer sudo systemctl start dnf-automatic-notifyonly.timer
システムアップデートが適用された後も、プログラムによっては適用される前の内容で動作し続ける場合があります。システムアップデートが適用された後の内容で動作させるためには、VPS の再起動が必要です。
dnf needs-restarting
コマンドで、VPS の再起動が必要かどうかを知ることができます。