NTP とは Network Time Protocol の略で、ネットワーク上でクライアントがサーバーに対して時刻を問い合わせるためのプロトコルです。
Ubuntuサーバーエディションでは標準ではインストールされていませんので、インストールします。
# apt-get install ntp
設定
NTP の設定ファイルは NTP をインストールしたときに作成されますが、時刻を同期するサーバーを近いサーバーに変更します。
/etc/ntp.confを開いて、以下のように編集します。
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# You do need to talk to an NTP server or two (or three).
server ntp.nict.jp
server ntp.jst.mfeed.ad.jpserver ntp.ubuntu.com
編集して保存したら、NTPを再起動します。
# /etc/init.d/ntp restart
以下のように実行することで NTP サーバーの動作確認を行うことができます。
ntpq コマンドに -p オプションをつけて実行すると NTP サーバーの同期状態が表示されます。
remote refid st t when poll reach delay offset jitter
==============================================================================
ntp-b2.nict.go. .NICT. 1 u 41 64 3 24.737 -3.997 4.855
ntp1.jst.mfeed. 210.173.176.4 2 u 39 64 3 21.113 -2.546 3.112
europium.canoni 193.79.237.14 2 u 40 64 3 265.788 -6.268 4.657
NTP サーバーを起動した直後は上記ような結果になりますが、10 分ほど経過して同期が始まると以下のように表示されます。
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp-b2.nict.go. .NICT. 1 u 61 64 77 23.670 -13.238 8.813
+ntp1.jst.mfeed. 210.173.176.251 2 u 55 64 77 21.113 -2.546 11.627
europium.canoni 193.79.237.14 2 u 57 64 77 264.916 -16.110 9.095