在CentOS 7上配置对等NTP服务器

时间:2020-03-21 11:42:30  来源:igfitidea点击:

在CentOS 7上配置NTP对等(peering)。

测试环境

我们安装了两个要配置的CentOS 7(最小)服务器,如下所示:

admin1.hl.local(10.11.1.2)将配置为使用admin2的NTP对等体
admin2.hl.local(10.11.1.3)将配置为使用admin1的NTP对等体

两台服务器都将SELinux设置为强制模式。

软件

本文使用的软件:

  • CentOS 7
  • NTP 4.2

安装和防火墙

请注意,本节适用于两台服务器。

由于我们计划使用NTP,因此我们不需要Chrony:

# yum remove chrony

安装软件包并确保已启用该服务:

# yum install ntp
# systemctl enable ntpd

启用入站防火墙访问(我们使用iptables):

# iptables -A INPUT -s 10.11.1.0/24 -p udp -m state --state NEW --dport 123 -j ACCEPT

对等配置

可以在admin1服务器上查看文件'/etc/ntp.conf'的配置。

driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery limited 
restrict -6 default kod nomodify notrap nopeer noquery limited
restrict 10.11.1.0 mask 255.255.255.0 nomodify notrap
restrict 127.0.0.1 
server 0.uk.pool.ntp.org iburst
server 1.uk.pool.ntp.org iburst
server 2.uk.pool.ntp.org iburst
server 3.uk.pool.ntp.org iburst
peer admin2.hl.local 
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

第二台服务器admin2上的配置是相同的,除了它与admin1而不是admin2对等的那一行。

在两个服务器上重新启动服务:

# systemctl restart ntpd

打印服务器已知的对等方的列表:

# ntpq -np

remote

refid

st t when poll reach   delay   offset  jitter
==============================================================================
+10.11.1.3

178.79.160.57    3 u  889 1024  376    0.686    3.124   5.872
+134.0.16.1

195.66.241.2     2 u 1064 1024  377   16.790    2.668   3.917
+193.150.34.2    87.242.168.84    2 u  939 1024  377   16.506    1.266   4.913
*80.82.244.120   140.203.204.77   2 u  118 1024  377   17.965    2.733   3.677
+93.93.131.118   130.88.200.6     4 u 1023 1024  377   24.704    2.093   4.737