基于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配置
1driftfile /var/lib/ntp/drift 2 3restrict default nomodify notrap nopeer noquery 4 5restrict 127.0.0.1 6restrict ::1 7 8# 添加该行允许某个网段服务器从该服务同步时间 9restrict 192.168.103.0 mask 255.255.255.0 nomodify notrap 10 11# 本地NTP服务同外网NTP服务同步时间 12server 0.centos.pool.ntp.org iburst 13server 1.centos.pool.ntp.org iburst 14server 2.centos.pool.ntp.org iburst 15server 3.centos.pool.ntp.org iburst 16 17includefile /etc/ntp/crypto/pw 18 19keys /etc/ntp/keys 20 21disable monitor
执行 ntpdate 0.centos.pool.ntp.org ,手动做一次时间同步。再执行systemctl start ntpd
查看同步情况:
1# ntpq -p 2 remote refid st t when poll reach delay offset jitter 3============================================================================== 4+ntp1.ams1.nl.le 130.133.1.10 2 u 253 256 377 229.358 -2.606 10.955 5+ntp.wdc1.us.lea 130.133.1.10 2 u 459 128 150 331.680 -44.356 17.944 6*85.199.214.100 .GPS. 1 u 384 64 140 215.429 10.354 22.668
NTP服务端(cdh51)配置
/etc/ntp.conf配置
1driftfile /var/lib/ntp/drift 2 3restrict default nomodify notrap nopeer noquery 4 5restrict 127.0.0.1 6restrict ::1 7 8# 同NTP服务端cdh51同步时间 9server cdh51 iburst 10 11includefile /etc/ntp/crypto/pw 12 13keys /etc/ntp/keys 14 15disable monitor
执行 ntpdate cdh51 ,手动做一次时间同步。再执行systemctl start ntpd
查看同步情况:
1# ntpq -p 2 remote refid st t when poll reach delay offset jitter 3============================================================================== 4*cdh51 85.199.214.100 2 u 52 128 377 0.322 -3.060 0.674