环境介绍 Node1作为NTP主节点,其他所有节点从node1进行时间同步, 节点 Ip Node1 192.168.20.101 Node2 192.168.20.102

  1. 所有节点安装ntp包:
yum install ntp
  1. 修改node1主节点的/etc/ntp.conf添加如下内容:
restrict 192.168.20.0 mask 255.255.255.0 nomodify notrap

即允许192.168.20.0网段的服务器从该节点同步时间,其中192.168.20.0可以更改为环境的实际ip网段。 3.注释掉原有的时间同步源,添加本地时间源,即外部时间服务器不可用时,以本地时间作为时间服务

#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  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

4.启动ntp服务并设置开机自启动

[root@node1 ~]# systemctl start ntpd
[root@node1 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@node1 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-10-17 22:39:05 CST; 17s ago
 Main PID: 2529 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─2529 /usr/sbin/ntpd -u ntp:ntp -g
Oct 17 22:39:05 node1 ntpd[2529]: Listen normally on 6 lo ::1 UDP 123
Oct 17 22:39:05 node1 systemd[1]: Started Network Time Service.
Oct 17 22:39:05 node1 ntpd[2529]: Listen normally on 7 eno50332184 fe80::20c:29ff:fe93:4ece UDP 123
Oct 17 22:39:05 node1 ntpd[2529]: Listen normally on 8 eno16777736 fe80::20c:29ff:fe93:4eba UDP 123
Oct 17 22:39:05 node1 ntpd[2529]: Listen normally on 9 eno33554960 fe80::20c:29ff:fe93:4ec4 UDP 123
Oct 17 22:39:05 node1 ntpd[2529]: Listening on routing socket on fd #26 for interface updates
Oct 17 22:39:05 node1 ntpd[2529]: 0.0.0.0 c016 06 restart
Oct 17 22:39:05 node1 ntpd[2529]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Oct 17 22:39:05 node1 ntpd[2529]: 0.0.0.0 c011 01 freq_not_set
Oct 17 22:39:06 node1 ntpd[2529]: 0.0.0.0 c514 04 freq_mode

5.修改其他所有ntp客户端,即node2的/etc/ntp.conf 。删除所有ntp源,并添加node1节点的ntp时间源,其中192.168.20.101为node1的ip,可用node1域名代替。

#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 192.168.20.101

6.启动ntp服务并设置开机自启动

[root@node2 ~]# systemctl start ntpd 
[root@node2 ~]# systemctl enable ntpd 
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.serviceto /usr/lib/systemd/system/ntpd.service.

7.查看是否同步成功,显示如下192.168.20.101为node1节点的ip地址,说明同步成功。

[root@node2 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*192.168.20.101  LOCAL(0)        11 u   49   64  377    0.293    0.011   0.253

8.在node2上查看与node1时间服务器的实际偏差

[root@node2 ~]# ntpdc -c loopinfo
offset:               0.000011 s
frequency:            0.002 ppm
poll adjust:          6
watchdog timer:       270 s

欢迎扫描关注本人公众号,会定时分享IT技术文章,如有其它技术问题,可随时咨询。