CentOS6 で NTP サーバの設定

2012-1-25 19:48
このエントリーをはてなブックマークに追加

これまで NTP サーバの設定方法を書いていなかったので、CentOS6 向けの設定をまとめます。

インストール

yum でインストールします。

  # yum install ntp

設定

外部のサーバと同期させるための設定です。(NTP サーバとしての公開の設定は後述)

ここでは、NTP サーバとして 日本標準時プロジェクトの公開 NTP サーバを利用します。

# vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
#server 0.centos.pool.ntp.org #コメントにする
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
server -4 ntp.nict.jp iburst  #おなじものを3つ書く!
server -4 ntp.nict.jp iburst
server -4 ntp.nict.jp iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

プロバイダや企業が提供する NTP サーバを利用する場合はそれらに読み替えてください。

NTPサーバ名のあとに iburst と書くいてあるのは、公開NTP FAQによると、

“iburst” は起動時に多数ポーリングし、初期化時間を短縮します。

ということです。

起動と動作確認

NTP サーバを再起動します。

  # service ntpd restart

ntpq コマンドで確認します。

# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp-b3.nict.go. .NICT.           1 u   69  128  377   17.515   23.736   3.499

起動直後は remote のアドレスの先頭はスペースですが、時刻の同期が完了すると * に変わります。

公開設定

社内ネットワークなどに NTP サーバを公開する設定です。

# vim /etc/ntp.conf
# 以下の設定を追加
restrict 192.168.1.0 mask 255.255.0.0 notrust nomodify notrap

NTP サーバを再起動して、他の マシンから ntpdate コマンドや ntpq コマンドで接続確認をします。

# ntpdate -d -4 192.168.1.123
25 Jan 20:14:44 ntpdate[20285]: ntpdate 4.2.4p8@1.1612-o Tue Nov 29 00:09:13 UTC 2011 (1)
Looking for host 192.168.1.123 and service ntp
host found : 192.168.1.123
transmit(192.168.1.123)
……(繰り返し)……
server 192.168.1.123, port 123
stratum 3, precision -23, leap 00, trust 000
……
25 Jan 20:14:44 ntpdate[20285]: adjust time server 192.168.1.123 offset -0.008846 sec

エラーが出た時

# ntpdate
25 Jan 20:23:30 ntpdate[19667]: no servers can be used, exiting

このようなエラーが出た時には、-d オプションを使って詳細を見ます。

# ntpdate -d -4 192.168.1.123
25 Jan 20:27:02 ntpdate[19670]: ntpdate 4.2.4p8@1.1612-o Tue Nov 29 00:09:13 UTC 2011 (1)
Looking for host 192.168.1.123 and service ntp
host found : 192.168.1.123
transmit(192.168.1.123)
transmit(192.168.1.123)
……
192.168.1.123: Server dropped: no data
server 192.168.1.123, port 123
stratum 0, precision 0, leap 00, trust 000
refid [192.168.1.123], delay 0.00000, dispersion 64.00000
transmitted 4, in filter 4
……
offset 0.000000
25 Jan 20:27:06 ntpdate[19670]: no server suitable for synchronization found

このような時には、通信がうまくできていません。NTPサーバの ntp.conf でもっとワークからのアクセスが許可されているか、また iptables やファイアウォールで UDP Port 123 へのアクセスが遮断されていないかを確認してください。

  • ブックマーク : アクセス: 70,611回
  • カテゴリー : Linux
  • キーワード :

コメントはまだありません

No comments yet.

Sorry, the comment form is closed at this time.

33 queries. HTML convert time: 0.074 sec. Powered by WordPress. Valid XHTML
Copyright © 2003-2017 @ futuremix.org ログイン