第1章 ntp时间服务器搭建
ntp(networktime protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时utc,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。
ntp服务器就是利用ntp协议提供时间同步服务的。
[root@oldboyedu ~]# vim/etc/ntp.conf
# restrict default kod nomodifynotrap nopeer noquery
restrict default nomodify
# nomodify客户端可以同步
# 将默认时间同步源注释改用可用源
# server 0.centos.pool.ntp.orgiburst
# server 1.centos.pool.ntp.orgiburst
# server 2.centos.pool.ntp.orgiburst
# server 3.centos.pool.ntp.orgiburst
server ntp1.aliyun.com
server time.nist.gov
启动ntp服务器
[root@oldboyedu ~]# /etc/init.d/ntpdstart
starting ntpd: [ ok ]
[root@oldboyedu ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp1.aliyun.com 10.137.38.86 2 u 22 64 1 525.885 -42.367 0.000
[root@oldboyedu ~]# ntpstat
synchronised to ntp server(110.75.186.247) at stratum 3
time correct to within 4257 ms
polling server every 64 s
[root@oldboyedu ~]# ntpdate10.0.0.9
7 dec 18:43:07 ntpdate[26950]: the ntp socketis in use, exiting
客户机要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示<code>no serversuitable for synchronization found</code>错误。
[root@zyops ~]# ntpdate 10.0.0.9
7 dec 18:40:16 ntpdate[1453]: step time server10.0.0.9 offset 40.880807 sec
# 将命令放入计划任务即可。