技術メモのかけら

内容はもとより調べたことすら忘れてしまうので個人的なメモです。とにかく短く、結論だけ書いていきます。

ntpで時刻を同期

前回タイムゾーンを日本に変更したが、そもそも時刻がずれていたのでntpの設定をしておくことにする。

まずはntpをインストール

# yum -y install ntp

さっそく時刻を合わせてみる。

# ntpdate ntp.nict.jp
23 Mar 09:26:36 ntpdate[3960]: step time server 133.243.238.243 offset -0.791366 sec

次に、自動的に時刻をntpサーバーと同期するようにしてみる。 まずは/etc/ntp.confのサーバーの指定を編集する。

# コメントアウトする
#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 -4 ntp.nict.jp
server -4 ntp1.jst.mfeed.ad.jp
server -4 ntp2.jst.mfeed.ad.jp
server -4 ntp3.jst.mfeed.ad.jp

サービスを起動する。

# service ntpd start

自動起動するように仕掛けておく。

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

状態は下記コマンドで調べられるらしい。同期可能なサーバは先頭が+、同期中は*、使えないサーバはxとか.とか-表示されるらしい。

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp-a3.nict.go. .NICT.           1 u    1   64  377   12.046  -19758. 5103.93
 ntp1.jst.mfeed. 172.29.3.50      2 u    3   64  377   13.373  -19723. 5112.72
 ntp2.jst.mfeed. 133.243.236.18   2 u   62   64  377   14.607  -18684. 5130.92
 ntp3.jst.mfeed. 172.29.3.50      2 u   66   64  377   13.246  -18613. 5129.00