NTPサーバー構築(chrony)(CentOS7)

提供:あわ自由帳

メインページ > CentOS 7 で自宅サーバー構築  > NTPサーバー構築(chrony)(CentOS7)

CentOS 7 標準となった、新しいNTPクライアント&サーバ、chrony をインストールすることに関する記録です。

chrony のインストール

[root@host3 ~]# yum install chrony

NTPD をストップ

旧NTPDを使っていたので止める。

[root@host3 ~]# systemctl stop ntpd

[root@host3 ~]# systemctl disable ntpd                                                          
rm '/etc/systemd/system/multi-user.target.wants/ntpd.service'

chrony サーバー設定

[root@host3 ~]# vi /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
#Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 同期をとるサーバーを変更
#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 ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
server ntp3.jst.mfeed.ad.jp iburst

# Allow NTP client access from local network.
# 内部からの時刻同期を許可
#allow 192.168/16
allow 192.168.1.0/24

手動による時刻合わせ

[root@host3 ~]# ntpdate ntp.jst.mfeed.ad.jp
27 Aug 12:42:40 ntpdate[16630]: adjust time server 210.173.160.27 offset -0.000137 sec

chronyd の起動

[root@host3 ~]# systemctl start chronyd

chronyd の自動起動設定

[root@host3 ~]# systemctl enable chronyd
ln -s '/usr/lib/systemd/system/ntpd.service' '/etc/systemd/system/multi-user.target.wants/ntpd.service'

動作確認

[root@host3 ~]# systemctl status chronyd
 chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since 土 2016-01-09 17:33:25 JST; 2h 26min ago
 Main PID: 604 (chronyd)
   CGroup: /system.slice/chronyd.service
           └─604 /usr/sbin/chronyd

 1月 09 17:33:24 host3.sudachi.jp systemd[1]: Starting NTP client/server...
 1月 09 17:33:24 host3.sudachi.jp chronyd[604]: chronyd version 2.1.1 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +...HASH)
 1月 09 17:33:24 host3.sudachi.jp chronyd[604]: Generated key 1
 1月 09 17:33:25 host3.sudachi.jp systemd[1]: Started NTP client/server.
 1月 09 17:33:34 host3.sudachi.jp chronyd[604]: Selected source 157.7.153.56
 1月 09 17:34:40 host3.sudachi.jp chronyd[604]: Selected source 157.7.203.102
 1月 09 20:00:05 host3.sudachi.jp systemd[1]: Started NTP client/server.
Hint: Some lines were ellipsized, use -l to show in full.

時刻同期状態確認

[root@host3 ~]# chronyc sources -v
210 Number of sources = 3

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||                                                /   xxxx = adjusted offset,
||         Log2(Polling interval) -.             |    yyyy = measured offset,
||                                  \            |    zzzz = estimated error.
||                                   |           |                         
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^+ ntp1.jst.mfeed.ad.jp          2   6     1     4    +11ms[  +11ms] +/-   46ms
^+ ntp2.jst.mfeed.ad.jp          2   6     1     4    +11ms[  +11ms] +/-   46ms
^* ntp3.jst.mfeed.ad.jp          2   6     1     4  +3265us[+3265us] +/-   22ms
[root@host3 ~]# chronyc sources                                                                 
210 Number of sources = 3
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* ntp1.jst.mfeed.ad.jp          2   6    17    28    -90us[-1490us] +/-   35ms
^- ntp2.jst.mfeed.ad.jp          2   6    17    26   +522us[ +522us] +/-   18ms
^- ntp3.jst.mfeed.ad.jp          2   6    17    27    -50us[  -50us] +/-   22ms