Amazon Linux AMI 2018.03ではデフォルトでAmazon Time Sync Serviceが使えます!

AWSが提供するマネージドのNTP(時刻同期)サービスAmazon Time Sync Serviceが、最新バージョンのAmazon Linux AMIである2018.03ではデフォルト状態で利用可能になっていることを確認しました。
2018.05.29

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

はじめに

清水です。現時点(2018/05/29)で最新版のAmazon Linux AMIである2018.03ではデフォルトの状態でAmazon Time Sync Serviceが利用できます。本エントリではこの点を実際に確認してみたのでまとめてみます。

Amazon Time Sync Service

まずはAmazo Time Sync Serviceについて簡単に振り返ります。re:Invent2017の期間中(2017年11月末)に発表された新たなサービスのひとつで、AWSが提供するマネージドのNTP(時刻同期)サービスです。VPC内のリンクローカルアドレス(169.254.169.123)で提供されインターネット通信を介さずに時刻同期ができること、また各リージョンで冗長化している衛星接続の原子時計を使っての高度な時刻参照などのメリットがあります。

【速報】マネージドNTP Amazon Time Sync Serviceが登場 #reinvent

マネージドNTPのAmazon Time Sync Serviceが便利な理由

従来のAmazon LinuxからのAmazon Time Sync Serviceの使い方

このAmazon Time Sync Serviceを使う方法ですが、例えば以下の方法が紹介されています。

抜粋しますと、

  • インストールされているntpdをアンインストールしてchronyをインストール(任意)
  • NTPで参照するサーバを169.254.169.123に変更

という具合で、(推奨されているchronyをインストールしなくても)参照先サーバの変更が必要でした。

なお、現在RC版であるAmazon Linux 2ではこの設定ははじめから施されたおり、提供されているAMIから起動するだけでAmazo Time Sync Serviceが(chronydにより)利用可能です。

Amazon Linux 2はNTPにChronyとAmazon Time Sync Serviceを使う

今後Amazon Linux 2が正式リリースされればこちらが標準で利用できますが、Amazon Linux(1のほう)で設定しないと使えないのは少し歯がゆいな…などと思っていました。

そんな折、Amazon Linux AMI 2018.03がリリースされました。その前のAmazon Linux AMIは2017.09でリリース時期などからAmazon Time Sync Serviceへの対応は難しいかと思いますが、2018.03ならAmazon Time Sync Serviceに対応しているのでは?ということで確認してみました。

Amazon Linux AMI 2018.03でAmazon Time Sync Serviceが利用できていることの確認

マネージメントコンソールから東京リージョンのAmazon Linux AMI 2018.03を起動してみます。

sshで接続して、NTPの同期先を確認してみます。ntpqコマンドの出力で*マークを確認すると、同期しているサーバが「169.254.169.123」であり、Amazon Time Sync Serviceを使用していることがわかりますね!(他にも+マークの同期可能なサーバはありますが。)

[ec2-user@ip-10-82-21-187 ~]$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*169.254.169.123 10.66.1.102      3 u   20   64  377    0.269    3.450   1.913
+cbr-jp-1.dn42.e 133.243.238.163  2 u   35   64  377    2.614    3.483   1.967
+sv1.localdomain 133.243.238.164  2 u   34   64  377    2.168    3.191   1.921
+34nm.com        78.73.83.84      2 u    6   64  377    1.622    3.190   1.389
+104.131.155.175 171.66.97.126    2 u    4   64  377  111.007    2.072   1.532

続いて、設定ファイル/etc/ntpd.confについても確認してみます。server 169.254.169.123 prefer iburst minpoll 3にて、Amazon Time Sync Serviceが設定されていることがわかります。他のPublic server指定もありますがAmazon Time Sync Serviceがpreferで優先接続先とされていますね。

[ec2-user@ip-10-82-21-187 ~]$ cat /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use and prefer the Amazon Time Service server
server 169.254.169.123 prefer iburst minpoll 3

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.amazon.pool.ntp.org iburst
server 1.amazon.pool.ntp.org iburst
server 2.amazon.pool.ntp.org iburst
server 3.amazon.pool.ntp.org iburst

#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 autokey            # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# 以下割愛 #

Amazon Linux AMI 2017.09をアップデートした場合にAmazon Time Sync Serviceが利用できていることの確認

続いて、一つ前の世代のAmazon Linux AMIである2017.09でパッケージをアップデートした場合に、Amazon Time Sycn Serviceが利用できることを確認してみます。Amazon Linux AMI はローリング・リリースを採用しています。パッケージアップデート後、インスタンスをリブートすることで最新版に更新できます。更新後にAmazon Time Sync Serviceは利用できるのでしょうか。

2017.09のAMI「ami-a77c30c1」(東京リージョン)を起動します。

sshで接続して、ntpqコマンドで現在の時刻同期設定を確認してみます。2017.09なので当然ながらAmazon Time Sycn Serviceの「169.254.169.123」とは同期していません。

[ec2-user@ip-10-82-21-250 ~]$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+66.241.101.63   193.190.230.65   2 u   33   64  377  131.245   -1.085   0.556
-pacific.latt.ne 44.24.199.34     3 u   20   64  377  110.104    0.323   0.425
*nipper.paina.ne 131.113.192.40   2 u   18   64  377    1.771   -0.448   0.485
+date.no-such-ag 103.1.106.69     2 u   60   64  377    1.476   -0.761   0.427

設定ファイル/etc/ntp.confも確認してみますが、Amazon Time Sync Serviceと思しき箇所は見つかりませんね。

[ec2-user@ip-10-82-21-250 ~]$ cat /etc/ntp.conf  | grep 123
[ec2-user@ip-10-82-21-250 ~]$ cat /etc/ntp.conf  | grep server
# Use public servers from the pool.ntp.org project.
server 0.amazon.pool.ntp.org iburst
server 1.amazon.pool.ntp.org iburst
server 2.amazon.pool.ntp.org iburst
server 3.amazon.pool.ntp.org iburst
#broadcast 192.168.1.255 autokey        # broadcast server
#broadcast 224.0.1.1 autokey            # multicast server
#manycastserver 239.255.254.254         # manycast server

それでは、sudo yum updateコマンドでAmazon Linux 2018.03後にアップデートしたあとはどうでしょうか。再起動後にntpqコマンドで同期状況を確認してみると、Amazon Time Sync Serviceと同期していました!

[ec2-user@ip-10-82-21-250 ~]$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*169.254.169.123 10.66.1.102      3 u   58   64  377    0.212    0.015   0.013
 2.amazon.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
+122x215x240x52. 103.1.106.69     2 u    5   64  377    1.911    0.008   0.056
-jiro.paina.net  131.113.192.40   2 u   25  128  177   18.341   -1.298   3.192
+s97.GchibaFL4.v 133.243.238.244  2 u    2   64  377    5.078   -0.093   0.215

また/etc/ntpd.confを、アップデート前に別名で保存しておいたもの(/etc/ntp.conf.201709original)と比較してみました。server 169.254.169.123 prefer iburst minpoll 3が追加されていることがわかります。

[ec2-user@ip-10-82-21-250 ~]$ diff /etc/ntp.conf /etc/ntp.conf.201709original
1c1,2
< # For more information about this file, see the ntp.conf(5) man page.
---
> # For more information about this file, see the man pages
> # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
3d3
< # Record the frequency of the system clock.
8,11c8
< restrict default nomodify notrap nopeer noepeer noquery
<
< # Permit association with pool servers.
< restrict source nomodify notrap noepeer noquery
---
> restrict default nomodify notrap nopeer noquery
22,24d18
< # Use and prefer the Amazon Time Service server
< server 169.254.169.123 prefer iburst minpoll 3
<
27,30c21,31
< pool 2.amazon.pool.ntp.org iburst
<
< # Reduce the maximum number of servers used from the pool.
< tos maxclock 5
---
> server 0.amazon.pool.ntp.org iburst
> server 1.amazon.pool.ntp.org iburst
> server 2.amazon.pool.ntp.org iburst
> server 3.amazon.pool.ntp.org iburst
>
> #broadcast 192.168.1.255 autokey      # broadcast server
> #broadcastclient                      # broadcast client
> #broadcast 224.0.1.1 autokey          # multicast server
> #multicastclient 224.0.1.1            # multicast client
> #manycastserver 239.255.254.254               # manycast server
> #manycastclient 239.255.254.254 autokey # manycast client

ということで、一つ前の世代のAmazon Linux AMIである2017.09を2018.03にアップデートした状態でもAmazon Time Sync Serviceが利用できていることが確認できました。

まとめ

AWSが提供するマネージドのNTP(時刻同期)サービスAmazon Time Sync Serviceが、最新バージョンのAmazon Linux AMIである2018.03ならデフォルトの状態で利用可能になっていること、また一つ前のバージョン2017.09をアップデートした状態でもデフォルト状態で利用可能になっていることを確認しました。パワフルなマネージドサービスがデフォルトで利用可能になっていることは大変ありがたいですね!とはいえきちんとntpサーバと同期ができているか、などは要所々々で確認しましょう。