Linux/Centos ntp时间同步,联网情况和无网情况配置

机器联网:

如果服务器可以联网:执行 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”来同步时间

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

 如果对此有兴趣,请扫下面二维码免费获取更多详情,如果文章对您有帮助,请打赏博主一两毛钱。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值