conf t

インフラエンジニアのメモ

LinuxでNTPのインストールと設定

LinuxでNTPのインストールと設定します。

yumでntpをインストールする

# yum install -y ntp

vi で/etc/ntp.conf編集

ここに載ってたntp.jst.mfeed.ad.jpを使用。
tracerouteで調べてもここが一番到達がはやいっぽい。
NTP/BIGLOBE - wiki@nothing

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntp.jst.mfeed.ad.jp

自動起動するようにしておく。

# chkconfig --list ntpd
ntpd            0:off   1:off   2:off   3:off   4:off   5:off   6:off
# chkconfig ntpd on
# chkconfig --list ntpd
ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

起動

# service ntpd start
ntpd を起動中:                                             [  OK  ]

ntpq -pで同期状態確認。
時刻がかなり離れています。
offsetが-325108ms
(この時普通に5時間以上時間が連れていたんですが?)

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp2.jst.mfeed. 172.16.176.60    2 u    4   64    3    5.460  -325108   6.656

以下のように、1000秒(約17分)離れいている場合、同期しません。

man 抜粋

In case there is no TOY chip or the TOY time is more than 1000 s  from  the  server
time, ntpd assumes something must be terribly wrong and exits with a panic message to the system operator.

今回は5時間以上離れていたため、ntpd起動しても同期されていないようでした。
そのため、手動で同期させます。

# ntpdate ntp.jst.mfeed.ad.jp

すると、NTP同期したようです。(offsetが少なくなった。)

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp2.jst.mfeed. 172.29.1.50      2 u   10   64    7    4.893  -13.315  10.708