前回の記事で ConoHa の VPS に RHEL9 をインストールする手順を説明しましたが、今回はこれに基本的な設定を施していきます。

SELinux の無効化
当初の予定では SELinux を有効にしたまま運用する気だったのだが、いきなり SELinux 絡みでトラブルが発生して時間を費やす羽目になった。やはり無効にして運用する事にします。
まずは現状の SELinux の状態を確認すると、有効(Enforcing)になっている。
getenforce
(out) EnforcingSELinux を無効にして、システムを再起動する。
grubby --update-kernel ALL --args selinux=0
reboot再起動後に無効(Disabled)になっていることを確認。
getenforce
(out) Disabled管理者の設定
ユーザーを wheel グループに追加
セットアップの際にユーザーを作成したが、そのとき「このユーザーを管理者にする」にチェックを入れておいたので、反映されているか確認する。
id ユーザー名
(out) uid=1000(ユーザー名) gid=1000(ユーザー名) groups=1000(ユーザー名),10(wheel)wheel グループに追加されていることが確認できた。
wheel グループに追加されていない場合は、下記コマンドで追加する。
usermod -G wheel ユーザー名su コマンドを実行できるユーザーを制限
/etc/pam.d/su の以下の行のコメントアウトを外す。
#auth required pam_wheel.so use_uid
↓
auth required pam_wheel.so use_uidこれで、root になれるユーザーが管理者のみになりました。
時刻合わせの設定
chrony で時刻合わせの設定をしていきます。
vi /etc/chrony.confchrony の設定ファイルを開き、時刻同期先の NTP サーバーを国内のものに変更します。
#pool 2.centos.pool.ntp.org iburst
server ntp.nict.jp iburst
pool ntp.jst.mfeed.ad.jp iburst時刻が大きくずれていると chrony が起動できないので、先に手動で時刻を合わせます。
chronyc makestep
(out) 200 OKchronyd の設定反映と、起動時に自動実行をさせます。
systemctl restart chronyd
systemctl enable chronydしばらく経ってから同期の確認をしてみます。
chronyc sources
(out) MS Name/IP address Stratum Poll Reach LastRx Last sample
(out) ===============================================================================
(out) ^* ntp-b2.nict.go.jp 1 10 377 769 -30us[ -105us] +/- 735us
(out) ^- ntp2.jst.mfeed.ad.jp 2 9 377 257 -1257us[-1257us] +/- 51ms
(out) ^- ntp3.jst.mfeed.ad.jp 2 9 377 325 -395us[ -395us] +/- 80ms
(out) ^- ntp1.jst.mfeed.ad.jp 2 10 377 962 -687us[ -762us] +/- 62ms頭に「^* 」が付いているサーバーと同期中です。「^+ 」となっていれば同期対象候補で、「^- 」は同期対象から外れているサーバーです。
kdump の無効化
メモリを常時消費するため無効化する。
systemctl stop kdump.service
systemctl disable kdump.service
(out) Removed /etc/systemd/system/multi-user.target.wants/kdump.service.
(out)
sysctl -a | grep kernel.kptr_restrict
(out) kernel.kptr_restrict = 1※ kernel.kptr_restrict の値が 1 であることを確認。
Syslog 用のローテーション設定
Syslog 用のログローテーション設定ファイルをインストールします。
dnf install rsyslog-logrotateパッケージを自動更新
CentOS 7 までは yum-cron を使って、パッケージを自動的に最新の状態に保っていました。RHEL 8 以降では dnf-automatic を使って行います。
まずは dnf-automatic のインストール。
dnf install dnf-automaticdnf-automatic の設定を変更していきます。
vi /etc/dnf/automatic.conf更新ファイルのチェックだけではなく、実際にアップデートを実行するようにします。
#apply_updates = no
apply_updates = yes定期実行を有効にして、毎日更新してもらうようにします。
systemctl enable dnf-automatic.timer
(out) Created symlink /etc/systemd/system/timers.target.wants/dnf-automatic.timer → /usr/lib/systemd/system/dnf-automatic.timer.念のため、何時に実行されるか確認しておきましょう。
systemctl edit --full dnf-automatic.timer[Unit]
Description=dnf-automatic timer
# See comment in dnf-makecache.service
ConditionPathExists=!/run/ostree-booted
Wants=network-online.target
[Timer]
OnCalendar=*-*-* 6:00
RandomizedDelaySec=60m
Persistent=true
[Install]
WantedBy=timers.target毎日 6:00 ~ 7:00 のランダムな時間に実行される様です。問題ないのでこのまま使用します。
automatic.conf の emit_via を stdio(デフォルト)から command_email に変更すると、更新内容をメールで通知するようになります。
メールサーバーの設定ができたら、必要に応じて変更すると良いでしょう。
FastestMirror の設定
遅いミラーリポジトリに接続するとインストールに時間がかかる場合があるので、FastestMirror を有効化する。
vi /etc/dnf/dnf.conf[main] ブロックの最後に fastestmirror=True を追加する。
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
fastestmirror=Trueサードパーティーリポジトリの追加
EPEL リポジトリ
追加パッケージのインストールに必要な、EPEL(Extra Packages for Enterprise Linux)リポジトリを追加する。
subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms
(out) リポジトリー 'codeready-builder-for-rhel-9-x86_64-rpms' は、このシステムに対して有効になりました。
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpmCRB(CodeReady Builder)リポジトリを有効にしてから、elep-release をインストールします。
dnf config-manager --set-enabled crb
dnf install epel-release epel-next-releaseRemi リポジトリ
PHP の最新バージョンなどが揃っている Remi リポジトリを追加します。RHEL9 の標準は PHP8.0 ですが、最新の PHP8.3 や、互換性重視の PHP7.4 を導入したい場合は必要になります。
dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf config-manager --set-enabled remi利用可能なバージョンを確認します。
dnf module list phpリセットしてから有効なバージョンを切り替えます。
dnf module reset php
dnf module install php:remi-8.3必要なパッケージのインストール
Wget のインストール
ファイルをダウンロードするのに必要な wget をインストールします。
dnf install wgetGit のインストール
同じく GitHub などからファイルをダウンロードする際に必要な git をインストールします。
dnf install gitBash Completion のインストール
各種コマンドで入力補完できるように bash-completion をインストールします。
dnf install bash-completionRHEL9 は base リポジトリからインストールできました。
一度ログアウトしてから、再度ログインすると Tab 補完が効くようになります。
SL のインストール
焦っているときに落ち着きを取り戻させてくれる SL コマンドをインストールします。
dnf install slEPEL からインストールされますので、初めての場合は GPG 鍵のインポートを確認されます。
GPG 鍵 0x3228467C をインポート中:
Userid : "Fedora (epel9) <epel@fedoraproject.org>"
Fingerprint: FF8A D134 4597 106E CE81 3B91 8A38 72BF 3228 467C
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9
これでよろしいですか? [y/N]: y
鍵のインポートに成功しましたインストールできたら、試しにコマンドを実行してみます。
sl
落ち着いたら、ファイアウォールの設定をしていきましょう。

コメント