多机部署之使用NTPD服务平滑同步时间

本文已在本人博客https://www.nsxsg.com/archives/82首发

多机部署之使用NTPD服务平滑同步时间

多机部署中时间的同步是很重要的,当然有人说了搞毛啊ntpdate命令直接同步不就完事了嘛。是的,这样的确可以达到同步时间的效果,但是会有一定的隐患,具体例子这里就不说明了,自行百度。下面就来介绍一下如何使用NTPD服务平滑同步时间。

  1. 检查是否安装NTPD服务

    rpm -q ntp
    

    有内容表示已经安装,如果没有,安装命令如下:

    yum install -y ntp
    
  2. 配置NTP服务为自启动

    chkconfig --list ntpd
    

    显示如下内容即可

    ntpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

  3. 使用ntpdate手动同步时间,免得时间相差太大,让ntpd不能正常同步

    ntpdate -u 202.112.10.36
    
  4. 配置内网NTP-Server(192.168.8.109),文件位置/etc/ntpd.conf,修改部分如下(多的添,原文件默认配置不做删除,不一样的进行修改)

    # 允许内网其他机器同步时间
    restrict 192.168.8.0 mask 255.255.255.0 nomodify notrap
    
    # 中国这边最活跃的时间服务器 : http://www.pool.ntp.org/zone/cn
    server 210.72.145.44 perfer   # 中国国家受时中心
    server 202.112.10.36             # 1.cn.pool.ntp.org
    
    
    # allow update time by the upper server
    # 允许上层时间服务器主动修改本机时间
    restrict 210.72.145.44 nomodify notrap noquery
    restrict 202.112.10.36 nomodify notrap noquery
    restrict 59.124.196.83 nomodify notrap noquery
    
    
    # 外部时间服务器不可用时,以本地时间作为时间服务
    server  127.127.1.0     # local clock
    fudge   127.127.1.0 stratum 10
    
  5. 重启服务

    /etc/init.d/ntpd restart
    
  6. 查看服务连接和监听

    netstat -autlnp | grep ntp
    

    出现如下即可

    udp 0 0 192.168.8.109:123 0.0.0.0:* 23103/ntpd

  7. 配置内网NTP-Clients,修改/etc/ntp.conf文件(此处贴出完整的不带注释的配置文件)

    driftfile /var/lib/ntp/drift
    
    restrict 127.0.0.1
    restrict -6 ::1
    
    
    # 配置时间服务器为本地的时间服务器
    server 192.168.8.109
    restrict 192.168.8.109 nomodify notrap noquery
    
    
    server  127.127.1.0     # local clock
    fudge   127.127.1.0 stratum 10
    
    
    includefile /etc/ntp/crypto/pw
    
    
    keys /etc/ntp/keys
    
  8. 使用ntpdate手动同步下时间

    ntpdate -u 192.168.8.109
    
  9. 几个命令

    ntpq -p #查看网络中的NTP服务器
    ntpstat #查看时间同步状态
    

参考文章:http://blog.csdn.net/xw_classmate/article/details/50611489

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值