ntpの設定方法 - CentOS/RHEL

ntpの設定方法を記載。

確認環境

  • RHEL5

方法

RHEL

(1) インストール
# yum -y install ntp

(2) 設定

日本国内のntpサーバを参照するよう/etc/ntp.confを修正する。※推奨参照サーバという記事を参考
# cp -p /etc/ntp.conf /etc/ntp.conf.org
# vi /etc/ntp.conf
# diff /etc/ntp.conf /etc/ntp.conf.org
< #server 0.centos.pool.ntp.org
< #server 1.centos.pool.ntp.org
< #server 2.centos.pool.ntp.org
< #server 3.centos.pool.ntp.org
< server ntp0.ring.gr.jp
< server ntp2.ring.gr.jp
< server ntp2.ring.gr.jp
---
> server 0.centos.pool.ntp.org
> server 1.centos.pool.ntp.org
> server 2.centos.pool.ntp.org
> server 3.centos.pool.ntp.org

slewモードにするため/etc/sysconfig/ntpdを修正する。
# cp -p /etc/sysconfig/ntpd /etc/sysconfig/ntpd.org
# vi /etc/sysconfig/ntpd
# diff /etc/sysconfig/ntpd /etc/sysconfig/ntpd.org
2,3c2
< #OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid"
< OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid"
---
> OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid"
6,7c5
< #SYNC_HWCLOCK=no
< SYNC_HWCLOCK=yes
---
> SYNC_HWCLOCK=no
10,11c8
< #NTPDATE_OPTIONS=""
< NTPDATE_OPTIONS="-B"
---
> NTPDATE_OPTIONS=""

起動設定および起動を行う。 ※[失敗]はこの時点ではあまり気にしない。
# chkconfig ntpd on
# chkconfig --list | grep ntpd
ntpd            0:off 1:off 2:on 3:on 4:on 5:on 6:off
# service ntpd start
ntpd: 時間サーバーと同期中:                                [失敗]
ntpd を起動中: 
# service ntpd status
ntpd (pid  2902) を実行中...

(3) 同期状態を確認 ※ntpq -npの見方は、Linuxユーザーズマニュアル - 富士通が詳しい
# ntpq -np
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*163.220.2.2     .GPS.            1 u   11   64  377   11.680    0.639   4.985
 133.243.237.36  .STEP.          16 u    -   64    0    0.000    0.000   0.000
+133.243.237.35  55.117.40.186    2 u   65   64  377   10.915   -1.594   8.780
 127.127.1.0     .LOCL.          10 l   20   64  377    0.000    0.000   0.001

*が左端に表示されていれば、同期開始されており、問題なしと判断可能。
以上

コメント