NTP 时间同步

164 阅读1分钟

 rpm -q ntp -- 验证是否安装 ntp 服务

yum install -y ntp -- 群发,如果没有 ntp 服务则安装一个

systemctl enable ntpd

systemctl start ntpd

systemctl status ntpd

配置服务端

vim /etc/ntp.conf

 

restrict 127.0.0.1
restrict ::1
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

[root@153 ~]# ntpstat
synchronised to NTP server (202.118.1.81) at stratum 2
time correct to within 983 ms
polling server every 64 s
[root@153 ~]# ntpq -p
remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time.neu.edu.cn .PTP.            1 u   16   64    1   61.155   14.381   7.256
sv1.ggsrv.de    192.53.103.103   2 u   15   64    1  241.410   18.393   0.197
111.230.189.174 100.122.36.196   2 u   14   64    1   21.831   16.980   0.174
time.neu.edu.cn .PTP.            1 u   13   64    1   59.822   15.195   0.231

客户端配置:

vim /etc/ntp.conf

restrict 127.0.0.1
restrict ::1
server *.*.*.*  #指向serverIP

测试是否正常

[root@154 ~]# ntpstat
unsynchronised
time server re-starting
polling server every 8 s
[root@154 ~]# ntpstat
synchronised to NTP server (191.191.170.153) at stratum 12 
time correct to within 1462 ms
polling server every 64 s
[root@dwzt154 ~]# ntpq -p
remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
t153         111.230.189.174  3 u   18   64  377    0.297   67.915  15.657
[root@dwzt154 ~]# ntpq -p
remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
153         LOCAL(0)        11 u   22   64  377    0.245   31.356   4.721