linux ntp 同步时间



弑神linux机器时间同步方法:


(1) #/etc/init.d/ntpd stop先关闭本机的ntp服务

(2) #vim /etc/crontab 添加计划任务

0 3 ** *root ntpdate 219.238.221.31

(3) #vim /etc/sysconfig/ntpd#执行系统时间与硬件时间同步

SYNC_HWCLOCK=yes

(4) #clock -w将系统时间写入硬件

(5) #ntpq -p查看ntp服务状态信息

synchronised to NTP server(115.182.1.207) at stratum 3

time correct to within 112 ms

polling server every 1024 s

(6) #netstat -tunl|grep 123查看ntp端口

udp00 192.168.60.59:1230.0.0.0:*

udp00 118.26.227.59:1230.0.0.0:*

udp00 127.0.0.1:1230.0.0.0:*

udp00 0.0.0.0:1230.0.0.0:*

udp00 ::1:123:::*

udp00 :::123:::*

(7) #vim /etc/ntp.conf

restrict 127.0.0.1

restrict -6 ::1

restrict default kod nomodify notrapnopeer noquery

restrict -6 default kod nomodifynotrap nopeer noquery

driftfile /var/lib/ntp/drift

server ntp1.gyyx.cn

server ntp2.gyyx.cn

Server 219.238.221.31 prefer