【CentOS】Chrony で時刻同期したりさせたりする
インストールされているか確認
code:console
% which chronyc chronyd
/usr/bin/chronyc
/usr/sbin/chronyd
% echo $?
0
設定ファイル編集
code:console
# cp -a /etc/chrony.conf /etc/chrony.conf.org
# vi /etc/chrony.conf
% diff -du /etc/chrony.conf.org /etc/chrony.conf
--- /etc/chrony.conf.org 2021-06-24 14:21:14.000000000 +0000
+++ /etc/chrony.conf 2021-12-14 01:34:45.026289500 +0000
@@ -1,6 +1,7 @@
# Use public servers from the pool.ntp.org project.
-pool 2.centos.pool.ntp.org iburst
+#pool 2.centos.pool.ntp.org iburst
+server 192.168.100.61
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
@@ -21,6 +22,7 @@
# Allow NTP client access from local network.
+allow 172.16.100.0/24
# Serve time even if not synchronized to a time source.
設定の適用
code:console
# systemctl restart chronyd
% chronyc sources # まだ同期できていない
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^? dhcp.tohoku-pc.ac.jp 2 6 1 25 -2155us-2155us +/- 9880us % chronyc sources # 同期がとれた
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* dhcp.tohoku-pc.ac.jp 2 6 7 7 -89us-2358us +/- 12ms 起動の確認
code:console
# systemctl status chronyd
NTP は UDP の 123 番ポートで listen している。
code:console
% ss -lun 'sport == :ntp'
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:123 0.0.0.0:*
firewalld の設定
忘れがち。 zone の指定を付け足すこと。
code:console
# firewall-cmd --permanent --add-service=ntp --zone=internal
# firewall-cmd --reload
おわりに
時刻情報が滅茶苦茶だと tar(1) とか make(1) とかで混乱するから気を付けよう。