0
0

AmazonLinux2023でパッチマネージャーを使用せずにセキュリティアップデートを自動的に適用する方法

Last updated at Posted at 2024-07-16

Amazon Linux2等でyum-cronでやっていた方法のAmazon Linux 2023版。
AWSの Patch Manager 経由でなく、OSのみでパッチ(セキュリティアップデートのみ)を適用する方法。

インストール

$ sudo dnf install dnf-automatic

リポジトリの設定

常に最新のリポジトリからとる設定。

$ sudo vi /etc/dnf/vars/releasever
latest

設定

セキュリティアップデートのみ適用する。

$ sudo vi /etc/dnf/automatic.conf

upgrade_type = default
↓
upgrade_type = security

apply_updates = no
↓
apply_updates = yes

必要であれば通知先メールアドレスの設定(デフォルト:メールは送らずログ出力のみ)や再起動の有無(デフォルト:再起動しない)をします。カーネルや特定パッケージを除外したい場合などは、/etc/dnf/dnf.conf の exclude に記述します(こちらは使用していないので未確認)。

適用時間の変更

OSのtimezoneを変更している場合は、適宜良い感じにしてください。

$ sudo vi /usr/lib/systemd/system/dnf-automatic-install.timer

OnCalendar=*-*-* 6:00
↓
# JST 1:00
OnCalendar=*-*-* 16:00

有効化

$ sudo systemctl enable dnf-automatic-install.timer
$ sudo systemctl start dnf-automatic-install.timer

更新後の自動サービス再起動

これを入れるとシステム更新時(dnf (update|upgrade|downgrade))に systemd サービスを再起動してくれる(らしい)。今までこんなことしなくてもよしなにやってくれていた気がするのでdnf-automaticとの組み合わせで意味があるかどうかは不明。下記の公式マニュアルに書いてあったのでいれてあります。意味はないよと言うことであれば教えて下さい。

$ sudo dnf install smart-restart

ログ

/var/log/messages にこんな感じで出ます。

セキュリティアップデートが適用されたとき

Jul 24 01:09:00 ip-192-168-1-232 systemd[1]: Starting dnf-automatic-install.service - dnf automatic install updates...
Jul 24 01:09:08 ip-192-168-1-232 dnf-automatic[1980762]: Last metadata expiration check: 0:00:07 ago on Wed 24 Jul 2024 01:09:01 AM JST.
Jul 24 01:09:10 ip-192-168-1-232 dnf-automatic[1980762]: Running transaction check
Jul 24 01:09:11 ip-192-168-1-232 dnf-automatic[1980762]: Transaction check succeeded.
Jul 24 01:09:11 ip-192-168-1-232 dnf-automatic[1980762]: Running transaction test
Jul 24 01:09:12 ip-192-168-1-232 dnf-automatic[1980762]: Transaction test succeeded.
Jul 24 01:09:12 ip-192-168-1-232 dnf-automatic[1980762]: Running transaction
Jul 24 01:09:28 ip-192-168-1-232 dnf-automatic[1980762]: Checking Secure Boot revocations...
Jul 24 01:09:28 ip-192-168-1-232 dnf-automatic[1980762]: Secure Boot not enabled
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: The following updates have been applied on 'ip-192-168-1-232.ap-northeast-1.compute.internal':
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: ================================================================================
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: Package            Arch     Version                        Repository     Size
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: ================================================================================
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: Installing:
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: kernel             x86_64   6.1.97-104.177.amzn2023        amazonlinux    31 M
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: Upgrading:
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: cups-libs          x86_64   1:2.3.3op2-18.amzn2023.0.8     amazonlinux   262 k
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: kernel-tools       x86_64   6.1.97-104.177.amzn2023        amazonlinux   157 k
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: libgs              x86_64   9.56.1-7.amzn2023.0.8          amazonlinux   3.6 M
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: nano               x86_64   5.8-3.amzn2023.0.4             amazonlinux   711 k
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: openssh            x86_64   8.7p1-8.amzn2023.0.12          amazonlinux   453 k
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: openssh-clients    x86_64   8.7p1-8.amzn2023.0.12          amazonlinux   708 k
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: openssh-server     x86_64   8.7p1-8.amzn2023.0.12          amazonlinux   455 k
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: wget               x86_64   1.21.3-1.amzn2023.0.4          amazonlinux   779 k
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: Transaction Summary
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: ================================================================================
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: Install   1 Package
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: Upgrade  13 Packages
Jul 24 01:09:32 ip-192-168-1-232 dnf-automatic[1980762]: Updates completed at Wed 24 Jul 2024 01:09:31 AM JST
Jul 24 01:09:32 ip-192-168-1-232 audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=dnf-automatic-install comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Jul 24 01:09:32 ip-192-168-1-232 audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=dnf-automatic-install comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Jul 24 01:09:32 ip-192-168-1-232 systemd[1]: dnf-automatic-install.service: Deactivated successfully.
Jul 24 01:09:32 ip-192-168-1-232 systemd[1]: Finished dnf-automatic-install.service - dnf automatic install updates.
Jul 24 01:09:32 ip-192-168-1-232 systemd[1]: dnf-automatic-install.service: Consumed 26.431s CPU time.

無かったとき

Jul 24 06:47:42 ip-192-168-1-232 systemd[1]: Starting dnf-automatic.service - dnf automatic...
Jul 24 06:47:44 ip-192-168-1-232 dnf-automatic[2029720]: No security updates needed, but 10 updates available
Jul 24 06:47:44 ip-192-168-1-232 audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=dnf-automatic comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Jul 24 06:47:44 ip-192-168-1-232 audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=dnf-automatic comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Jul 24 06:47:44 ip-192-168-1-232 systemd[1]: dnf-automatic.service: Deactivated successfully.
Jul 24 06:47:44 ip-192-168-1-232 systemd[1]: Finished dnf-automatic.service - dnf automatic.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0