Amazon Linux に Chrony で Amazon Time Sync Service の NTP サーバを参照させる
AWS から VPC の中からリンクローカル IP アドレスで参照出来る NTP サーバが提供されました。 設定方法等は Amazon Time Sync Service で時間を維持する で詳しく説明されています。 今回はこの記事に従って、Amazon Linux へ実際に Amazon Time Sync Service の NTP サーバを設定してみます。
デフォルトの状態¶
現状、Amazon Linux をインストールすると(chronyd では無く)ntpd がインストールされます。
chronyd をインストールする¶
Amazon Time Sync Service を使う上で必須では無いと思いますが、ntpd よりも速く正確に時刻同期させることが出来る chronyd へ差し替えることにします。 ntpd をアンインストールした後、Amazon Linux の標準リポジトリから chronyd をインストールし、起動&自動起動設定まで実施します。
Amazon Time Sync Service の NTP サーバは 169.254.169.123 というアドレスで参照することが可能です。 Amazon Linux の標準リポジトリから chronyd をインストールすると、デフォルトでこのサーバを優先的に参照するよう、設定されていました。
これで Amazon Time Sync Service の設定は完了です。
時刻同期状態を確認する¶
時刻の同期状態を確認するには chronyc sources を使います。
# chronyc sources
210 Number of sources = 5
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 169.254.169.123 3 6 77 47 -2841ns[ -62us] +/- 418us
^- ns1.backplanedns.org 2 6 77 47 -1281us[-1340us] +/- 72ms
^- 2.time.dbsinet.com 2 6 77 48 -5113us[-5171us] +/- 58ms
^- 12.167.151.1 2 6 77 48 +1043us[ +985us] +/- 29ms
^- mail.coldnorthadmin.com 2 6 77 46 +8170us[+8170us] +/- 68ms
同期している NTP サーバのトラッキング情報を見るには chronyc tracking を使います。
# chronyc tracking
Reference ID : A9FEA97B (169.254.169.123)
Stratum : 4
Ref time (UTC) : Thu Nov 30 13:48:31 2017
System time : 0.000003592 seconds fast of NTP time
Last offset : +0.000001651 seconds
RMS offset : 0.000036398 seconds
Frequency : 39.733 ppm fast
Residual freq : +0.001 ppm
Skew : 0.109 ppm
Root delay : 0.000532688 seconds
Root dispersion : 0.000134502 seconds
Update interval : 64.4 seconds
Leap status : Normal
参考¶
/etc/chrony.conf¶
# use the local instance NTP service, if available
server 169.254.169.123 prefer iburst
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.amazon.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 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
# save data between restarts for fast re-load
dumponexit
dumpdir /var/run/chrony