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

一、简要说明
          搭建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主授时服务器配置文件-与上层的中国区的服务器地址进行同步

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

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

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

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

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

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

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

图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

转载于:https://www.cnblogs.com/rancher-maomao/p/9309990.html

NTP服务器时间同步相关推荐

  1. 配置NTP服务器时间同步

    配置NTP服务器时间同步 ntp服务端:192.168.200.175 [root@es-0003 user1]# yum install -y ntp #安装ntp #修改/etc/ntp.conf ...

  2. NTP服务器时间同步部署 -- 内网环境下,亲测有效.

    1.服务端操作(主服务器) 选定主节点为NTP服务器,其他服务器时间均以此为准. 比如当前我选择 192.168.6.3作为NTP服务器  1.1下载ntp服务端: [命令]yum -y instal ...

  3. NTP服务器时间同步设置

    1)时间服务器配置(必须root用户) (1)在所有节点关闭ntp服务和自启动 sudo systemctl stop ntpdsudo systemctl disable ntpd (2)修改ntp ...

  4. 如何用ntp实现服务器时间同步!!!

    如何用ntp实现服务器时间同步!!! 什么是NTP 一.ntp服务器时间同步 1.获取阿里云服务器时间同步到服务器 2.同步服务器 什么是NTP NTP是用来使计算机时间同步化的一种协议,全称是Net ...

  5. win2016开启ntp_WinServer 2016域控设置NTP服务器

    我们公司里都应该有NTP服务器,这样所有的客户端都指向这台NTP服务器,时间就会都同步了,我们使用域控作为一台NTP服务器,并且域控会像外网上的NTP服务器同步时间,而内部的客户端都指向这台域控去获取 ...

  6. 域控ntp服务器配置,Win1216域控设置NTP服务器

    Win12&16域控设置NTP服务器 发布时间:2020-08-03 23:04:55 来源:51CTO 阅读:387 作者:kangl PDC: 指定外部时间源并与之同步,在PDC所在的域控 ...

  7. ubuntu20开启NTP服务器操作步骤

    这里写目录标题 验证是否安装ntp 开启ntp服务器步骤 1.编辑配置文件 2.放开端口 3.重启NTP服务 客户端测试 linux 设置客户端定时更新 windows10 验证是否安装ntp ntp ...

  8. Ubuntu 系统设置同步NTP服务器

    环境: ubuntu 任何的系统 服务器端安装ntp(以此服务器时间为准) 1.配置成NTP服务器 apt update apt -y install upgrade apt-get install ...

  9. ntp服务器部署和配置文件

    需要注意的几点: 1.自己配置的NTP是需要设置上层服务器来进行时间同步的,172.25.23.250主机通过另一块网卡可以上网,使用的上层主机是cn.ntp.org.cn ; 2.NTP服务器和上层 ...

最新文章

  1. 为何说“内容+社交”是奥运发展化趋势?
  2. android studio 跳转后保留原页面数据_Intent详解以及Activity的跳转与数据传递
  3. 在python中给自己介绍对象笔记--OO面向对象
  4. centos7 时间设置
  5. Codeforces 360E 贪心 最短路
  6. Nginx下Uwsgi模块常用参数说明
  7. 数据分析师教你如何用Python向心仪的小姐姐表白
  8. json数据格式分析
  9. NodeJS连接MySQL
  10. 如何在Ubuntu MATE 18.04中安装GNOME 3?
  11. 关于I2C调试过程中遇到的一些细节性的问题(包括定位Master read-->Slaver send不成功的问题)
  12. 从零基础到web前端工程师(三)
  13. 手机链游撼动腾讯王者荣耀?Nova Battles更具潜力
  14. saas php7框架开源,HRM SAAS v2.5.7 – PHP人力资源管理系统SaaS平台版
  15. 吴恩达机器学习笔记——含一个隐藏层的神经网络
  16. c语言搬石头 有100块石头,成语大挑战 一个人搬着一块大石头 答案是什么成语...
  17. 智能BI,如今走到了哪一步?
  18. 微型计算机原理8255并行接口实验,微机原理实验二 8255A并行接口应用.pdf
  19. 计算机在英语写作中应用,多媒体计算机技术在初中英语写作中应用.doc
  20. 风机变速箱_1.5MW风机变速箱维修成本分析

热门文章

  1. ARM 汇编学习——编写简单的ARM汇编程序
  2. Linux 系统应用编程——网络编程(TCP/IP 数据包格式解析)
  3. React开发(274):ant design 时间显示秒
  4. [react-router] react的路由和普通路由有什么区别?
  5. [react] react父子组件如何通信?
  6. React开发(186):react 父调用子组件的方法
  7. JS中的异步任务有哪些
  8. 工作408- Module build failed (from ./node_modules/sass-loader/dist/cjs.js)
  9. PS教程第二课:PS安装
  10. [html] HTML5拖拽事件的顺序是什么?