Ubuntu ~NTP~

○ NTP

サーバー運用にあたり、システム時間を正確に保つ必要がある。
そこで利用するのが、NTP(Network Time Protocol)サーバという正確な時刻を管理・提供しているサーバと同期する方法。

○ インストール

# apt-get install ntp
Reading package lists... Done
xxxxx
xxxxx
Setting up ntp (1:4.2.4p4+dfsg-3ubuntu2) ...
 * Starting NTP server ntpd
[ OK ]

○ 設定

NTP の設定は /etc/ntp.conf を編集することで可能。 

# nano /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.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

# 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 

デフォルトの設定では、NTP サーバが 「 ntp.ubuntu.com 」 となっているので、より近いサーバに変更する
精度をあげるために複数指定することが推奨されているので、サーバの記述は 3 つ程度する。
また、同一サーバを複数しているしているのは 「 DNS ラウンドロビン 」 という技術を利用するため。
異なるサーバを指定しても当然問題ない。

#server ntp.ubuntu.com
server ntp.nict.jp
server ntp.nict.jp
server ntp.nict.jp

○ 設定の適用

設定ファイルを編集したら、NTP サービスを再起動して設定を反映させる。

# /etc/init.d/ntp restart
 * Stopping NTP server ntpd
 [ OK ]
 * Starting NTP server ntpd
 [ OK ]

○ 動作確認

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp-a2.nict.go. .NICT.           1 u   36   64    3   12.749   37.336   2.785
 ntp-b3.nict.go. .NICT.           1 u   36   64    3   14.097   37.344   2.837
 ntp-a3.nict.go. .NICT.           1 u   34   64    3   13.002   37.432   3.027

設定直後に確認すると、上記のように表示される。 

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp-a2.nict.go. .NICT.           1 u    9   64   17   12.749   37.336   3.740
*ntp-b3.nict.go. .NICT.           1 u   10   64   17   14.029   42.704   5.840
+ntp-a3.nict.go. .NICT.           1 u    7   64   17   12.883   42.500   5.696

しばらくすると、上記のように表示される。
左端の * のマークは現在同期を行っているサーバーを、+ のマークは次に同期行う候補のサーバーを表しています。


自宅サーバーWebRing << 前 |ID=231 |次 >> 乱移動前後5表示サイト一覧