ヘルプ:NTPサーバー構築(chrony)(CentOS7)

提供:EELの自由帳

メインページ > ヘルプ:目次 > ヘルプ:自宅サーバー構築(CentOS7)  > NTPサーバー構築(chrony)(CentOS7)

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

chrony のインストール

[root@host2 ~]# 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@host2 ~]# 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@host2 ~]# ntpdate ntp.nict.jp
 5 May 22:43:30 ntpdate[28364]: adjust time server 133.243.238.163 offset -0.015374 sec

chronyd の起動

[root@host3 ~]# systemctl start chronyd

chronyd の自動起動設定

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

動作確認

[root@host2 ~]# systemctl status chronyd
 chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since 日 2019-05-05 22:46:13 JST; 4s ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 28385 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
  Process: 28381 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 28383 (chronyd)
   CGroup: /system.slice/chronyd.service
           mq28383 /usr/sbin/chronyd

 5月 05 22:46:13 host2.sudachi.jp systemd[1]: Starting NTP client/server...
 5月 05 22:46:13 host2.sudachi.jp chronyd[28383]: chronyd version 3.2 starti...
 5月 05 22:46:13 host2.sudachi.jp chronyd[28383]: Frequency -12.491 +/- 0.06...
 5月 05 22:46:13 host2.sudachi.jp systemd[1]: Started NTP client/server.
Hint: Some lines were ellipsized, use -l to show in full.

時刻同期状態確認

[root@host2 ~]# 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
||      Reachability register (octal) -.           |  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   177    35  +1910us[+1910us] +/-  113ms
^+ ntp2.jst.mfeed.ad.jp          2   6   177    37  +7666us[+7666us] +/-  111ms
^* ntp3.jst.mfeed.ad.jp          2   6    77   105  +3895us[+2073us] +/-  139ms
[root@host2 ~]# chronyc sources
210 Number of sources = 3
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^+ ntp1.jst.mfeed.ad.jp          2   6   377    60  +2092us[+2092us] +/-  114ms
^+ ntp2.jst.mfeed.ad.jp          2   6   377    58  +8636us[+8636us] +/-  112ms
^* ntp3.jst.mfeed.ad.jp          2   6   176   191  +3895us[+2073us] +/-  139ms