インターネットなこと: 2016年12月アーカイブ

IIJ GIO ホスティングパッケージで提供されているサーバが 2台あって、仮に A.exsample.com と B.exsample.com とする。
この 2台の保守を依頼されたんだけど、なんか、A の時刻は合ってるのに、B の方は 8分ほどずれている。

どちらのサーバにも ntpd は入ってないようなので、IIJ のマニュアルを調べてみると「IIJ GIOホスティングパッケージのCentOS5は、初期状態ではXenの機能を使用してハイパーバイザと時刻を同期するように設定されています。」と。
確かに、A の方が CentOS 5 で、B の方が CentOS 6 のようだ。

試しに、A の方で確認してみると、

# /sbin/sysctl -n xen.independent_wallclock
0

と、ハイパーバイザとの時刻同期が有効な状態にあるという結果が返ってくる。("1"だと無効)

B の方で確認すると、

# /sbin/sysctl -n xen.independent_wallclock
error: "xen.independent_wallclock" is an unknown key

となる。

CentOS 6 環境も Xen 上で提供されていると思うんだけど、こっちは端からハイパーバイザとの時刻同期とはなっていないようですなあ。

ということで、Xen はよく知らないので、手っ取り早く NTP(Network Time Protocol)で時刻同期を行うことにする。

まず、yum を使ってパッケージのインストール。

# yum -y install ntp

ntp-4.2.6p5-10.el6.centos.1.x86_64 がインストールされる。

自動実行ファイルなんかも入ってるね。

# ls -la /etc/rc.d/init.d/ntp*
-rwxr-xr-x 1 root root 1923 May  4  2016 /etc/rc.d/init.d/ntpd
-rwxr-xr-x 1 root root 2043 May  4  2016 /etc/rc.d/init.d/ntpdate

まず、NTP はあまりに時間がかけ離れていると同期に時間がかかるので(って、最近もそうなん?以前はそうだった。あ、20年くらい前の話ね(笑))、ある程度手動で時刻を合わせておこう。

# date
Thu Dec  8 11:45:02 JST 2016
# date -s "12/08 11:53 2016"
Thu Dec  8 11:53:00 JST 2016

8分遅れていたので調整。

# date
Thu Dec  8 11:53:05 JST 2016

ちゃんと時刻が変更されている。
実際の時間とは数十秒ずれているだろうが、ここで ntpdate の実行。

# date
Thu Dec  8 11:55:27 JST 2016
# ntpdate ntp00.iij.net
 8 Dec 11:55:49 ntpdate[9221]: step time server 210.130.188.10 offset 21.042093 sec
# date
Thu Dec  8 11:55:53 JST 2016

21秒ほどあった差が修正された。
あとは、自動的に同期が行われるよう、ntpdデーモンを起動しておく。

まず、/etc/ntp.conf の上位サーバを変更。
上位サーバには全て IIJ が提供しているものを選んだ。

# cp /etc/ntp.conf /etc/ntp.conf_20161208
# vi /etc/ntp.conf
# diff /etc/ntp.conf /etc/ntp.conf_20161208
22,28c22,25
< #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 ntp00.iij.net
< server ntp01.iij.net
< server ntp02.iij.net
---
> 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

自動起動の設定を忘れないうちにやっておこう。

# 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
Starting ntpd:                                             [  OK  ]

同期状況確認。

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp00.IIJ.Net   210.130.188.1    3 u    6   64    1    1.108    0.055   0.002
 ntp01.IIJ.Net   210.130.188.1    3 u    6   64    1    1.481    0.266   0.002
 ntp02.IIJ.Net   210.130.188.1    3 u    5   64    1    1.063    0.068   0.002

さすが、同じ社内の NTP サーバ。同期が早い。起動したとたんに同期したで。
あ、さっき手動で ntpdate コマンド実行したからか(^^;

左に * がついている ntp00.IIJ.Net が、時刻同期している上位NTPサーバ。

もう一回実行してみる。

# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp00.IIJ.Net   210.130.188.1    3 u   25   64    7    1.114    2.955   2.291
+ntp01.IIJ.Net   210.130.188.1    3 u   29   64    7    1.488    3.068   2.217
+ntp02.IIJ.Net   210.130.188.1    3 u   28   64    7    1.130    2.903   2.255

ntp01.IIJ.Net や ntp02.IIJ.Net の横に + マークがついたけど、これは「同期候補にあがっている」サーバだということ。
例えば現在同期サーバである ntp00.IIJ.Net に何かあった場合は(多分、反応に時間がかかってるとか)、この + マークが付いているサーバが同期に使われる。

ばっちりやね。

このアーカイブについて

このページには、2016年12月以降に書かれたブログ記事のうちインターネットなことカテゴリに属しているものが含まれています。

前のアーカイブはインターネットなこと: 2016年11月です。

次のアーカイブはインターネットなこと: 2017年1月です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。


月別 アーカイブ

電気ウナギ的○○ mobile ver.

携帯版「電気ウナギ的○○」はこちら