机器联网:

如果服务器可以联网:执行 ntpdate 1.cn.pool.ntp.org 服务器就会自动同步时间 写一个计划任务 每俩分钟执行一次时间同步;

crontab -e

*/2 * * * * /usr/sbin/ntpdate 1.cn.pool.ntp.org //这样就可以实现时间同步

下面是国内的NTP Server 1.cn.pool.ntp.org 2.cn.pool.ntp.org 3.cn.pool.ntp.org 0.cn.pool.ntp.org cn.pool.ntp.org tw.pool.ntp.org 0.tw.pool.ntp.org 1.tw.pool.ntp.org 2.tw.pool.ntp.org 3.tw.pool.ntp.org

如果不能联网 则需要配置ntpserver ntp的包系统默认安装 服务名叫ntpd

配置文件/etc/ntp.conf 添加以下几行 restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery restrict 127.0.0.1 restrict -6 ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap //意思是从192.168.1.1-192.168.1.254的服务器都可以使用我们的NTP服务器来同步时间。 server 192.168.1.12 //指明局域网中作为NTP服务器的IP 不能联网的话 写本机就可以
server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 //配置文件的最后两行作用是当服务器与公用的时间服务器失去联系时以本地时间为客户端提供时间服务

NTP客户端配置:在客户端手动执行“ntpdate 192.168.1.12”来同步时间

然后写计划任务定时同步时间 同上

如果对此有兴趣,请扫下面二维码免费获取更多详情