19
28

More than 5 years have passed since last update.

Chrony によるNTP設定(CentOS7.4)

Posted at

ChronyによるNTP設定のメモ

OSバージョン

CentOS Linux release 7.4.1708 (Core)

Chronyとは

CentOS7/RHEL7でntpdの変わりに標準となったNTP機能(サーバ/クライアント両方)
これからNTPを学ぶ方はChronyの方が良いのかなと思われます。

事前確認

# rpm -qa | grep chrony
chrony-3.1-2.el7.centos.x86_64

サービスとしても自動起動が設定されています。

# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since 土 2017-12-30 14:40:12 JST; 4min 9s ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 797 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
  Process: 774 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 779 (chronyd)
   CGroup: /system.slice/chronyd.service
           mq779 /usr/sbin/chronyd

12月 30 14:40:11 centos74.localdomain systemd[1]: Starting NTP client/server...
12月 30 14:40:12 centos74.localdomain chronyd[779]: chronyd version 3.1 star...
12月 30 14:40:12 centos74.localdomain chronyd[779]: Frequency 0.047 +/- 0.03...
12月 30 14:40:12 centos74.localdomain systemd[1]: Started NTP client/server.
12月 30 14:40:49 centos74.localdomain chronyd[779]: Forward time jump detected!
12月 30 14:40:54 centos74.localdomain chronyd[779]: Selected source 133.130....
12月 30 14:40:54 centos74.localdomain chronyd[779]: System clock wrong by -2...
12月 30 14:40:28 centos74.localdomain chronyd[779]: System clock was stepped...
12月 30 14:40:28 centos74.localdomain chronyd[779]: Selected source 122.215....
12月 30 14:40:30 centos74.localdomain chronyd[779]: Source 129.250.35.250 re...
Hint: Some lines were ellipsized, use -l to show in full.

設定

設定は非常に簡単です。

(1)定義ファイルのバックアップ

# cp -p /etc/chrony.conf /etc/chrony.conf.org
# diff /etc/chrony.conf /etc/chrony.conf.org
#

(2)定義ファイルの設定を行います。
 NTPサーバの指定としてNICTのNTPサーバを指定してみました。

# vi /etc/chrony.conf

/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 ntp.nict.jp iburst ★←同期したいNTPサーバを指定してください。

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
#  もし1秒以上のズレがある場合、最初の3回まではslew調整の代わりにstep調整する
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#allow 192.168.0.0/16 ★←NTPクライアントからの接続を制限したい場合はこちらを設定

# Serve time even if not synchronized to a time source.
#local stratum 10 ★←Stratum1を最上位としてローカルがどこのNTPになるかを設定(NTPサーバとする場合は記述)

# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys

# Specify directory for log files.
logdir /var/log/chrony ★←ログの出力先ディレクトリを指定

# Select which information is logged.
#log measurements statistics tracking ★←取得するログの種類を指定

# デフォルトで入っていなかったオプション
# noclientlog ★←こちらを指定するとクライアントログが取得されない

取得可能なログは下記表の通り。

ログ 説明
measurements 生のNTP測定と関連情報を measurements.log と呼ばれるファイルにログ記録します。
statistics 回帰処理についての情報を statistics.log と呼ばれるファイルにログ記録します。
tracking システムが進むまたは遅れるレートの予測に対する変更、およびなされたスルーを tracking.log と呼ばれるファイルにログ記録します。
rtc システムのリアルタイムクロックについての情報を rtc.log と呼ばれるファイルにログ記録します。
refclocks 生およびフィルター処理された参照クロックの測定を refclocks.log と呼ばれるファイルにログ記録します。
tempcomp 温度測定とシステムレートの補正を tempcomp.log と呼ばれるファイルにログ記録します。

(3)サービスの再起動を行います。

# systemctl restart chronyd

(4)動作確認
同期状態を確認します。

# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* ntp-b3.nict.go.jp             1   6   177    26    +66us[ +632us] +/- 4299us

クライアントログについて

クライアントログは、「自ホスト NTPクライアント設定の上位NTPサーバへのアクセス」を記録したものです。
NTPサーバ機能で下位NTPクライアントからのアクセスを記録することはできません。
(他サイトで見てこの部分を混乱していました。)

ハードウェアアプライアンス等々でも「NTPクライアントからのアクセス記録」するのは難しいようです。
(仕様的にそういう想定はしてなさそう)

顧客要求があった場合はNW機器(FW)やOSのFirewall設定で通信記録を取るしかなさそうです。

参考

RHEL公式
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-understanding_chrony_and-its_configuration

19
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
28