zoukankan      html  css  js  c++  java
  • NTP服务器时间同步


    一、简要说明
    二、安装步骤
    三、配置文件
    四、常用命令
    五、注意事项
    六、运行截图
    七、参考资料


    一、简要说明
              搭建Kubernetes环境,需要几台、几十台机器配合运作,许多集群服务比如Etcd等都依赖系统的时间,如果机器的系统时间不一致,可能会出现各种问题。因此有必要统一集群内所有服务器的系统时间。

              NTP(Network Time Protocol)可以很方便的解决服务器之间的时间同步问题,Ubuntu系统下NTP安装也很方便,经过测试,在Ubuntu 16.04环境下,直接安装NTP服务,使用Ubuntu系统自带的pool ntp.ubuntu.com 时间服务器地址池,就可以实现时间同步。用户也可以选择NTP官方网站推荐的pool pool.ntp.org地址池,或者选择中国区的pool cn.pool.ntp.org地址池,都会生效的。

              用户还可以选择集群中的1台作为主授时服务器(NTP 服务器角色),通过配置文件中的pool 地址池与上层的服务器同步时间,集群内所有其他机器(NTP客户端角色)的NTP配置文件中,使用Server xx.xx.xx.xx形式,明确指向主授时服务器IP地址,也可以实现为集群提供统一的时间服务。如果考虑高可靠性,还可以将多台服务器作为集群的授时服务器。

             也可以到www.ntp.org网站中查找中国区的服务器地址,直接在NTP配置文件中使用这些地址,比如 server  xx.xx.xx.xx 。

             下面的例子中,我们使用到的服务器信息:
               服务器名   IP地址                 角色
               rancher2   192.168.3.220   NTP 服务器
               node221    192.168.3.221   NTP 客户端
        
    二、安装步骤
    #在集群的所有机器上安装NTP相关程序即可
    sudo apt install ntp ntpdate ntpstat

    三、配置文件
    #3.1 NTP 主授时服务器(192.168.3.220)配置文件/etc/ntp.conf去除注释后的内容:
    driftfile /var/lib/ntp/ntp.drift

    statistics loopstats peerstats clockstats
    filegen loopstats file loopstats type day enable
    filegen peerstats file peerstats type day enable
    filegen clockstats file clockstats type day enable

    server 1.networktime.org iburst
    server 2.networktime.org iburst
    server ntp.synet.edu.cn iburst
    server ntp.neu6.edu.cn iburst
    server ntp.gwadar.cn iburst
    server ntp.neu.edu.cn iburst

    restrict -4 default kod notrap nomodify nopeer limited
    restrict -6 default kod notrap nomodify nopeer limited
    restrict 127.0.0.1
    restrict ::1
    restrict source notrap nomodify noquery

    #3.2 NTP 客户端服务器(192.168.3.221)配置文件/etc/ntp.conf去除注释后的内容:
    driftfile /var/lib/ntp/ntp.drift

    statistics loopstats peerstats clockstats
    filegen loopstats file loopstats type day enable
    filegen peerstats file peerstats type day enable
    filegen clockstats file clockstats type day enable

    server 192.168.3.220 iburst

    restrict -4 default kod notrap nomodify nopeer limited
    restrict -6 default kod notrap nomodify nopeer limited
    restrict 127.0.0.1
    restrict ::1
    restrict source notrap nomodify noquery

    #3.3 其他地址池和授时服务器地址参考
    #3.3.1===Ubuntu 16.04系统默认的地址池===

    pool ntp.ubuntu.com

    pool 0.ubuntu.pool.ntp.org
    pool 1.ubuntu.pool.ntp.org
    pool 2.ubuntu.pool.ntp.org
    pool 3.ubuntu.pool.ntp.org

    #3.3.2===www.pool.ntp.org官网上推荐的地址池===
    pool pool.ntp.org

    pool 0.pool.ntp.org
    pool 1.pool.ntp.org
    pool 2.pool.ntp.org
    pool 3.pool.ntp.org

    #3.3.3===中国区地址池===
    pool cn.pool.ntp.org

    pool 0.cn.pool.ntp.org
    pool 1.cn.pool.ntp.org
    pool 2.cn.pool.ntp.org
    pool 3.cn.pool.ntp.org

    #3.3.4===www.ntp.org官网上提供的中国区服务器地址===

    server 1.networktime.org
    server 2.networktime.org
    server ntp.synet.edu.cn
    server ntp.neu6.edu.cn
    server ntp.gwadar.cn
    server ntp.neu.edu.cn


    四、常用命令

    #停止NTP服务
    sudo service ntp stop

    #只查询、不更新本机系统时间
    sudo ntpdate -q pool.ntp.org

    #使用debug(-d)模式查询详细更新信息
    sudo ntpdate -d pool.ntp.org

    #直接与pool.ntp.org中的服务器同步本机系统时间
    sudo ntpdate pool.ntp.org

    #查询NTP连接上层授时服务器的状态
    nptq -p

    #启动NTP服务
    sudo service ntp start

    #查询ntp运行状态
    sudo ntpstat

    #查看系统时间
    date
    #设置系统时间的日期为2018年07月09日08点44分30秒
    sudo date -s "2018/07/09 08:44:30"

    #查看硬件时间
    sudo hwclock  --show
    #设置硬件时间
    sudo hwclock --set --date="07/09/18 14:55:30"

    #使用硬件时间同步系统时间
    sudo hwclock --hctosys
    #使用系统时间同步硬件时间
    sudo hwclock --systohc


    五、注意事项
          1、NTP服务和ntpdate命令不可同时使用。使用ntpdate之前,一定要先停止NTP服务。启用NTP服务之前,应先使用ntpdate命令 同步一下服务器时间,或者直接使用date命令设置系统时间,以免服务器时间相差太大,NTP服务不起作用。
          2、注意互联网授时服务器地址是否可用?正式使用之前,可以使用ntpdate 验证一下,是否可以同步时间。
          3、除了Linux自带的防火墙要打开UDP123端口外,网络出口防火墙也要打开UDP123端口!这样运行ntpdate同步时间时,才不会出现“no server suitable for synchronization found”错误。

    六、运行截图

    图01-Rancher2主授时服务器配置文件-与上层的中国区的服务器地址进行同步

    01-Rancher2主授时服务器配置文件-与上层的中国区的服务器地址进行同步

    图02-Rancher2主授时服务器同步结果

    02-Rancher2主授时服务器同步结果

    图03-NTP客户端服务器node221,配置文件指向主授时服务器

    03-NTP客户端服务器node221,配置文件指向主授时服务器

    图04-NTP客户端服务器node221时间同步结果

    04-NTP客户端服务器node221时间同步结果

    图05-使用Ubuntu系统自带的NTP地址池pool,能够正常同步时间

    05-使用Ubuntu系统自带的NTP地址池pool,能够正常同步时间

    图06-使用pool.ntp.org地址池也是能正常同步时间的

    06-使用pool.ntp.org地址池也是能正常同步时间的

    图07-使用中国区的地址池cn.pool.ntp.org 也是可以同步时间的

    07-使用中国区的地址池cn.pool.ntp.org 也是可以同步时间的

    图08-使用nslookup查询cn.pool.ntp.org地址池域名的地址信息

    08-使用nslookup查询cn.pool.ntp.org地址池域名的地址信息

    图09-NTP相关配置文件位置

    09-NTP相关配置文件位置


    七、参考资料

    Linux NTP配置详解 (Network Time Protocol)
    https://blog.csdn.net/iloli/article/details/6431757

    Linux的NTP配置总结
    https://www.cnblogs.com/kerrycode/archive/2015/08/20/4744804.html

    部署NTP服务器进行时间同步
    https://www.cnblogs.com/linypwb/p/5532535.html

    NTP服务配置
    http://blog.sina.com.cn/s/blog_4612ed51010124e2.html

    NTP时间同步问题
    https://blog.csdn.net/sinat_36384705/article/details/73826408

    How to Configure NTP for Use in the NTP Pool Project on Ubuntu 16.04
    https://www.digitalocean.com/community/tutorials/how-to-configure-ntp-for-use-in-the-ntp-pool-project-on-ubuntu-16-04

    查找中国区授时服务器
    http://support.ntp.org/bin/view/Servers/StratumOneTimeServers
    http://support.ntp.org/bin/view/Servers/PublicTimeServer000934
    http://support.ntp.org/bin/view/Servers/PublicTimeServer001036
    http://support.ntp.org/bin/view/Servers/PublicTimeServer000893
    http://support.ntp.org/bin/view/Servers/StratumTwoTimeServers
    http://support.ntp.org/bin/view/Servers/PublicTimeServer001465
    http://support.ntp.org/bin/view/Servers/PublicTimeServer000794
    http://support.ntp.org/bin/view/Servers/PublicTimeServer001466
    http://support.ntp.org/bin/view/Servers/PublicTimeServer000781
    http://support.ntp.org/bin/view/Servers/PublicTimeServer000782
    http://support.ntp.org/bin/view/Servers/PublicTimeServer001237

    How do I use pool.ntp.org
    http://www.pool.ntp.org/zh/use.html

    关于ntp时间同步理论及配置参数
    https://blog.csdn.net/qq_32748887/article/details/76690944

    NTP的配置总结(整理+转载)
    https://blog.csdn.net/gycool21/article/details/51746174

    解决ntp的错误 no server suitable for synchronization found
    http://www.blogjava.net/spray/archive/2008/07/10/213964.html






  • 相关阅读:
    Some bugs in CE6
    WINCE知识点滴
    多个设备共享同一个硬件中断
    磁盘分区详解
    开发串口驱动程序
    CE BSP开发入门之重要的配置文件
    boost pcre Greta RE2 正则表达式性能测试
    Python GIL
    Oracle Instant Client 安装
    C++ 与 python 整数除法差异
  • 原文地址:https://www.cnblogs.com/rancher-maomao/p/9309990.html
Copyright © 2011-2022 走看看