7系からは NTP サービスとして chorny が標準で起動しています。
AWS 環境での NTP 設定を chrony で行う際は、参照先サーバをAmazon Time Sync Serviceにしたほうが親和性が良いので、変更する手順について記載。
オリジナルの保全
cp /etc/chrony.conf /etc/chrony.conf.org
設定ファイルの編集
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
追加・修正
server 169.254.169.123 prefer iburst
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
コマンドで実行する場合
sed -e "3i server 169.254.169.123 prefer iburst" /etc/chrony.conf -i
sed -e "s/server 0.centos.pool.ntp.org iburst/^#server 0.centos.pool.ntp.org iburst/g" /etc/chrony.conf -i
sed -e "s/server 1.centos.pool.ntp.org iburst/^#server 1.centos.pool.ntp.org iburst/g" /etc/chrony.conf -i
sed -e "s/server 2.centos.pool.ntp.org iburst/^#server 2.centos.pool.ntp.org iburst/g" /etc/chrony.conf -i
sed -e "s/server 3.centos.pool.ntp.org iburst/^#server 3.centos.pool.ntp.org iburst/g" /etc/chrony.conf -i
変更差異の確認
diff /etc/chrony.conf /etc/chrony.conf.org
実行結果
# 3,8c3,6
# < server 169.254.169.123 prefer iburst
#
# < #server 0.centos.pool.ntp.org iburst
# < #server 1.centos.pool.ntp.org iburst
# < #server 2.centos.pool.ntp.org iburst
# < #server 3.centos.pool.ntp.org iburst
# < # --- # > server 0.centos.pool.ntp.org iburst
# > server 1.centos.pool.ntp.org iburst
# > server 2.centos.pool.ntp.org iburst
# > server 3.centos.pool.ntp.org iburst
設定の反映
service chronyd restart
状態の確認
chronyc sources -v
実行結果
# 210 Number of sources = 1
#
# .-- Source mode '^' = server, '=' = peer, '#' = local clock.
# / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
# | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
# || .- xxxx [ yyyy ] +/- zzzz
# || Reachability register (octal) -. | xxxx = adjusted offset,
# || Log2(Polling interval) --. | | yyyy = measured offset,
# || \ | | zzzz = estimated error.
# || | | \
# MS Name/IP address Stratum Poll Reach LastRx Last sample
# ===============================================================================
# ^* 169.254.169.123 3 6 17 62 +2155ns[ -54us] +/- 1551us
#--------------------------------------------------