はじめに
次回の案件でRockyLinuxを使用することから備忘録として残します。
古いRHEL互換しか触ってこなかったためコマンド等に誤りがありましたらコメントでご指摘いただけると幸いです…
今回は実行結果まで含めて、できるだけ丁寧に実践していきます。
環境
・Proxmox VE 9.1 上で構築
・RockyLinux v8.10(サーバ側 192.168.0.92/24 )
・RockyLinux v8.10(クライアント側 192.168.0.90/24 )

別の記事でNFS、syslogサーバについても記述予定なので今回使用しない VM も記載されています。
サーバ側の構築
サーバ側の構築
SE Linuxについては割愛。私は Disable の状態で開始しました。
0. 事前確認
事前確認として下記でNTPが動いている確認。デフォルトであれば起動時から動いているはず。
STOPになっていたらstartしていただいて問題ないです。
# systemctl status chronyd
1. /etc/chrony.confの退避
まずは /etc/chrony.conf の退避。
その後 /etc/chrony.conf の編集を行う。
# cp /etc/chrony.conf /etc/chrony.conf.org
# ls -l /etc/ | grep chrony.conf
-rw-r--r--. 1 root root 1084 Nov 5 2024 chrony.conf
-rw-r--r-- 1 root root 1084 Mar 4 08:55 chrony.conf.org
2. /etc/chrony.confの編集
NTPサーバに必要な設定値を入力していきます。
# vi /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# pool 2.rocky.pool.ntp.org iburst
↑をコメントアウト
有効のままだと、RHEL系向けのNTPプールサーバに同期する設定。今回はなしで。
# Allow NTP client access from local network.
# allow 192.168.0.0/16
allow 192.168.0.0/24
↑ここに環境に合わせたネットワークアドレスを追記。
# Serve time even if not synchronized to a time source.
#local stratum 10
local stratum 10
↑ 上記を追記。local stratum 10 は、
外部NTPと同期できない場合に自サーバを擬似的な時刻源として動作させる設定。
今回は閉鎖的な環境で実践しているため10で設定。
Stratumは数字が小さいほど上位で信頼度が高い。
↓設定比較のため全体文記載してます。
設定値全体(デフォルト)
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.rocky.pool.ntp.org iburst
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3
# Enable kernel synchronization of the real-time clock (RTC).
rtcsync
# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *
# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2
# Allow NTP client access from local network.
#allow 192.168.0.0/16
# Serve time even if not synchronized to a time source.
#local stratum 10
# Specify file containing keys for NTP authentication.
keyfile /etc/chrony.keys
# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC
# Specify directory for log files.
logdir /var/log/chrony
# Select which information is logged.
#log measurements statistics tracking
設定値全体(編集後)
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# pool 2.rocky.pool.ntp.org iburst
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3
# Enable kernel synchronization of the real-time clock (RTC).
rtcsync
# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *
# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2
# Allow NTP client access from local network.
allow 192.168.0.0/16
# Serve time even if not synchronized to a time source.
#local stratum 10
local stratum 10
# Specify file containing keys for NTP authentication.
keyfile /etc/chrony.keys
# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC
# Specify directory for log files.
logdir /var/log/chrony
# Select which information is logged.
#log measurements statistics tracking
3. firewallの設定
# firewall-cmd --add-service=ntp --permanent
# firewall-cmd --reload
# firewall-cmd --list-all | grep ntp
services: cockpit dhcpv6-client ntp ssh
3. chronydのサービス開始
設定を反映させるために chronyd(NTP) を restart させます。
ここまででサーバ側の設定は完了になります。
# systemctl restart chronyd
クライアント側の構築
クライアント側の構築
0. 事前確認
サーバ側と同様に、デフォルトでstartになっているはず。
STOPになっていたらstartしていただいて問題ないです。
# systemctl status chronyd
1. /etc/chrony.conf の編集
# systemctl status chronyd
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# pool 2.rhel.pool.ntp.org iburst
server 192.168.0.92 iburst
↑デフォルトの設定をコメントアウトし、上記を追記。
iburstの意味はNTPサーバへ初回同期時に高速で複数回リクエストを送るオプション。
通常はゆっくり間隔をあけて問い合わせるが、
iburst を付けると起動直後に短時間で連続問い合わせを行い、時刻を素早く安定させる。
2. chronyd 設定反映
クライアント側の設定を反映させるためにサービスを再起動します。
# systemctl restart chronyd
3. NTPサーバに同期できているか確認!
# chronyc sources
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.0.92 3 6 377 57 -9088ns[ -10us] +/- 5767us
「^*」がついているので同期できていますね!
最後に
NTPサーバは意外と重要なことを新人の頃知りました。
少し未来に生きていたり、過去にいきていたりする機体からsyslogを送られるてくると、障害発生時に追えないこともないですが混乱するのは目に見えています。
初歩的なところではありますが忘れることも多々。
業務で触る機会も少ないですし、たまには思い出して復習していかなくてはいけないですね。