Oracle Cloud上の古いOracle Linux 7インスタンスのyum設定を更新する

「Notices: General Notices for Oracle Linux Images」というページに「2021.03 – Yum Update for Oracle Linux 7 and Oracle Linux 8 Instances」というのを発見した。

たしかに2021年3月より前に作成したインスタンス Oracle-Linux-7.7-2019.08.28-0, Oracle-Autonomous-Linux-7.8-2020.05-0 には oci-linux-config というパッケージはインストールされていなかった。

$ rpm -qa|grep oci-linux-config
$

とりあえず、ここに書いてある手順通りに進めていく

$ curl -H "Authorization:Bearer Oracle" -sfm 25 http://169.254.169.254/opc/v2/instance/ 2>/dev/null | jq -r '.regionInfo.realmKey'
oc1
$

上記では「oc1」という結果が出力されているが、「oc1」~「oc4」ならOKとのこと。

oci-linux-config パッケージをインストール

$ sudo yum -y install oci-linux-config
読み込んだプラグイン:langpacks, ulninfo
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ oci-linux-config.noarch 0:1.0-3.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

================================================================================
 Package               アーキテクチャー
                                   バージョン      リポジトリー            容量
================================================================================
インストール中:
 oci-linux-config      noarch      1.0-3.el7       ol7_ociyum_config       13 k

トランザクションの要約
================================================================================
インストール  1 パッケージ

総ダウンロード容量: 13 k
インストール容量: 29 k
Downloading packages:
oci-linux-config-1.0-3.el7.noarch.rpm                      |  13 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : oci-linux-config-1.0-3.el7.noarch               1/1
IMPORTANT: PLEASE NOTE!!  Oracle Linux yum repository configurations have been updated. New repository configuration files have been installed but are disabled.  To complete the transition, run this script as root user:

/usr/lib/oci-linux-config/oci_yum_configure.sh

  検証中                  : oci-linux-config-1.0-3.el7.noarch               1/1

インストール:
  oci-linux-config.noarch 0:1.0-3.el7

完了しました!
$

/usr/lib/oci-linux-config/oci_yum_configure.sh を実行して /etc/yum.repos.d/ のレポジトリファイルを作成

$ ls -l /etc/yum.repos.d/
合計 84
-rw-r--r--. 1 root root  488  2月 17 06:40 ksplice-ol7.repo
-rw-r--r--. 1 root root  273  5月 13 15:39 oracle-epel-ol7.repo
-rw-r--r--. 1 root root  242  8月 15  2019 oracle-epel-ol7.repo.20190815
-rw-r--r--. 1 root root  252  5月 13 15:38 oracle-epel-ol7.repo.20210217
-rw-r--r--. 1 root root 4322  6月 11 04:12 oracle-linux-ol7.repo
-rw-r--r--. 1 root root 3825  7月 10  2020 oracle-linux-ol7.repo.20200710
-rw-r--r--. 1 root root 4586  6月  9 12:57 oracle-linux-ol7.repo.rpmnew
-rw-r--r--. 1 root root 1067  2月 26 04:35 oracle-php-ol7.repo
-rw-r--r--. 1 root root  797  4月  6  2020 oracle-php-ol7.repo.20200406
-rw-r--r--. 1 root root  275  8月 15  2019 oracle-softwarecollection-ol7.repo
-rw-r--r--. 1 root root  276  2月 17 06:38 oracle-softwarecollection-ol7.repo.rpmnew
-rw-r--r--. 1 root root 1041  2月  5 04:15 oraclelinux-developer-ol7.repo
-rw-r--r--. 1 root root  802 12月 27  2019 oraclelinux-developer-ol7.repo.20200406
-rw-r--r--. 1 root root 3117  9月 30  2019 public-yum-ol7.repo.sav
-rw-r--r--. 1 root root 2577  5月 28  2020 uek-ol7.repo
-rw-r--r--. 1 root root 2108  4月  6  2020 uek-ol7.repo.20200406
-rw-r--r--. 1 root root 2587  2月 17 06:42 uek-ol7.repo.rpmnew
-rw-r--r--. 1 root root  225  5月 28  2020 virt-ol7.repo
-rw-r--r--. 1 root root  226  2月 17 06:42 virt-ol7.repo.rpmnew
$ sudo /usr/lib/oci-linux-config/oci_yum_configure.sh
読み込んだプラグイン:langpacks, ulninfo
No packages marked for update
Disabling Repository ol7_UEKR6
Repository ol7_developer already enabled
Repository ol7_developer_EPEL already enabled
Repository ol7_developer_php74 already enabled
Repository ol7_ksplice already enabled
Repository ol7_latest already enabled
Repository ol7_software_collections already enabled
Enabling Repository ol7_UEKR5
Enabling Repository ol7_addons
Repository ol7_developer already enabled
Repository ol7_developer_EPEL already enabled
Repository ol7_developer_php74 already enabled
Repository ol7_ksplice already enabled
Repository ol7_latest already enabled
Enabling Repository ol7_ociyum_config
Enabling Repository ol7_optional_latest
Repository ol7_software_collections already enabled
$ ls -l /etc/yum.repos.d/
合計 104
-rw-r--r--. 1 root root  488  2月 17 06:40 ksplice-ol7.repo
-rw-r--r--. 1 root root  273  5月 13 15:39 oracle-epel-ol7.repo
-rw-r--r--. 1 root root  242  8月 15  2019 oracle-epel-ol7.repo.20190815
-rw-r--r--. 1 root root  252  5月 13 15:38 oracle-epel-ol7.repo.20210217
-rw-r--r--. 1 root root 4586  6月 16 10:15 oracle-linux-ol7.repo
-rw-r--r--. 1 root root 3825  7月 10  2020 oracle-linux-ol7.repo.20200710
-rw-r--r--. 1 root root 4322  6月 11 04:12 oracle-linux-ol7.repo.bkp
-rw-r--r--. 1 root root 4586  6月  9 12:57 oracle-linux-ol7.repo.rpmnew.bkp
-rw-r--r--. 1 root root 1067  2月 26 04:35 oracle-php-ol7.repo
-rw-r--r--. 1 root root  797  4月  6  2020 oracle-php-ol7.repo.20200406
-rw-r--r--. 1 root root  276  2月 17 06:38 oracle-softwarecollection-ol7.repo
-rw-r--r--. 1 root root  275  8月 15  2019 oracle-softwarecollection-ol7.repo.bkp
-rw-r--r--. 1 root root  276  2月 17 06:38 oracle-softwarecollection-ol7.repo.rpmnew.bkp
-rw-r--r--. 1 root root 1041  2月  5 04:15 oraclelinux-developer-ol7.repo
-rw-r--r--. 1 root root  802 12月 27  2019 oraclelinux-developer-ol7.repo.20200406
-rw-r--r--. 1 root root 3117  9月 30  2019 public-yum-ol7.repo.sav
-rw-r--r--. 1 root root 2587  6月 16 10:15 uek-ol7.repo
-rw-r--r--. 1 root root 2108  4月  6  2020 uek-ol7.repo.20200406
-rw-r--r--. 1 root root 2577  5月 28  2020 uek-ol7.repo.bkp
-rw-r--r--. 1 root root 2587  2月 17 06:42 uek-ol7.repo.rpmnew.bkp
-rw-r--r--. 1 root root  226  2月 17 06:42 virt-ol7.repo
-rw-r--r--. 1 root root  225  5月 28  2020 virt-ol7.repo.bkp
-rw-r--r--. 1 root root  226  2月 17 06:42 virt-ol7.repo.rpmnew.bkp
$

以前のrepoファイルは全て bkpという名前にリネームされて置き換わった感じですね。

各レポジトリファイルの変更点は「baseurl=https://yum$ociregion.oracle.com/repo/OracleLinux/」という記載だったものが「baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/」というように「oracle.com」以外のドメインが設定される可能性に配慮したものに変更されていた。

この$ociregionや$ocidomainはどこで設定されているかというと /etc/yum/vars/ にあるファイルで定義されています。

$ ls -l /etc/yum/vars/
合計 12
-rw-r--r--. 1 root root 11  6月 16 10:15 ocidomain
-rw-r--r--. 1 root root 14  6月 16 10:15 ociregion
-rw-r--r--. 1 root root 13  6月 16 10:15 region
$ cat /etc/yum/vars/ocidomain
oracle.com
$ cat /etc/yum/vars/ociregion
-us-phoenix-1
$ cat /etc/yum/vars/region
us-phoenix-1
$

Oracle Cloud上のLinuxインスタンスでiscsistartというサービスが起動失敗している

Oracle Cloud上Linuxインスタンスでol-consolebaud.serviceの起動に失敗している」の件で、これまでに作ったインスタンスの状態を確認していったところ、一番古いLinuxインスタンスでは「iscsistart_169.254.0.2:::1:iqn.2015\http://x2d02.oracle.boot:uefi.service」というサービスの起動に失敗していた。

ぐぐるとOracleサポートの「OCI: iscsistart attempts to connect iscsi target when the network link is not ready (Doc ID 2610486.1)」が出てくるがサポートがないので内容がわからない。

とりあえず、起動失敗しているものと起動成功しているものの/etc/default/grubを比較してみたところ、起動成功しているもののGRUB_CMDLINE_LINUX行には「rd.iscsi.bypass」が追加されていた。

GRUB_CMDLINE_LINUX行に追加して「grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg」を実行してgrub設定を更新、再起動して、問題無く起動するようになった。


確認したOracle Linuxインスタンスの /etc/default/grub設定の比較

Oracle-Linux-7.7-2019.08.28-0 の /etc/default/grub

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_DISABLE_RECOVERY="true"
GRUB_TERMINAL="console"
GRUB_CMDLINE_LINUX="crashkernel=auto LANG=en_US.UTF-8 console=tty0 console=ttyS0,9600 rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0 netroot=iscsi:169.254.0.2:::1:iqn.2015-02.oracle.boot:uefi iscsi_param=node.session.timeo.replacement_timeout=6000 net.ifnames=1 nvme_core.shutdown_timeout=10 ipmi_si.tryacpi=0 ipmi_si.trydmi=0 ipmi_si.trydefaults=0 libiscsi.debug_libiscsi_eh=1 loglevel=4"

CentOS-7-2020.06.16-0 の /etc/default/grub

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_DISABLE_RECOVERY="true"
GRUB_TERMINAL="console"
GRUB_CMDLINE_LINUX="crashkernel=auto LANG=en_US.UTF-8 transparent_hugepage=never console=tty0 console=ttyS0,9600 libiscsi.debug_libiscsi_eh=1 rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0 ip=dhcp netroot=iscsi:169.254.0.2::::iqn.2015-02.oracle.boot:uefi iscsi_param=node.session.timeo.replacement_timeout=6000 net.ifnames=1 rd.iscsi.bypass"

Oracle-Autonomous-Linux-7.8-2020.05-0 の /etc/default/grub

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_DISABLE_RECOVERY="true"
GRUB_TERMINAL="console"
GRUB_CMDLINE_LINUX="crashkernel=auto LANG=en_US.UTF-8 console=tty0 console=ttyS0,9600 rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0 rd.iscsi.bypass=1 netroot=iscsi:169.254.0.2:::1:iqn.2015-02.oracle.boot:uefi iscsi_param=node.session.timeo.replacement_timeout=6000 net.ifnames=1 nvme_core.shutdown_timeout=10 ipmi_si.tryacpi=0 ipmi_si.trydmi=0 ipmi_si.trydefaults=0 libiscsi.debug_libiscsi_eh=1 loglevel=4"

Oracle-Linux-8.3-2021.05.12-0 の /etc/default/grub

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
GRUB_TERMINAL="console"
GRUB_CMDLINE_LINUX="crashkernel=auto LANG=en_US.UTF-8 console=tty0 console=ttyS0,9600 rd.luks=0 rd.md=0 rd.dm=0 rd.lvm.vg=ocivolume rd.lvm.lv=ocivolume/root rd.net.timeout.carrier=5 netroot=iscsi:169.254.0.2:::1:iqn.2015-02.oracle.boot:uefi rd.iscsi.param=node.session.timeo.replacement_timeout=6000 net.ifnames=1 nvme_core.shutdown_timeout=10 ipmi_si.tryacpi=0 ipmi_si.trydmi=0 libiscsi.debug_libiscsi_eh=1 loglevel=4 ip=single-dhcp crash_kexec_post_notifiers"

Oracle-Linux-8.3-aarch64-2021.05.12-0 の /etc/default/grub

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
GRUB_TERMINAL="console"
GRUB_CMDLINE_LINUX="crashkernel=auto LANG=en_US.UTF-8 console=ttyAMA1 console=ttyAMA0,115200 rd.luks=0 rd.md=0 rd.dm=0 rd.lvm.vg=ocivolume rd.lvm.lv=ocivolume/root rd.net.timeout.carrier=5 netroot=iscsi:169.254.0.2:::1:iqn.2015-02.oracle.boot:uefi rd.iscsi.param=node.session.timeo.replacement_timeout=6000 net.ifnames=1 nvme_core.shutdown_timeout=10 ipmi_si.tryacpi=0 ipmi_si.trydmi=0 libiscsi.debug_libiscsi_eh=1 loglevel=4 ip=single-dhcp crash_kexec_post_notifiers"

Oracle Cloud上Linuxインスタンスでol-consolebaud.serviceの起動に失敗している

2020年にOracle Cloud上に作ったLinuxインスタンスの状態を「systemctl status」で確認してみたら、ol-consolebaud.serviceの起動に失敗していた。

画像
ol-consolebaud.service: main process exited, code=exited, status=1/FAILURE
Failed to start Check console baud rate.
Unit ol-consolebaud.service entered failed state.
ol-consolebaud.service failed.

検索してみるとRogerio Eguchi Blog の「OCI – ol-consolebaud.service」を発見。

/etc/default/grub に書かれているシリアルコンソール設定の速度が9600から115200に変更になったことが原因のようである。

Oracle Cloud Infrastructure ドキュメントを確認すると「インポートされたLinuxイメージでのシリアル・コンソール・アクセスの有効化」のブートローダの構成で設定している速度が115200になっている。そして、”シリアルコンソールアクセスの検証”では9600になっていてドキュメントの整合性がとれていない・・・というわけで、途中で変更されたようなのだが、All Oracle Linux 7.x Images の履歴をみたけど、それっぽい変更が見当たらない・・・うーん?

まあ、ともかく原因は判明したのでGRUB_CMDLINE_LINUX行の「console=ttyS0,9600」を「console=ttyS0,115200」に変更。

そして、 「grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg」でgrubブートローダに変更を反映して、再起動。

これでol-consolebaudが正常に起動するようになった。

Oracle Cloud上のインスタンスから管理メールを送信する手法

Oracle Cloud上に作成したインスタンスのうち、Oracle Autonomouse Linux 7インスタンスだと適切に設定している場合、yum-cronなどが実行された際に 送信者 noreply@notification.~.oci.oraclecloud.com でメールを送信する設定になっている。

Oralce Linux 8インスタンスだとそのような設定にはなっていない。

似たような形でインスタンスのrootから送信されるメールを noreply@notification.~.oci.oraclecloud.com で発信する方法があるかを確認した。

参考ドキュメント
Oracle Cloud Infrastructureドキュメント「電子メール配信の開始
Oracle Cloud Infrastructureドキュメント「Postfixと電子メール配信の統合

しかし、「電子メール配信」については有料アカウントが必要になるようだ。

Oracle Autonomouse Linux 7インスタンスが利用しているのは「通知」の方になっている

このサブスクリプション設定が流用できればいいんですけど・・・

Oracle Cloud : 通知サービスとoci-cliを使って一時間ごとにDBCSの状態を通知する

この情報が使えそうです。

今回の環境ではすでに[開発者サービス]-[アプリケーション統合]-[通知]に

すでにAutonomouse Linux用で作成したトピックが作成されているため、それを流用します。

上記の「AL_notification」のトピックOCIDを使用してコマンドを実行・・・

$ oci ons message publish --topic-id ocid1.onstopic.oc1.ap-tokyo-1.<略> --title "test mail" --body "test mail"
-bash: oci: command not found
$

oci-utilsのパッケージがアップデートされていないとエラーになります。その場合はアップデートします。

2024/10/15: いまは python39-oci-cli か python36-oci-cli にociコマンドが含まれているようなので、 oci-utils と python3?-oci-cli をインストールします。

$ sudo dnf update oci-utils -y
Last metadata expiration check: 4:26:16 ago on Tue 08 Jun 2021 01:30:06 PM JST.
Dependencies resolved.
================================================================================
 Package                  Arch     Version            Repository           Size
================================================================================
Upgrading:
 oci-utils                noarch   0.12.4-1.el8       ol8_oci_included    245 k
Installing dependencies:
 python3-arrow            noarch   0.17.0-1.0.1.el8   ol8_oci_included    101 k
 python3-click            noarch   6.7-8.el8          ol8_appstream       131 k
 python3-convertdate      noarch   2.3.0-1.0.1.el8    ol8_oci_included     83 k
 python3-dateparser       noarch   1.0.0-1.0.1.el8    ol8_oci_included    392 k
 python3-hijri-converter  noarch   2.1.1-1.0.1.el8    ol8_oci_included     30 k
 python3-jmespath         noarch   0.10.0-1.el8       ol8_oci_included     48 k
 python3-pymeeus          noarch   0.3.6-2.0.1.el8    ol8_oci_included    1.1 M
 python3-regex            aarch64  2021.4.4-1.el8     ol8_developer_EPEL  328 k
 python3-retrying         noarch   1.3.3-1.0.1.el8    ol8_oci_included     22 k
 python3-terminaltables   noarch   3.1.0-1.0.1.el8    ol8_oci_included     31 k
 python3-tzlocal          noarch   2.0.0-4.el8        ol8_oci_included     37 k
 python36-oci-cli         noarch   2.22.1-1.el8       ol8_oci_included    6.4 M

Transaction Summary
================================================================================
Install  12 Packages
Upgrade   1 Package

Total download size: 8.9 M
<略>
$

$ oci ons message publish --topic-id ocid1.onstopic.oc1.ap-tokyo-1.<略> --title "test mail" --body "test mail"
ERROR: Could not find config file at /home/opc/.oci/config, please follow the instructions in the link to setup the config file https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm
$

ociコマンドに必要な諸設定を行っていないのでエラーになりました。

まず、キーを作成します。なお、passphraseは何も入力せずエンターキーのみにします(そうしないとスクリプト実行の時にpassphraseを要求される)

$ oci setup keys
Enter a passphrase for your private key (empty for no passphrase):
Public key written to: /home/opc/.oci/oci_api_key_public.pem
Private key written to: /home/opc/.oci/oci_api_key.pem
Public key fingerprint: xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx


    If you haven't already uploaded your API Signing public key through the
    console, follow the instructions on the page linked below in the section
    'How to upload the public key':

        https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#How2

$  ls -al ~/.oci
total 8
drwx------. 2 opc opc   59 Jun  7 17:32 .
drwx------. 5 opc opc  138 Jun  7 17:32 ..
-rw-------. 1 opc opc 1679 Jun  7 17:32 oci_api_key.pem
-rw-------. 1 opc opc  451 Jun  7 17:32 oci_api_key_public.pem
$

作成された oci_api_key_public.pem の内容を[アイデンティティとセキュリティ]-[アイデンティティ]-[ユーザー]に登録されている各ユーザから、使用するユーザを選択し[リソース]-[APIキー]に登録します。

なお、APIキーは無料アカウントでは3つまで登録可能で、それ以上は登録できませんでした。
使ってないものを消すには面倒くさいですが、各ユーザの~/.oci/oci_api_key.pem のフィンガープリントを計算して、登録されているものを比較する必要があります。

フィンガープリントの計算手法はOracle Cloudドキュメント「キーのフィンガープリントの取得方法」にあるように「openssl rsa -pubout -outform DER -in ~/.oci/oci_api_key.pem | openssl md5 -c」で実施出来ます。

つぎに~/.oci/config ファイル作成のために

[ガバナンスと管理]-[アカウント管理]-[テナンシ詳細]にて、テナントのOCIDを取得

また、ユーザのOCIDと先ほど登録したAPIキーのフィンガープリントを configファイルに記載する。

$ cat ~/.oci/config
[DEFAULT]
key_file=/home/opc/.oci/oci_api_key.pem
region=ap-tokyo-1
tenancy=ocid1.tenancy.oc1..aaaaaaaa7lml<略>
user=ocid1.user.oc1..aaaaaaaamenibh4iny<略>
fingerprint=<略>
$

記載してociコマンドを再実行

$ oci ons message publish --topic-id ocid1.onstopic.oc1.ap-tokyo-1.aa<略> --title "test mail" --body "test mail"
WARNING: Permissions on /home/opc/.oci/config are too open.
To fix this please try executing the following command:
oci setup repair-file-permissions --file /home/opc/.oci/config
Alternatively to hide this warning, you may set the environment variable, OCI_CLI_SUPPRESS_FILE_PERMISSIONS_WARNING:
export OCI_CLI_SUPPRESS_FILE_PERMISSIONS_WARNING=True

{
  "data": {
    "message-id": "56ca7636-1605-7a19-5344-<略>",
    "time-stamp": null
  }
}
$

まず、「WARNING: Permissions on /home/opc/.oci/config are too open.」についてはパーミッション問題なので、書いてある通りに対処する。

$ ls -l /home/opc/.oci/config
-rw-rw-rw-. 1 opc opc 299 Jun  7 17:43 /home/opc/.oci/config
$ oci setup repair-file-permissions --file /home/opc/.oci/config
$ ls -l /home/opc/.oci/config
-rw-------. 1 opc opc 299 Jun  7 17:43 /home/opc/.oci/config
$

再実行

$ oci ons message publish --topic-id ocid1.onstopic.oc1.ap-tokyo-1.aaaaaaaacesi5<略> --title "test mail" --body "test mail"
{
  "data": {
    "message-id": "c491e672-9401-beb3-16f5-<略>",
    "time-stamp": null
  }
}
$

成功か失敗か分かりづらいですが、成功していました。(WARNING: Permissions の時のやつもメール送信は出来ていました)

というわけで、ociコマンドを使用することで、Oracle Cloudの通知を使ってシステムメールを送信することができそうなことがわかりました。

ociコマンドは https://github.com/oracle/oci-cli にソースがある

つぎに dnf automaticでそれを実行するにはどういう手法が最適化の検討です。

DNF Automatic」には「[command] section」と「[command_email] section」があり、利用できそうです。

違いの詳細については「RHEL8/CentOS8のdnf automaticのemitters設定を調べた」に書きましたが、今回の場合は[command_email]sectionを使うことにします。

dnf automaticではメール本文を標準入力で指定することになっていて、そのままではociコマンドのbodyオプションとして渡すことができません。

なので、Oracle Cloud Infrastructure Document Notifications Publish Messages(日本語版) を起点に調べていったところOracle Cloud Infrastructure Documentation / API Reference and Endpoints の「PublishMessage」にて、REST API/Java SDK/Python SDK/Go SDK/TypeScript SDK/.NET SDK/Ruby SDKを使った場合のコードサンプルを発見。

ociコマンドはpyhonを使っているので、Python SDKのサンプルコードを利用した /usr/local/bin/oci-notification-mail を作って使用します。

topic_id=のところは自分の環境に合わせてください。

$ sudo vi /usr/local/bin/oci-notification-mail
$ cat /usr/local/bin/oci-notification-mail
#!/usr/bin/python3
# This is an automatically generated code sample.
# To make this code sample work in your Oracle Cloud tenancy,
# please replace the values for any parameters whose current values do not fit
# your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
# boolean, number, and enum parameters with values not fitting your use case).

import oci
import sys

argvs=sys.argv
argc = len(argvs)
subject=argvs[1]
textbody="".join(sys.stdin.readlines())

# Create a default config using DEFAULT profile in default location
# Refer to
# https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File
# for more info
config = oci.config.from_file()


# Initialize service client with default config file
ons_client = oci.ons.NotificationDataPlaneClient(config)

# Send the request to service, some parameters are not required, see API
# doc for more info
publish_message_response = ons_client.publish_message(
    topic_id="ocid1.onstopic.oc1.ap-tokyo-1.<略>",
    message_details=oci.ons.models.MessageDetails(
        body=textbody,
        title=subject),
    message_type="RAW_TEXT")

# Get the data from response
print(publish_message_response.data)
$ sudo chmod a+x /usr/local/bin/oci-notification-mail
$

まずこれを作成したあと、送信テストをします。

$ cat /etc/hosts | /usr/local/bin/oci-notification-mail testmail
{
  "message_id": "ef1aa15b-98d0-1824-68ef-<略>",
  "time_stamp": null
}
$

これを実行してしばらく待つと、「Subject:testmail」 で、本文が/etc/hostsの中身になっているメールが届きます。

スクリプトが正常に動作することを確認できたら、ociコマンドがrootユーザでも実行できるように .oci ディレクトリの内容を /root/.oci にコピーします。書かれてるpemファイルのパスなどはそのままでかまいません。注意点は /root/.oci ディレクトリの権限を 700 にしておく、ということです。

最後にdnf automaticの設定を変更します。

変更する場所は2つ

「[emitters] セクション」のemit_via を「emit_via=command_email」に変更

「[command_email]セクション」のcommand_formatを「command_format = “/usr/local/bin/oci-notification-mail {subject}”」、「#stdin_format = “{body}”」を「stdin_format = “{body}”」に変更します。

これにより、dnf automaticでパッチが適用された場合に下記の様なメールが届くようになりました。

おまけ

ちなみに、Oracle Linux 8の標準インスタンスではpostfixやsendmailではなく、esmtp というパッケージでメール送信が行われるようです。

$ ls -l /usr/sbin/sendmail
lrwxrwxrwx. 1 root root 21 May 27 13:04 /usr/sbin/sendmail -> /etc/alternatives/mta
$ ls -l /etc/alternatives/mta
lrwxrwxrwx. 1 root root 22 May 27 13:04 /etc/alternatives/mta -> /usr/bin/esmtp-wrapper
$ ls -l /usr/bin/esmtp-wrapper
-rwxr-xr-x. 1 root root 3374 Jul  2  2020 /usr/bin/esmtp-wrapper
$  rpm -qa|grep smtp
esmtp-1.2-15.el8.aarch64
libesmtp-1.0.6-18.el8.aarch64
$ alternatives --display mta
mta - status is auto.
 link currently points to /usr/bin/esmtp-wrapper
/usr/bin/esmtp-wrapper - priority 30
 slave mta-sendmail: /usr/bin/esmtp-wrapper
 slave mta-sendmailman: /usr/share/man/man1/esmtp.1.gz
 slave mta-mailq: /usr/bin/esmtp-wrapper
 slave mta-mailqman: /usr/share/man/man1/esmtp.1.gz
Current `best' version is /usr/bin/esmtp-wrapper.
$

公式ページに「THIS PROJECT IS NO LONGER BEING MAINTAINED. IF IT DOESN’T WORK FOR YOU SEE THESE LINKS.」って書いてあるのにRHEL/CentOS/Oracle Linux 8で使っているのか・・・

Oracle Linux 8でWordPressサーバを立てる

Oracle CloudのAlways Freeで作れるインスタンスにARMベースのインスタンスが追加された。

従来のCPU1個/メモリ1GBに対して、CPU1~4個/メモリ6GB~24GBと破格のスペックなので、Wordpressサーバでも移行してみるかな、と思って、「CentOS 7 / Oracle Linux 7でWordPressサーバを建てる」の手順でつくろうとしてみたところ、Oracle Linux 7 ARMではPHP Packages for Oracle Linuxが提供されていなかった。

Oracle Linux 8であれば標準状態でphp 7.4が利用できるようなので、Oracle Linux 8で作成する手順を策定した。

変更履歴

・Wordpress本体を更新しようとしたらできなかったので「手順8-2: php-fpmの書き込み権限問題」追加
・既存blogのデータをインポートしようとしたらファイルサイズオーバーだったので「手順9: WordPressで取り扱えるファイルサイズの拡大」追加
・存在を思い出したので「手順10: WordPressのSite Health Status対応」追加
・パーマリンク設定を変更したら動かなかったので「手順11: WordPressの.htaccess有効化」追加
・「手順12: OS自動更新の設定」追加
・日本語Localeに設定した場合の対応として「手順2-3:日本語Locale対応」追加
・2022/04/06にOracle-Linux-8.5-aarch64-2022.03.17-1を使って構築した時の状況を追加
・手順8が2つあったので番号を振り直した
・wordpressにWP Multibyte Patchをインストールする手順を書き忘れていたので追加

また、手順8以降でWordpressにアクセスすると「Service Unavailable」と表示される場合があります。その場合は、php-fpmのSELinuxポリシー設定問題であるため「Oracle Linux 8でphp 7.4.19-1にアップデート後からphp-fpmが起動しなくなった」の対処を行ってみてください。

準備1: Oracle Cloud用手順

準備1-1: IPv6アドレス割り当て:Oracle Cloudコンソール側

Oracle Cloudのコンソールを開いて、インスタンスにIPv6アドレスを割り当てます。

また、割り当てられたIPv6アドレスを確認します。

準備1-2: インスタンス側操作

2021年5月27日の段階ではOracle Cloud環境で提供されるOracle Linux 8でIPv6アドレスの自動割り当てが動作していませんでした。

Oracle-Linux-8.5-aarch64-2022.03.17-1(2022/04/06時点)やOracle-Linux-8.6-aarch64-2022.05.30-0(2022/07/01時点)でも同様でした。

このため、firewalldの設定でdhcpv6-clientが許可されていないために発生していましたので、許可します。

まず初期状態を確認

$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$

dhcpv6-clientの許可設定と設定読み込みと確認

$ sudo firewall-cmd --permanent --add-service=dhcpv6-client
success
$ sudo firewall-cmd --reload
success
$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$

準備2: 一般的な前準備

準備2-1: 日本時間にする

日本に住んでいる場合、日本時間表記の方が使いやすいので、OSも日本時間表示に設定する。

$ sudo timedatectl set-timezone Japan
$ 

準備2-2: パッケージを最新にアップデートする

現時点でインストール済みパッケージを最新にします。

Oracle Linux 8ではyum updateではなくdnf updateとなります。アップデート後は再起動します。(yumコマンドでも動きます)

$ sudo dnf update -y
<略>
$ sudo reboot

手順2-3:日本語Locale対応

ja_JP.UTF-8など日本語Localeで設定した際、「Failed to set locale, defaulting to C.UTF-8」というメッセージが出力される場合があります。

その場合は日本語Localeを追加インストールします。

$ sudo dnf install langpacks-ja glibc-langpack-ja
<略>
$

手順3: EPELレポジトリの追加

EPELレポジトリを使うので、使用できるようにします。

Oracle Cloud上のOracle Linux 8環境ではレポジトリパッケージのインストールはされているので、有効化を行います。(なお、/etc/yum.repo.d/のファイルを編集するのは時代遅れな操作です)

また、2021年11月以降のOracle Cloudでの新規インスタンスではOS管理が有効になっている関係で手順が変わっています。新規で作る場合は手順3-1bの方を参照してください。

手順3-1a:通常の手順

Oracle Cloud外の環境でOracle Linux 8をインストールしている場合や古めのOracle Cloudインスタンスの場合、こちらのOS側のコマンドで設定する手順を行います。

現状のレポジトリ設定状況を「sudo dnf repolist –all」を実行して確認します。

$ sudo dnf repolist --all
repo id                          repo name                              status
ol8_MySQL80                      MySQL 8.0 for Oracle Linux 8 (aarch64) enabled
ol8_MySQL80_connectors_community MySQL 8.0 Connectors Community for Ora enabled
ol8_MySQL80_tools_community      MySQL 8.0 Tools Community for Oracle L enabled
ol8_aarch64_userspace_ksplice    Ksplice aware userspace packages for O disabled
ol8_appstream                    Oracle Linux 8 Application Stream (aar enabled
ol8_baseos_latest                Oracle Linux 8 BaseOS Latest (aarch64) enabled
ol8_codeready_builder            Oracle Linux 8 CodeReady Builder (aarc disabled
ol8_developer                    Oracle Linux 8 Development Packages (a disabled
ol8_developer_EPEL               Oracle Linux 8 EPEL Packages for Devel disabled
ol8_developer_UEKR6              Developer Preview of UEK Release 6 (aa disabled
ol8_distro_builder               Oracle Linux 8 Distro Builder (aarch64 disabled
ol8_ksplice                      Ksplice for Oracle Linux 8 (aarch64)   enabled
ol8_oci_included                 Oracle Software for OCI users on Oracl enabled
ol8_u2_baseos_base               Oracle Linux 8.2 BaseOS (aarch64)      disabled
ol8_u3_baseos_base               Oracle Linux 8.3 BaseOS (aarch64)      disabled
ol8_u4_baseos_base               Oracle Linux 8.4 BaseOS (aarch64)      disabled
$ 

上記の場合、ol8_developer_EPELが登録されているもののdisabledになっています。

この場合は「sudo dnf config-manager –set-enabled ol8_developer_EPEL」を実行し、enabledに変更されたことを確認します。

$ sudo dnf config-manager --set-enabled ol8_developer_EPEL
$ sudo dnf repolist --all
repo id                          repo name                              status
ol8_MySQL80                      MySQL 8.0 for Oracle Linux 8 (aarch64) enabled
ol8_MySQL80_connectors_community MySQL 8.0 Connectors Community for Ora enabled
ol8_MySQL80_tools_community      MySQL 8.0 Tools Community for Oracle L enabled
ol8_aarch64_userspace_ksplice    Ksplice aware userspace packages for O disabled
ol8_appstream                    Oracle Linux 8 Application Stream (aar enabled
ol8_baseos_latest                Oracle Linux 8 BaseOS Latest (aarch64) enabled
ol8_codeready_builder            Oracle Linux 8 CodeReady Builder (aarc disabled
ol8_developer                    Oracle Linux 8 Development Packages (a disabled
ol8_developer_EPEL               Oracle Linux 8 EPEL Packages for Devel enabled
ol8_developer_UEKR6              Developer Preview of UEK Release 6 (aa disabled
ol8_distro_builder               Oracle Linux 8 Distro Builder (aarch64 disabled
ol8_ksplice                      Ksplice for Oracle Linux 8 (aarch64)   enabled
ol8_oci_included                 Oracle Software for OCI users on Oracl enabled
ol8_u2_baseos_base               Oracle Linux 8.2 BaseOS (aarch64)      disabled
ol8_u3_baseos_base               Oracle Linux 8.3 BaseOS (aarch64)      disabled
ol8_u4_baseos_base               Oracle Linux 8.4 BaseOS (aarch64)      disabled
$

手順3-1b:Oracle CloudのOS管理下にある場合の手順

2022年4月6日時点でOracle Cloud上で提供されているOracle-Linux-8.5-aarch64-2022.03.17-1では「sudo dnf repolist –all」の実行結果に変化があり、「This system is receiving updates from OSMS server.」と書かれた上で、だいぶ整理されたレポジトリのみが表示されます。

$ sudo dnf repolist --all
This system is receiving updates from OSMS server.
repo id                                  repo name                       status
ol8_addons-aarch64                       Oracle Linux 8 Add ons (aarch64 enabled
ol8_appstream-aarch64                    Oracle Linux 8 Application Stre enabled
ol8_baseos_latest-aarch64                Oracle Linux 8 BaseOS Latest (a enabled
ol8_ksplice-aarch64                      Ksplice for Oracle Linux 8 (aar enabled
ol8_mysql80-aarch64                      MySQL 8.0 for Oracle Linux 8 (a enabled
ol8_mysql80_connectors_community-aarch64 MySQL 8.0 Connectors for Oracle enabled
ol8_mysql80_tools_community-aarch64      MySQL 8.0 Tools Community for O enabled
ol8_oci_included-aarch64                 Oracle Software for OCI users o enabled
$

これはOracle Cloudの「OS管理(OS Managemnt System)」という機能との連携が始まり、Oracle CloudのWebコンソール からパッチ状態を見れるように変更になったためです。

レポジトリの設定変更は上記画面の「…」をクリックし「OS管理詳細の表示」を選択

[リソース]-[ソフトウェア・ソース]から「追加」を選択

「Oralce Linux 8 EPEL Packages for Development」を選択し「追加」

Web上で追加されたことを確認

次にコマンドに戻り「sudo dnf repolist –all」を実行するとEPELレポジトリがenabledとして増えていることが確認できます。

$ sudo dnf repolist --all
This system is receiving updates from OSMS server.
repo id                                  repo name                       status
ol8_addons-aarch64                       Oracle Linux 8 Add ons (aarch64 enabled
ol8_appstream-aarch64                    Oracle Linux 8 Application Stre enabled
ol8_baseos_latest-aarch64                Oracle Linux 8 BaseOS Latest (a enabled
ol8_developer_epel-aarch64               Oracle Linux 8 EPEL Packages fo enabled
ol8_ksplice-aarch64                      Ksplice for Oracle Linux 8 (aar enabled
ol8_mysql80-aarch64                      MySQL 8.0 for Oracle Linux 8 (a enabled
ol8_mysql80_connectors_community-aarch64 MySQL 8.0 Connectors for Oracle enabled
ol8_mysql80_tools_community-aarch64      MySQL 8.0 Tools Community for O enabled
ol8_oci_included-aarch64                 Oracle Software for OCI users o enabled

手順4: インターネット公開用設定

手順4-1: fail2ban導入

公開サーバは各種のアタックにさらされます。管理用sshポートにもやってきます。

多少なりとも軽減するためにEPELレポジトリ収録のfail2banを使用します。

$ sudo dnf install fail2ban -y
$ 

カスタム設定は/etc/fail2ban/jail.localに行います。

$ sudo vi /etc/fail2ban/jail.local
$ cat /etc/fail2ban/jail.local
[DEFAULT]
# 86400秒=24時間以内に5回不審なアクセスがあったら24時間BAN
bantime  = 86400
findtime  = 86400
maxretry = 5
# 259200秒=3日以内に5回不審なアクセスがあったら3日間BAN
#bantime  = 259200
#findtime  = 259200
#maxretry = 5

# 除外IP
ignoreip = 127.0.0.1 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16

[sshd]
enabled = true
banaction = firewallcmd-ipset
$ 

上記設定では24時間BANにしていますが、まぁ、3日BANでもかまわないとは思います。(本当に間違えた場合に困るのでほどほどにしておくとよい)

fail2banをOS起動時に実行する設定と、今すぐfail2banを起動するコマンドを実行します。

$ sudo systemctl enable fail2ban
$ sudo systemctl start fail2ban
$

以降、アタックがあると /var/log/fail2ban.log にログが出ます。

手順4-2: Webサーバ用ポート公開設定

この段階では、dhcpv6-clientとsshのみが許可されています。

Webサーバ公開用にhttp(ポート80)とhttps(ポート443)を追加します。

$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$
$ sudo firewall-cmd --permanent --add-service=http
success
$ sudo firewall-cmd --permanent --add-service=https
success
$ sudo firewall-cmd --reload
success
$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: dhcpv6-client http https ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$

手順5: php 7.4追加

Oracle Linux 8環境では、moduleという形で複数バージョンのソフトウェアが提供されています。

phpに関してどのようなものがあるのかを「dnf module list | grep php」を実行して確認します。

$ sudo dnf module list | grep php
php                  7.2 [d]         common [d], devel, minimal               PHP scripting language                                                                                                                                                                                
php                  7.3             common [d], devel, minimal               PHP scripting language                                                                                                                                                                                
php                  7.4             common [d], devel, minimal               PHP scripting language                                                                                                                                                                                
$

php 7.2が標準選択で、他にphp 7.3とphp 7.4が選べることがわかります。
2022/07/01時点で提供されているOracle Linux 8.6では php 8.0も選択できるようになっています。

php7.4を指定してパッケージを追加します。

$ sudo dnf install @php:7.4 -y
Last metadata expiration check: 0:07:11 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
==========================================================================================================================================
 Package                     Architecture       Version                                                Repository                    Size
==========================================================================================================================================
Installing group/module packages:
 php-cli                     aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                2.8 M
 php-common                  aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                675 k
 php-fpm                     aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                1.5 M
 php-json                    aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                 73 k
 php-mbstring                aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                474 k
 php-xml                     aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                166 k
Installing dependencies:
 httpd-filesystem            noarch             2.4.37-39.0.1.module+el8.4.0+20024+b87b2deb            ol8_appstream                 39 k
 libxslt                     aarch64            1.1.32-6.0.1.el8                                       ol8_baseos_latest            239 k
 nginx-filesystem            noarch             1:1.14.1-9.0.1.module+el8.0.0+5347+9282027e            ol8_appstream                 25 k
Installing module profiles:
 php/common
Enabling module streams:
 httpd                                          2.4
 nginx                                          1.14
 php                                            7.4

Transaction Summary
==========================================================================================================================================
Install  9 Packages

Total download size: 5.9 M
Installed size: 23 M
Downloading Packages:
<略>
$

手順6: MySQL設定編

Oralce Linux 8ではわざわざ「MySQL 8.0 for Oracle Linux 8 (aarch64)」を用意していますが、よく見るとそこにmysql-serverはなく、メインのol8_appstream に含まれているという理由はよくわかりませんが、せっかくなのでそのまま使用します。

(ちなみにol8_appstreamではmariadb 10.3と10.5も提供されていますので変更することもできます)

$ sudo dnf install mysql-server -y
Last metadata expiration check: 0:56:46 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package      Arch    Version                               Repository     Size
================================================================================
Installing:
 mysql-server aarch64 8.0.21-1.module+el8.2.0+7793+cfe2b687 ol8_appstream  28 M
Installing dependencies:
 mariadb-connector-c-config
              noarch  3.1.11-2.el8_3                        ol8_appstream  15 k
 mecab        aarch64 0.996-1.module+el8.0.0+5253+1dce7bb2.9
                                                            ol8_appstream 367 k
 mysql        aarch64 8.0.21-1.module+el8.2.0+7793+cfe2b687 ol8_appstream  13 M
 mysql-common aarch64 8.0.21-1.module+el8.2.0+7793+cfe2b687 ol8_appstream 147 k
 mysql-errmsg aarch64 8.0.21-1.module+el8.2.0+7793+cfe2b687 ol8_appstream 581 k
 protobuf-lite
              aarch64 3.5.0-13.el8                          ol8_appstream 129 k
Enabling module streams:
 mysql                8.0

Transaction Summary
================================================================================
Install  7 Packages

Total download size: 42 M
Installed size: 228 M
Downloading Packages:
<略>
$

mysqldを自動起動する設定とします。

$ sudo systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
$

mysqldを起動します。

$ sudo systemctl start mysqld
$

WordPress用データベースを作成します。

MySQL 8におけるデータベースユーザ作成と権限の割り当てが従来の「grant all on DB名.* to wordpress@localhost identified by ‘パスワード’;」という一文から、「create user ~」と「grant ~」の2つに分かれている点に注意が必要です。

$ sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database DB名 character set utf8;
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> create user wordpress@localhost  identified by 'パスワード';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on DB名.* to wordpress@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
$

手順7: Webサーバ設定

手順7-1: httpdインストール

httpdをインストールします。

Oracle Linux 8では httpd(Apache) 2.4と nginx 1.14 / 1.16 / 1.18 が使用できますが、httpdを使用します。nginxを使用したい場合は「Oracle Autonomous Linuxでwordpressサーバを建ててみた」を参照してください。

$ sudo dnf install httpd -y
Last metadata expiration check: 0:08:49 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
==========================================================================================================================================
 Package                      Architecture      Version                                                 Repository                   Size
==========================================================================================================================================
Installing:
 httpd                        aarch64           2.4.37-39.0.1.module+el8.4.0+20024+b87b2deb             ol8_appstream               1.4 M
Installing dependencies:
 apr                          aarch64           1.6.3-11.el8                                            ol8_appstream               119 k
 apr-util                     aarch64           1.6.1-6.el8                                             ol8_appstream               104 k
 httpd-tools                  aarch64           2.4.37-39.0.1.module+el8.4.0+20024+b87b2deb             ol8_appstream               104 k
 mod_http2                    aarch64           1.15.7-3.module+el8.4.0+20024+b87b2deb                  ol8_appstream               146 k
 oracle-logos-httpd           noarch            84.3-1.0.1.el8                                          ol8_baseos_latest            29 k

Transaction Summary
==========================================================================================================================================
Install  6 Packages

Total download size: 1.8 M
Installed size: 10 M
Downloading Packages:
<略>
$

次で設定変更をするので、この段階ではhttpdを起動しません。

OS起動時に自動起動する設定だけを行います。

$ sudo systemctl enable httpd
$

手順7-2: dehydratedによるLet’s Encrypt導入

Let’s EncryptによるSSL証明書導入はcertbotを使うのが一般的ではあるのだが、python環境とあわせてパッケージサイズが大きいので、コンパクトでEPELにも収録されているdehydratedを使用する。

$ sudo dnf install dehydrated -y
Last metadata expiration check: 1:07:45 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package          Architecture Version           Repository                Size
================================================================================
Installing:
 dehydrated       noarch       0.6.5-1.el8       ol8_developer_EPEL        90 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 90 k
Installed size: 164 k
Downloading Packages:
<略>
$

dehydratedによるSSL証明書取得処理には /var/www/dehydrated が使用されるためディレクトリを作成します。

$ sudo mkdir  /var/www/dehydrated
$

http://~/.well-known/acme-challenge でアクセスした時に上記ディレクトリが開くようApacheの設定を /etc/httpd/conf.d/dehydrated.conf として作成します。(sudo vi /etc/httpd/conf.d/dehydrated.conf )

$ sudo vi /etc/httpd/conf.d/dehydrated.conf
$ cat /etc/httpd/conf.d/dehydrated.conf
Alias /.well-known/acme-challenge /var/www/dehydrated
<Directory /var/www/dehydrated/>
</Directory>
$

httpdを起動します

$ sudo systemctl start httpd
$

SSL証明書を発行するホスト名を /etc/dehydrated/domains.txt に記載する。(sudo vi /etc/dehydrated/domains.txt)

1行に複数のホスト名を記載するとaliasになります。

$ sudo vi /etc/dehydrated/domains.txt
$ sudo cat /etc/dehydrated/domains.txt
ホスト1名.ドメイン名 ホスト2名.ドメイン名
$

登録操作を開始します。

$ sudo dehydrated --register
# INFO: Using main config file /etc/dehydrated/config
# INFO: Using additional config file /etc/dehydrated/conf.d/local.sh

To use dehydrated with this certificate authority you have to agree to their terms of service which you can find here: https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf

To accept these terms of service run `/bin/dehydrated --register --accept-terms`.
$ sudo /bin/dehydrated --register --accept-terms
# INFO: Using main config file /etc/dehydrated/config
# INFO: Using additional config file /etc/dehydrated/conf.d/local.sh
+ Generating account key...
+ Registering account key with ACME server...
+ Fetching account ID...
+ Done!
$

初回のSSL証明書発行処理を実行します。

$ sudo dehydrated --cron
# INFO: Using main config file /etc/dehydrated/config
# INFO: Using additional config file /etc/dehydrated/conf.d/local.sh
Processing ホスト1名.ドメイン名 with alternative names: ホスト2名.ドメイン名
 + Signing domains...
 + Generating private key...
 + Generating signing request...
 + Requesting new certificate order from CA...
 + Received 2 authorizations URLs from the CA
 + Handling authorization for ホスト1名.ドメイン名
 + Handling authorization for ホスト2名.ドメイン名
 + 2 pending challenge(s)
 + Deploying challenge tokens...
 + Responding to challenge for ホスト1名.ドメイン名 authorization...
 + Challenge is valid!
 + Responding to challenge for ホスト2名.ドメイン名 authorization...
 + Challenge is valid!
 + Cleaning challenge tokens...
 + Requesting certificate...
 + Checking certificate...
 + Done!
 + Creating fullchain.pem...
 + Done!
$

手順7-3: WebサーバへのSSL証明書設定

まず、httpdにmod_sslを追加します。

$ sudo dnf install mod_ssl -y
Last metadata expiration check: 1:36:21 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package
      Arch    Version                                       Repository     Size
================================================================================
Installing:
 mod_ssl
      aarch64 1:2.4.37-39.0.1.module+el8.4.0+20024+b87b2deb ol8_appstream 126 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 126 k
Installed size: 274 k
Downloading Packages:
<略>
$

標準の /etc/httpd/conf.d/ssl.conf は使わず、Mozilla SSL Configuration Generatorベースの設定を /etc/httpd/conf.d/ssl-mozilla.conf として作成します。(なお、ssl.conf には”Listen 443 https”設定もあるので、そのままにしています)

$ sudo vi /etc/httpd/conf.d/ssl-mozilla.conf
$ cat /etc/httpd/conf.d/ssl-mozilla.conf
# generated 2021-05-27, Mozilla Guideline v5.6, Apache 2.4.37, OpenSSL 1.1.1g, intermediate configuration
# https://ssl-config.mozilla.org/#server=apache&version=2.4.37&config=intermediate&openssl=1.1.1g&guideline=5.6

# this configuration requires mod_ssl, mod_socache_shmcb, mod_rewrite, and mod_headers
<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on

    # curl https://ssl-config.mozilla.org/ffdhe2048.txt >> /path/to/signed_cert_and_intermediate_certs_and_dhparams
    SSLCertificateFile      /etc/dehydrated/certs/<ホスト名>/cert.pem
    SSLCertificateKeyFile   /etc/dehydrated/certs/<ホスト名>/privkey.pem

    # enable HTTP/2, if available
    Protocols h2 http/1.1

    # HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
    Header always set Strict-Transport-Security "max-age=63072000"
</VirtualHost>

# intermediate configuration
SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite          ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder     off
SSLSessionTickets       off

SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
$

httpdを再起動します。

$ sudo systemctl restart httpd
$

手順8: WordPress導入

手順8-1: WordPressの基本インストール

WordPressのWebから最新版をダウンロードして、/var/www/html以下に展開します。
(日本語環境向けのlatest-ja.tar.gzファイルを使っていないのはWordpressプラグインが正常にインストールできるかを確認するためにWP Multibyte Patchを手動インストールする手順を入れているためです)

$ cd /var/www/html/
$ ls
$ sudo curl -O https://wordpress.org/latest.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15.0M  100 15.0M    0     0  6978k      0  0:00:02  0:00:02 --:--:-- 6978k
$ ls
latest.tar.gz
$ sudo tar xfz latest.tar.gz
$ ls -l
total 15388
-rw-r--r--. 1 root   root   15750424 May 27 14:54 latest.tar.gz
drwxr-xr-x. 5 nobody nobody     4096 May 13 08:49 wordpress
$ sudo rm latest.tar.gz
$

WordPressディレクトリの所有者をWebサービスのユーザである「apache」に変更します。

$ ps -ef|grep http
root        7619       1  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7621    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7622    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7623    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7624    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7836    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
opc         7943    2643  0 14:55 pts/0    00:00:00 grep --color=auto http
$ sudo chown -R apache:apache wordpress/
$ ls -l
total 4
drwxr-xr-x. 5 apache apache 4096 May 13 08:49 wordpress
$

/var/www/html/wordpress をDocumentRootとするように ssl-mozilla.conf に追加して、httpdを再起動します。

$ sudo vi /etc/httpd/conf.d/ssl-mozilla.conf
$ cat /etc/httpd/conf.d/ssl-mozilla.conf
# generated 2021-05-27, Mozilla Guideline v5.6, Apache 2.4.37, OpenSSL 1.1.1g, intermediate configuration
# https://ssl-config.mozilla.org/#server=apache&version=2.4.37&config=intermediate&openssl=1.1.1g&guideline=5.6

# this configuration requires mod_ssl, mod_socache_shmcb, mod_rewrite, and mod_headers
<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<VirtualHost *:443>
    DocumentRoot /var/www/html/wordpress
    SSLEngine on

    # curl https://ssl-config.mozilla.org/ffdhe2048.txt >> /path/to/signed_cert_and_intermediate_certs_and_dhparams
    SSLCertificateFile      /etc/dehydrated/certs/<ホスト名>/cert.pem
    SSLCertificateKeyFile   /etc/dehydrated/certs/<ホスト名>/privkey.pem

    # enable HTTP/2, if available
    Protocols h2 http/1.1

    # HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
    Header always set Strict-Transport-Security "max-age=63072000"
</VirtualHost>

# intermediate configuration
SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite          ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder     off
SSLSessionTickets       off

SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
$ sudo systemctl restart httpd
$

手順8-2:「Service Unavailable」となる場合の対処

ブラウザからアクセスして「Service Unavailable」となる場合はphp-fpmのSELinux設定問題が発生しています。

httpd_execmemを有効にします。

$ getsebool httpd_execmem
httpd_execmem --> off
$ sudo setsebool -P httpd_execmem on
$ sudo getsebool httpd_execmem
httpd_execmem --> on
$

次に、php-fpm用のSELinux設定を作成します。まず「sudo ausearch -m AVC |grep php |audit2allow」を実行して「allow ~」の出力があることを確認

$ sudo ausearch -m AVC |grep php |audit2allow


#============= httpd_t ==============
allow httpd_t httpd_exec_t:file execmod;
$

次にこれを使ってSELinux用のモジュールを作成

$ sudo ausearch -m AVC |grep php |sudo audit2allow -M ph
p-fpm
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i php-fpm.pp

$ ls
php-fpm.pp  php-fpm.te  wordpress
$

モジュールとして組み込みphp-fpmを起動

$ sudo semodule -i php-fpm.pp
$ sudo systemctl start php-fpm
$ 

手順8-3: 「missing the MySQL extension」がでる場合の手順

php-fpmが正常に動作している状態でブラウザからアクセスすると、下記の表示になります。

これはphpからMySQLにアクセスするためのパッケージがインストールされていないためなので、php-mysqlndを追加して、httpdを再起動します。

$ sudo dnf install php-mysqlnd -y
Last metadata expiration check: 1:56:37 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package     Arch    Version                                Repository     Size
================================================================================
Installing:
 php-mysqlnd aarch64 7.4.6-4.module+el8.3.0+7685+72d70b58   ol8_appstream 182 k
Installing dependencies:
 php-pdo     aarch64 7.4.6-4.module+el8.3.0+7685+72d70b58   ol8_appstream 118 k

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 300 k
Installed size: 806 k
Downloading Packages:
<略>
$ sudo systemctl restart httpd
$

WordPressの設定手順を進めると wp-config.php に書き込めない、と出ますので、「sudo vi /var/www/html/wordpress/wp-config.php」を実行し、指定された内容を記載します。

手順9: SELinux設定

手順9-1: httpdのネットワーク接続問題

一見するとここまででうまく動いているように見えます。

しかし、プラグインをインストールしようとするとエラーになります。

/var/log/audit/audit.logを確認すると下記のようなログが出ています。

type=AVC msg=audit(1622095859.957:2064): avc:  denied  { name_connect } for  pid=8908 comm="php-fpm" dest=443 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0
type=AVC msg=audit(1622095868.397:2065): avc:  denied  { name_connect } for  pid=8313 comm="php-fpm" dest=443 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0
type=AVC msg=audit(1622095868.401:2066): avc:  denied  { name_connect } for  pid=8313 comm="php-fpm" dest=80 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0

これはhttpd_can_network_connect という値で制御されている

現在の設定値を「sudo getsebool -a |grep httpd_can_network」で確認し、「sudo setsebool -P httpd_can_network_connect on」で有効にする

$ sudo getsebool -a |grep httpd_can_network
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
$ sudo setsebool -P httpd_can_network_connect on
$ sudo getsebool -a |grep httpd_can_network
httpd_can_network_connect --> on
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
$

この変更ではhttpdの再起動は不要。

手順9-2: php-fpmの書き込み権限問題

プラグインやテーマのインストールについては問題なくても、WordPressのアップデートが出来ない。

このときの/var/log/audit/audit.logは下記

type=AVC msg=audit(1622101524.977:177): avc:  denied  { write } for  pid=2964 comm="php-fpm" name="wordpress" dev="dm-0" ino=101235463 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_sys_content_t:s0 tclass=dir permissive=0

こちらは/var/www/html/wordpress に対して httpdから書き込みが行えるような SELinuxのコンテキストをつけることで解決する。

「sudo chcon -R -t httpd_sys_script_rw_t /var/www/html/wordpress」

$ ls -lZ /var/www/html/
total 4
drwxr-xr-x. 5 apache apache unconfined_u:object_r:httpd_sys_content_t:s0 4096 May 27 15:02 wordpress
$ sudo chcon -R -t httpd_sys_script_rw_t /var/www/html/wordpress
$ ls -lZ /var/www/html/
total 4
drwxr-xr-x. 5 apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 4096 May 27 15:02 wordpress
$

手順9-3:Wordpressプラグイン追加の動作確認

WordPressプラグインがインストールできる状態になっているかを確認するために「WP Multibyte Patch」をインストールします。

これをインストールするとWordpressの設定画面([Settings]-[General])に「Site language(サイトの言語)」が追加され、「日本語」表示に切り替えることができるようになります。

手順10: WordPressで取り扱えるファイルサイズの拡大

WordPressで取り扱えるファイルは標準状態だと2MBになっている。

WordPressのドキュメントのFile Upload Sizes を見ると、これはphpの設定ファイル /etc/php.ini による制限となっている。

Oracle Linux 8の標準設定では下記の値となっている。

<略>
post_max_size = 8M
<略>
upload_max_filesize = 2M
<略>

で・・・よくある手順だと軽率に /etc/php.ini を書き換えていますが、 /etc/php.d/ 以下にファイルを追加することで、そちらの設定項目を優先させることができる機能があるため、 /etc/php.d/90-wordpress.ini に変更したい2行だけを記載したファイルを作成します。

$ sudo vi /etc/php.d/90-wordpress.ini
$ cat /etc/php.d/90-wordpress.ini
post_max_size = 100M
upload_max_filesize = 100M
$

phpの設定変更を反映させるために「sudo systemctl restart php-fpm」を実行します。

手順11: WordPressのSite Health Status対応

WordPressのサイトステータスを見てみると、いくつかパッケージを要求されている。

ImageMagickに関するphpモジュールは含まれていない

$ dnf search magick
Last metadata expiration check: 2:56:09 ago on Thu 27 May 2021 01:10:22 PM JST.
======================== Name & Summary Matched: magick ========================
GraphicsMagick.aarch64 : An ImageMagick fork, offering faster image generation
                       : and better quality
GraphicsMagick.src : An ImageMagick fork, offering faster image generation and
                   : better quality
GraphicsMagick-c++.aarch64 : GraphicsMagick Magick++ library (C++ bindings)
GraphicsMagick-c++-devel.aarch64 : C++ bindings for the GraphicsMagick library
GraphicsMagick-debugsource.aarch64 : Debug sources for package GraphicsMagick
GraphicsMagick-devel.aarch64 : Libraries and header files for GraphicsMagick app
                             : development
GraphicsMagick-doc.noarch : GraphicsMagick documentation
GraphicsMagick-perl.aarch64 : GraphicsMagick perl bindings
ImageMagick-c++.aarch64 : ImageMagick Magick++ library (C++ bindings)
ImageMagick-c++-devel.aarch64 : C++ bindings for the ImageMagick library
ImageMagick-devel.aarch64 : Library links and header files for ImageMagick app
                          : development
ImageMagick-doc.aarch64 : ImageMagick html documentation
ImageMagick-libs.aarch64 : ImageMagick libraries to link with
ImageMagick-perl.aarch64 : ImageMagick perl bindings
============================= Name Matched: magick =============================
ImageMagick.aarch64 : An X application for displaying and manipulating images
ImageMagick.src : An X application for displaying and manipulating images
=========================== Summary Matched: magick ============================
converseen.aarch64 : A batch image conversion tool written in C++ with Qt5 and
                   : Magick++
converseen.src : A batch image conversion tool written in C++ with Qt5 and
               : Magick++
$

zipとgdはそれっぽいものがあるので「sudo dnf install php-pecl-zip php-gd -y」で追加

$ sudo dnf install php-pecl-zip php-gd -y
Last metadata expiration check: 3:04:44 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package      Arch    Version                               Repository     Size
================================================================================
Installing:
 php-gd       aarch64 7.4.6-4.module+el8.3.0+7685+72d70b58  ol8_appstream  83 k
 php-pecl-zip aarch64 1.18.2-1.module+el8.3.0+7685+72d70b58 ol8_appstream  53 k
Installing dependencies:
 gd           aarch64 2.2.5-7.el8                           ol8_appstream 134 k
 jbigkit-libs aarch64 2.1-14.el8                            ol8_appstream  54 k
 libXpm       aarch64 3.5.12-8.el8                          ol8_appstream  56 k
 libjpeg-turbo
              aarch64 1.5.3-10.el8                          ol8_appstream 145 k
 libtiff      aarch64 4.0.9-18.el8                          ol8_appstream 178 k
 libwebp      aarch64 1.0.0-1.el8                           ol8_appstream 246 k
 libzip       aarch64 1.6.1-1.module+el8.3.0+7685+72d70b58  ol8_appstream  62 k

Transaction Summary
================================================================================
Install  9 Packages

Total download size: 1.0 M
Installed size: 3.0 M
Downloading Packages:
<略>
$

こちらは再起動は不要なようで、すぐにSite Healthの状態に反映され、imagickモジュールに関するメッセージのみになった。

2022/04/06追記: wordpress 5.9.3では推奨phpプラグインに「php-intl」が追加されたので「sudo dnf install php-intl」で追加する

$ sudo dnf install php-intl
This system is receiving updates from OSMS server.
Last metadata expiration check: 0:09:17 ago on Wed 06 Apr 2022 01:29:10 PM JST.
Dependencies resolved.
================================================================================
 Package
     Arch    Version                                Repository             Size
================================================================================
Installing:
 php-intl
     aarch64 7.4.19-1.module+el8.5.0+20354+db97279a ol8_appstream-aarch64 182 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 182 k
Installed size: 522 k
Is this ok [y/N]: y
Downloading Packages:
php-intl-7.4.19-1.module+el8.5.0+20354+db97279a 2.0 MB/s | 182 kB     00:00
--------------------------------------------------------------------------------
Total                                           1.9 MB/s | 182 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : php-intl-7.4.19-1.module+el8.5.0+20354+db97279a.aarc   1/1
  Running scriptlet: php-intl-7.4.19-1.module+el8.5.0+20354+db97279a.aarc   1/1
  Verifying        : php-intl-7.4.19-1.module+el8.5.0+20354+db97279a.aarc   1/1

Installed:
  php-intl-7.4.19-1.module+el8.5.0+20354+db97279a.aarch64

Complete!
$

手順12: WordPressの.htaccess有効化

/var/www/html/wordpress/.htaccess が作成されているが、Oracle Linux 8のhttpd標準設定ではこれを読み込むようにはなっていない。

これが有効になっていないと、パーマリンク設定を「基本」から変えた場合に個別記事にアクセスできなくなる。

/etc/httpd/conf.d/wordpress.conf にファイルを作って設定する。

$ sudo vi /etc/httpd/conf.d/wordpress.conf
$ cat /etc/httpd/conf.d/wordpress.conf
<Directory /var/www/html/wordpress/>
 Allowoverride All
</Directory>
$ sudo systemctl restart httpd
$

手順13: OS自動更新の設定

メンテナンスがめんどくさくなって忘れる可能性があるので、Oracle Linux 8の自動更新設定を実施。

以前はyum-cronでしたが、現在は dnf-automatic に変わったので、パッケージをインストールします。

$ sudo dnf install dnf-automatic -y
Last metadata expiration check: 0:21:33 ago on Wed 02 Jun 2021 05:00:20 PM JST.
Dependencies resolved.
================================================================================
 Package            Arch        Version            Repository              Size
================================================================================
Installing:
 dnf-automatic      noarch      4.4.2-11.el8       ol8_baseos_latest      148 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 148 k
Installed size: 51 k
Downloading Packages:
<略>
$

/etc/dnf/automatic.conf 内の「apply_updates = no」を「apply_updates = yes」に変更

$ sudo vi /etc/dnf/automatic.conf
$ cat /etc/dnf/automatic.conf
[commands]
#  What kind of upgrade to perform:
# default                            = all available upgrades
# security                           = only the security upgrades
upgrade_type = default
random_sleep = 0

# Maximum time in seconds to wait until the system is on-line and able to
# connect to remote repositories.
network_online_timeout = 60

# To just receive updates use dnf-automatic-notifyonly.timer

# 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

# 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


[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 = stdio


[email]
# The address to send email messages from.
email_from = root@example.com

# List of addresses to send messages to.
email_to = root

# Name of the host to connect to to send email messages.
email_host = localhost


[command]
# The shell command to execute. This is a Python format string, as used in
# str.format(). The format function will pass a shell-quoted argument called
# `body`.
# command_format = "cat"

# The contents of stdin to pass to the command. It is a format string with the
# same arguments as `command_format`.
# stdin_format = "{body}"


[command_email]
# The shell command to use to send email. This is a Python format string,
# as used in str.format(). The format function will pass shell-quoted arguments
# called body, subject, email_from, email_to.
# command_format = "mail -Ssendwait -s {subject} -r {email_from} {email_to}"

# The contents of stdin to pass to the command. It is a format string with the
# same arguments as `command_format`.
# stdin_format = "{body}"

# The address to send email messages from.
email_from = root@example.com

# List of addresses to send messages to.
email_to = root


[base]
# This section overrides dnf.conf

# Use this to filter DNF core messages
debuglevel = 1
$

そしてdnf-automatic.timerを有効化し、開始します。

$ sudo systemctl enable dnf-automatic.timer
Created symlink /etc/systemd/system/timers.target.wants/dnf-automatic.timer → /usr/lib/systemd/system/dnf-automatic.timer.
$ sudo systemctl status dnf-automatic
● dnf-automatic.service - dnf automatic
   Loaded: loaded (/usr/lib/systemd/system/dnf-automatic.service; static; vendo>
   Active: inactive (dead)
$ sudo systemctl start dnf-automatic.timer
$ sudo systemctl status dnf-automatic.timer
● dnf-automatic.timer - dnf-automatic timer
   Loaded: loaded (/usr/lib/systemd/system/dnf-automatic.timer; enabled; vendor>
   Active: active (waiting) since Wed 2021-06-02 17:26:38 JST; 2s ago
  Trigger: Thu 2021-06-03 06:07:23 JST; 12h left

Jun 02 17:26:38 ホスト名 systemd[1]: Started dnf-automatic timer.
$

なお、dnf automaticでアップデートされた場合に、通知メールを送るようにする場合は、「Oracle Cloud上のインスタンスから管理メールを送信する手法」を参照のこと。