linux时钟同步ntp服务
操作方法
- 01以下是亲身实践的经验,供大家参考。 ntp服务有一个主配置文件在/etc/ntp.conf 
- 02driftfile /var/lib/ntp/drift 
- 03keys /etc/ntp/keys 
- 04logfile /var/log/ntp.log 
- 05restrict default kod nomodify notrap nopeer noquery 
- 06restrict -6 default kod nomodify notrap nopeer noquery 
- 07restrict 127.0.0.1 
- 08restrict -6 ::1 
- 09restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap 
- 10server 192.168.0.12(ntp服务器的IP地址) 
- 11server 0.centos.pool.ntp.org prefer 
- 12server 1.centos.pool.ntp.org 
- 13server 127.127.1.0 # local clock 
- 14fudge 127.127.1.0 stratum 10 
- 15配置详解:第一行restrict、default定义默认访问规则,nomodify禁止远程主机修改本地服务器配置,notrap拒绝特殊的ntpdq捕获消息,noquery拒绝btodq/ntpdc查询(这里的查询是服务器本身状态查询)。restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap这句是手动增加的,意思是从192.168.1.1-192.168.1.254的服务器都可以使用我们的NTP服务器来同步时间。server 192.168.146.225这句也是手动增加的,指明局域网中作为NTP服务器的IP;配置文件的最后两行作用是当服务器与公用的时间服务器失去联系时以本地时间为客户端提供时间服务。 /etc/ntp/step-tickers ntp服务用来同步时钟的服务器,直接写地址即可(一般我就在ntp.conf里面设置server项来实现) /etc/sysconfig/ntpd 这个文件中的SYNC_HWCLOCK是设置是否允许BIOS与系统时间进行同步。 1 # Set to 'yes' to sync hw clock after successful ntpdate 2 SYNC_HWCLOCK=no ntp服务使用的是udp的123端口,如果开启了防火墙要记得放开这个端口奥。 而且在启动ntp服务的机器上无法使用ntpdate进行时钟同步,且ntp服务在启动后大概要等 3分钟左右才能进行第一次同步。 正常的ntp服务启动日志如下: 在现网进行ntp服务重新部署且有较大的时间更新时请注意服务如果有心跳检测可能会影响到服务。 
