NTPサーバ
提供: Astarisk Works Wiki
NTPサーバについてまとめる。
インストール
Ubuntuなら簡単。apt-getで一発。
> sudo apt-get install ntp
設定
まず、NTPサーバとなるマシンの時間を合わせる。
外部のNTPサーバに問い合わせて時刻あわせするにはntpdateコマンドを利用する。
次の例は日本標準時プロジェクト 公開NTP
のNTPサーバ(ntp.nict.jp)で時刻あわせしている例。
他のサーバであわせたければNTP サーバ一覧 をまとめてくれている方がいる。感謝。
> sudo ntpdate ntp.nict.jp
/etc/ntp.confを編集して設定する。
Ubuntでのデフォルトの設定ファイルの内容は次の通り。
# /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.ubuntu.com # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for # details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions> # might also be helpful. # # Note that "restrict" applies to both servers and clients, so a configuration # that might be intended to block requests from certain clients could also end # up blocking replies from your own upstream servers. # By default, exchange time with everybody, but don't allow configuration. restrict -4 default kod notrap nomodify nopeer noquery restrict -6 default kod notrap nomodify nopeer noquery # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1 restrict 192.168.1.0 mask 255.255.255.0 # Clients from this (example!) subnet have unlimited access, but only if # cryptographically authenticated. #restrict 192.168.123.0 mask 255.255.255.0 notrust # If you want to provide time to your local subnet, change the next line. # (Again, the address is an example only.) #broadcast 192.168.123.255 # If you want to listen to time broadcasts on your local subnet, de-comment the # next lines. Please do this only if you trust everybody on the network! #disable auth #broadcastclient
serverでこのNTPサーバ自身が参照する上位のNTPサーバを設定し、 restrictでアクセスを許可するクライアントネットワークを指定する。
設定がすんだら、NTPサーバを再起動する。
> sudo /etc/init.d/ntpd restart
確認
次のコマンドを実行すると、上位のNTPと同期がとれているかどうか確認できる。
同期したサーバには * がつく。
> ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*europium.canoni 193.79.237.14 2 u 5 128 377 272.404 16.541 2.818
次に自分自身との同期を確認し、設定したNTPサーバが機能していることを確認する。
adjust time serverと表示されれば機能している。
> ntpdate -q localhost
server ::1, stratum 3, offset -0.000006, delay 0.02563
server 127.0.0.1, stratum 3, offset -0.000006, delay 0.02563
16 Dec 16:43:01 ntpdate[14521]: adjust time server 127.0.0.1 offset -0.000006 sec
ちなみに、ntpdateの-qオプションをつけるとNTPサーバから時刻を取ってくるだけで、自身の時刻あわせは行われない。 ずれていたら、合わせる必要がある。