LinuxシステムにおけるNTPサーバーの構築と運用

サーバー側のインストールプロセス

必要なパッケージをインストール

[root@server ~]# yum -y install chrony ntpdate

NTP構成ファイルを修正し、中国本土向けの時間同期サーバーを追加してBIOS時刻との調整を行います。

中国本土のデータセンターに設置されたサーバーについては、標準のRHEL/CentOS NTPサーバーがアクセス不能なため、中国本土専用のNTPサービスを利用する必要があります。 海外データセンターのサーバーは標準のRHEL/CentOS NTPサービスを利用できます(アクセス可能か事前に確認してください)。 以下の通り設定します:

cat <<  EOF >> /etc/chrony.conf
server 0.centos.pool.ntp.org iburst minpoll 4 maxpoll 4
server 1.centos.pool.ntp.org iburst minpoll 4 maxpoll 4
server 2.centos.pool.ntp.org iburst minpoll 4 maxpoll 4
server 3.centos.pool.ntp.org iburst minpoll 4 maxpoll 4
server ntp1.cloud.tencent.com iburst minpoll 4 maxpoll 4
server ntp2.cloud.tencent.com iburst minpoll 4 maxpoll 4
server ntp.tencent.com iburst minpoll 4 maxpoll 4
server ntp.gwbnetwork.com iburst minpoll 4 maxpoll 4
allow 192.168.0.0/16
local stratum 10
makestep 1.0 3
EOF

説明:特定のネットワーク範囲からのみ時刻同期を許可します。すべてのIPアドレスからの接続を許可する場合は「allow all」を追加します。

NTPサービスを再起動

[root@server ~]# systemctl start chronyd
[root@server ~]# systemctl enable chronyd
# CentOS 6系の場合
[root@server ~]# service chronyd start
[root@server ~]# chkconfig --level 35 chronyd on

サーバー側の定期実行タスク設定

サーバーで定期的な外部同期を設定できます

[root@server ~]# crontab -e
0 */2 * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1

クライアント側の設定方法

ntpdateパッケージをインストール

[root@client ~]# yum -y install ntpdate

定期実行タスクを構成

手動でコマンドを実行して動作確認:
[root@client ~]# ntpdate 時刻サーバーのIPアドレス
21 Jun 16:45:35 ntpdate[2323]: adjust time server IPアドレス offset 0.123456 sec
自動同期を設定
[root@client ~]# crontab -e
# サーバー時刻同期
*/10 * * * * /usr/sbin/ntpdate 時刻サーバーのIPアドレス > /dev/null 2>&1

CentOS 7.xのファイアウォール設定

# NTPポートを開放
firewall-cmd --permanent --add-port=123/udp
firewall-cmd --permanent --add-service=ntp

# ルールをリロード
firewall-cmd --reload

CentOS 6.xから5.xのファイアウォール設定

[root@server ~]# iptables -I INPUT -p udp --dport 123 -j ACCEPT
[root@server ~]# service iptables save

公開NTPサーバー一覧

アリババクラウドのNTP同期サーバー

Unix系システム:time1-7.aliyun.com
Windows:time.pool.aliyun.com

ntp1.aliyun.com
ntp2.aliyun.com
ntp3.aliyun.com
ntp4.aliyun.com
ntp5.aliyun.com
ntp6.aliyun.com
ntp7.aliyun.com

中国各大学の公開NTPサーバー

ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学ネットワークセンターNTPサーバー)
s1a.time.edu.cn	北京郵電大学
s1b.time.edu.cn	清華大学
s1c.time.edu.cn	北京大学
s1d.time.edu.cn	東南大学
s1e.time.edu.cn	清華大学
s2a.time.edu.cn	清華大学
s2b.time.edu.cn	清華大学
s2c.time.edu.cn	北京郵電大学
s2d.time.edu.cn	西南地域ネットワークセンター
s2e.time.edu.cn	西北地域ネットワークセンター
s2f.time.edu.cn	東北地域ネットワークセンター
s2g.time.edu.cn	華東南地域ネットワークセンター
s2h.time.edu.cn	四川大学ネットワーク管理センター
s2j.time.edu.cn	大連理工大学ネットワークセンター
s2k.time.edu.cn CERNET桂林ノード
s2m.time.edu.cn 北京大学

グローバルNTPサービスサイト

http://www.ntp.org.cn/pool.php

タグ: ntp linux server time-synchronization CentOS

5月19日 06:15 投稿