基于CentOS 7
规划
比如有2台机器
IP
主机名
说明
192.168.103.51
cdh51
本地NTP服务端
192.168.103.52
cdh52
本地NTP客户端
安装NTP服务
每台机器都安装ntp
yum -y install ntp
NTP服务端(cdh51)配置
/etc/ntp.conf配置
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
# 添加该行允许某个网段服务器从该服务同步时间
restrict 192.168.103.0 mask 255.255.255.0 nomodify notrap
# 本地NTP服务同外网NTP服务同步时间
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
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
执行 ntpdate 0.centos.pool.ntp.org ,手动做一次时间同步。再执行systemctl start ntpd
查看同步情况:
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp1.ams1.nl.le 130.133.1.10     2 u  253  256  377  229.358   -2.606  10.955
+ntp.wdc1.us.lea 130.133.1.10     2 u  459  128  150  331.680  -44.356  17.944
*85.199.214.100  .GPS.            1 u  384   64  140  215.429   10.354  22.668
NTP服务端(cdh51)配置
/etc/ntp.conf配置
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
# 同NTP服务端cdh51同步时间
server cdh51 iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
执行 ntpdate cdh51 ,手动做一次时间同步。再执行systemctl start ntpd
查看同步情况:
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*cdh51           85.199.214.100   2 u   52  128  377    0.322   -3.060   0.674
 
 
 
 
 
 