hpマイクロサーバにNTPによる自動時刻合せ設定
マイクロサーバにNTPによる時刻合はせを設定する。
- NTPをインストール。
$ sudo apt-get install ntp
- NTPの設定を確認。vimで/etc/ntp.confを開くと下記のやうになつてゐる。
$ sudo vi /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.your-provider.example # pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will # pick a different set every time it starts up. Please consider joining the # pool: <http://www.pool.ntp.org/join.html> server 0.debian.pool.ntp.org iburst server 1.debian.pool.ntp.org iburst server 2.debian.pool.ntp.org iburst server 3.debian.pool.ntp.org iburst
- 今回はデフォルトの同期先からNICTの公開NTPサーバへ同期する設定にする。変更点は強調部(もとのNTPサーバをコメントにしてntp.nict.jpを追加)。同じサーバを3回指定してゐるがDNSラウンドロビンによる負荷分散で時刻を問ひ合はせる度に別のNTPサーバに割り当ててくれるからとのこと。契約してゐるISPがNTPサーバを運用してるならそちらを指定した方がいいかもしれない。
# You do need to talk to an NTP server or two (or three). #server ntp.your-provider.example server ntp.nict.jp server ntp.nict.jp server ntp.nict.jp # pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will # pick a different set every time it starts up. Please consider joining the # pool: <http://www.pool.ntp.org/join.html> #server 0.debian.pool.ntp.org iburst #server 1.debian.pool.ntp.org iburst #server 2.debian.pool.ntp.org iburst #server 3.debian.pool.ntp.org iburst
- NTPサービスを再起動する。
$ sudo /etc/init.d/ntp restart [ ok ] Restarting ntp (via systemctl): ntp.service.
- 時刻同期の状態を確認する。
$ ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== ntp-a2.nict.go. .NICT. 1 u 65 64 1 7.763 -11.431 0.000
- しばらくたつてもう一度確認すると先頭に*がつくはず。*は現在同期してゐるNTPサーバ。+がついてゐれば接続テストに合格していつでも同期可能なサーバ。
$ ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *ntp-a2.nict.go. .NICT. 1 u 17 64 377 7.304 -15.797 3.927
サーバを再起動したらNTPが動作しなくなると困るので再起動してもNTPが動作してゐるかを確認するため、サーバを一旦再起動する。NTPの動作確認は/etc/init.d/ntp statusでもいいし、psコマンドでプロセスを確認してもいい。
$ sudo /etc/init.d/ntp status ● ntp.service - LSB: Start NTP daemon Loaded: loaded (/etc/init.d/ntp) Active: active (running) since 水 2015-08-12 21:31:40 JST; 1min 59s ago ↑がActive: active (running)なら動作してゐる。inactive (dead)だと停止してゐる。
プロセスを確認するなら下記コマンド(psコマンドをパイプしてntpでgrepした結果だけ表示)
$ ps ax | grep ntp 402 ? Ss 0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 105:110 432 pts/0 S+ 0:00 grep ntp ↑1行目がNTPのプロセス。2行目は今実行したgrepコマンドのプロセス
- サーバ再起動後もNTPが動作してをり、ntpq -pで時刻同期されてゐることを確認したら終了。