2007年7月23日月曜日

時刻同期手順

■dateコマンドであらかじめ時刻を合わせておく
[root@tanyao ~]# date 072310312007
2007年 7月 23日 月曜日 10:31:00 JST

■/etc/ntp.conf を編集
# --- OUR TIMESERVERS -----
# server 0.pool.ntp.org
# server 1.pool.ntp.org
# server 2.pool.ntp.org
server 192.168.199.126
restrict 192.168.199.126 mask 255.255.255.255 nomodify notrap noquery

■ntpdを起動する
[root@tanyao ~]# /etc/init.d/ntpd start
ntpd 繧定オキ蜍穂クュ: [ OK ]

■少し時間をおいてから、ntpqコマンドを実行
[root@tanyao ~]# /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.199.126 202.232.0.1 4 u - 64 3 4.475 -33939. 3387.84
LOCAL(0) LOCAL(0) 10 l 62 64 1 0.000 0.000 0.002

■サービスとして登録しておく?(不要かも)
[root@tanyao ~]# echo "/etc/init.d/ntpd start" >> /etc/rc.d/rc.local


■手動で時刻を同期する(ntpdを停止してから)
[root@tanyao ~]# ntpdate 192.168.199.126
11 Oct 15:02:42 ntpdate[15326]: step time server 192.168.199.126 offset 4.384445 sec


■/etc/ntp.conf を置換えてみる
[root@tanyao ~]# cat /etc/ntp.conf
# デフォルトで全てのNTPアクセス拒否
restrict default ignore

# ローカルホストからはNTPアクセス許可
restrict 127.0.0.1

# 外部のNTPサーバへのNTPアクセス許可(下記serverで指定したサーバを全て指定。
# NICTやMFEEDはラウンドロビンでどのサーバになるか不定のため全て記述すること。)
restrict 192.168.199.126 mask 255.255.255.255 nomodify notrap noquery

# 外部のNTPサーバの指定
server 192.168.199.126

# 変動情報記録ファイルの指定(起動前にファイルがあることを確認。なければ作成しておく。)
driftfile /var/lib/ntp/drif

# 認証の指定(上位NTPサーバの認証キーがある場合は、yesとすることで認証可能)
authenticate no

→再起動
[root@tanyao ~]# /etc/init.d/ntpd start
ntpd: 譎る俣繧オ繝シ繝舌→蜷梧悄荳ュ: [ OK ]
ntpd 繧定オキ蜍穂クュ: [ OK ]

[root@tanyao ~]# /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.199.126 202.232.0.1 4 u 52 64 3 7.868 -652.73 4611.07

ラベルの意味:
 remote リモート・サーバーのホスト名
 refid 参照ID(不明の場合は、0.0.0.0)
 st stratum番号、サーバーが第何階層かを表します。
 t 階層タイプ(l:local,u:unicast,m:multicast,b:broadcast)
 when 最後のパケットを受け取ってからの時間(単位:秒)
 poll ポーリング間隔(単位:秒)
 reach 到達可能なレジスタを(8進数表現)
 delay ポーリングインターバルの遅延見積もり(単位:ミリ秒)
 offset 階層のオフセット(単位:ミリ秒)
 disp 階層の分散(単位:ミリ秒)


しばらくすると完全に合わせられる?!
[root@tanyao ~]# /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.199.126 .STEP. 16 u 149 64 0 0.000 0.000 4000.00