CentOS7.3でNTPサーバを構築する。
NTPサーバを構築します。
CentOS7ではchrondyとntpdの選択肢がありますが、
今回はchronydを使います
インストール
Cent7のminimalでインストールされていたため、
おそらくインストール不要。
無ければ
yum install chronyd
で。
設定ファイルを編集する
# vi /etc/chrony.conf
上位のNTPサーバを指定します。
このあたりを参考にNTPサーバを指定する。
http://wiki.nothing.sh/page/NTP/%BF%E4%BE%A9%B8%F8%B3%AB%A5%B5%A1%BC%A5%D0
#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
また、CentOS8.0からはデフォルトのchronyc.confでは、serverコマンドではなく、poolコマンドが使用されるようになりました。
pool 2.centos.pool.ntp.org iburst
poolはDNSによる名前解決時に複数のIPアドレスを返してくれる場合に、
まとめて同期先サーバとして指定してくれます。
ですので、上記でserverコマンドを3行並べていましたが、
これらは「ntp.jst.mfeed.ad.jp」の正引きでそれぞれのIPアドレスを返してくれるので、
下記に置き換えできます。
pool ntp.jst.mfeed.ad.jp iburst
CentOS8においても従来通りserverコマンドで指定もできますし、pool/serverコマンドの併用も可能です。
アクセス許可
allowエントリーでアクセス制御設定をします。
今回はプライベートアドレスからの時刻問い合わせを許可します。
allow 192.168/16
allow 172.16/12
allow 10/8
firewalld設定
ntp(udp:123)を開放します。
# firewall-cmd --permanent --zone=public --add-port=123/udp
success
ntpdの起動
# systemctl start chronyd
# systemctl enable chronyd
動作確認
# chronyc sources
210 Number of sources = 3
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* ntp1.jst.mfeed.ad.jp 2 10 377 1008 +967us[ +480us] +/- 99ms
^+ ntp2.jst.mfeed.ad.jp 2 10 377 985 -1598us[-1598us] +/- 92ms
^+ ntp3.jst.mfeed.ad.jp 2 10 377 300 +731us[ +731us] +/- 115ms