CentOSをつかって自宅サーバを構築−Webサーバ・Mailサーバ・Sambaサーバ etc

インターネットで接続できる外部のntpサーバーと同期させて、サーバー機の時刻合わせをする。



ntpサーバーのインストール

# yum -y install ntp

ntpサーバーの設定

ntpサーバーの設定ファイルを編集する。
 # cp /etc/ntp.conf /etc/ntp.conf.old ←(オリジナルをコピーしておく)
 
 # vi /etc/ntp.conf
 
 【13行目】
 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
  ↓
 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
  内部ネットワークからの時刻同期を許可する

 【17行目から19行目】
 server -4 ntp.nict.jp minpoll 4 maxpoll 8 iburst
 server -4 ntp.nict.jp minpoll 4 maxpoll 8 iburst
 server -4 ntp.nict.jp minpoll 4 maxpoll 8 iburst
 
 同じ内容を3行とも記載する。
 「-4」IPv4で強制的に接続する。
 「minpoll」ポーリングする間隔の最小値(例だと2の4乗=16秒)
 「maxpoll」ポーリングする間隔の最大値(例だと2の8条=256秒)
 「iburst」起動時に多数ポーリングし、初期化時間を短縮する。

ntpサーバーについてはこちらを参考に
独立行政法人情報通信研究機構(NICT)
NTP-nothing@wiki

ntpサーバーの起動

 # /etc/rc.d/init.d/ntpd start

自動起動の設定を確認
 # chkconfig --list ntpd
 ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
2〜5が"on"になっていない場合
 # chkconfig ntpd on

ntpサーバーの確認

 # ntpq -p

設定直後は下記のように表示される
      remote           refid      st t when poll reach   delay   offset  jitter
 ==============================================================================
  ntp-a3.nict.go. .NICT.           1 u    1   16    1   14.411   14.108   1.077
  ntp-a2.nict.go. .NICT.           1 u    2   16    1   17.978   14.643   0.001
  ntp-b3.nict.go. .NICT.           1 u    1   16    1   20.327   15.462   0.001

しばらく経つと下記のように表示される(左端に+などの記号がでる。)
      remote           refid      st t when poll reach   delay   offset  jitter
 ==============================================================================
 +ntp-a3.nict.go. .NICT.           1 u   37   64  377   13.938   16.932   3.585
 +ntp-a2.nict.go. .NICT.           1 u   55   64  377   13.940   17.145   2.671
 *ntp-b3.nict.go. .NICT.           1 u   62   64  377   15.776   12.137   3.604

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます