ntpdの設定

パッケージの入手

apt-get install ntp ntp-doc ntpdate ntp-server ntp-simple 

/etc/ntp.conf の編集

# ファイル出力の設定
driftfile /var/lib/ntp/ntp.drift
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

# コメントアウトするとsyslogに書く
#logfile /var/log/ntpd

# ブロードキャストは無視
#broadcast 192.168.123.255
#broadcastclient

## クライアントアクセスの制限
restrict default ignore
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

disable bclient calibrate pps
enable auth kernel monitor ntp stats

## サーバ指定とアクセス制限の解除

# ntp1.sakura.ad.jp
server   210.188.224.14 minpoll 4 maxpoll 12
restrict 210.188.224.14

# ntp2.jst.mfeed.ad.jp
server   210.173.160.57 minpoll 4 maxpoll 12
restrict 210.173.160.57
server   210.173.160.87 minpoll 4 maxpoll 12
restrict 210.173.160.87

ntpdateで合わせてから起動

# ntpdate 210.173.160.57
# /etc/init.d/ntp-server start

動作確認

# ntpq -pn ; ntptrace
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 210.188.224.14  .INIT.          16 u    -   64    0    0.000    0.000 4000.00
 210.173.160.57  .INIT.          16 u    -   64    0    0.000    0.000 4000.00
 210.173.160.87  .INIT.          16 u    -   64    0    0.000    0.000 4000.00
localhost.localdomain: stratum 16, offset 0.000000, synch distance 0.000000

今回の場合、

  • whenが書かれていない => サーバ指定に合わせた restrict を書く
  • ntptrace でstratum が16のまま => 待つ

で直りました。

# ntpq -pn ; ntptrace
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 *p1*210.188.224.14  .GPS.            1 u    4   16  377    4.271   94.248   5.596
+210.173.160.57  210.173.160.86   2 u    3   16  377    4.147   89.791   6.572
+210.173.160.87  210.173.160.86   2 u    4   16  377    3.775   96.401   6.462
localhost.localdomain: stratum 2, offset 0.000000, synch distance 0.001963
ntp1.sakura.ad.jp: stratum 1, offset 0.000000, synch distance 0.000000, refid 'GPS'

ログの確認
/var/log/daemon.log のntpdの行を見て怪しかったのが

Feb  6 05:26:34 localhost ntpd[15136]: kernel time sync status 0040
Feb  6 05:26:34 localhost ntpd[15136]: Frequency format error in /var/lib/ntp/ntp.drift
Feb  6 05:28:29 localhost ntpd[15136]: kernel time sync disabled 0041

の3行。driftfile は 1時間後に出来るらしい。 kernel time sync disabled は usr-share-doc/ntp-doc/html/msyslog.html , usr-share-doc/ntp-doc/html/miscopt.html によると
によると

kernel time sync disabled ?
  The kernel reports an error. See the codes in the timex.h file.

(enable|disable) kernel
    Enables the kernel time discipline, if available. The default for this flag is enable if support is available, otherwise disable.

とあり、ビルド時に有効にされていないと設定を変えても直らない、ということのようだ。