多机部署之使用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

猜你喜欢

转载自blog.csdn.net/qq_39014761/article/details/85158901
今日推荐