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






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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/413727.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[bug] uni-app 支付宝小程序 上传文件uni.uploadFile 报错 errMsg: “uploadFile:fail 无效参数“

首先看报错 就挺奇怪的 uni.chooseImage返回的参数都没问题, H5上也能正常运行 看下我的uni.uploadFile函数 uni.uploadFile({url: baseUrl params_.url,name: file,filePath: params_.query.files,formData: param_,success: (res) > {uni.hideLoading() …

【bug】HbuilderX运行到微信小程序 报错

首先,大前提是代码本身在HbuilderX里运行H5是没问题的,不报错 。然后运行到微信小程序报错了。(注:以下所说小程序代指微信小程序)。 我来这里分享一下我报了什么错,怎么解决的和我浅薄的理解。 报错位置…

php 获取某个月的周一

今天有个朋友问了一个问题,最后解决了下,先整理记下来,后面用到了再说 function getMonday($month ){if(empty($month)){$month date("Y-m");}$maxDay date(t, strtotime($month."-01"));$mondays array();for($i1;…

Mac安装brew及报错处理办法

brew又叫Homebrew,官网安装方式 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" MacOS系统使用Homebrew官方地址时,报错: curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYS…

微信小程序复制到剪切板及换行问题

wxml <textarea type"text" v-model"copyContent" placeholder"请输入内容" style""/> <button type"default" click"copy">复制内容</button> data中声明变量 data(){return{copyContent: …

Object Tracking using OpenCV (C++/Python)(使用OpenCV进行目标跟踪)

本博客翻译搬运自https://www.learnopencv.com/object-tracking-using-opencv-cpp-python&#xff0c;用于初入目标跟踪的新手学习&#xff0c;转贴请注明&#xff01; 使用OpenCV进行目标跟踪&#xff08;C/Python&#xff09; 在本教程里&#xff0c;我们将学习OpenCV3.0中引…

Sublime Text 3 、WebStorm配置实时刷新

本文所用软件版本Sublime Text 3(Build 3143)、WebStorm 2017.2.4(Build #WS-172.4155.35)、Google Chrome v61.0.3163.100&#xff0c;其他版本软件配置过程可能不一样&#xff0c;请知悉&#xff01; 一.Google Chrome安装LiveReload插件 1.下载插件 LiveReload 2.1.0 链…

#0 scrapy爬虫学习中遇到的坑记录

python 基础学习中对于scrapy的使用遇到了一些问题。 首先进行的是对Amazon.cn的检索结果页进行爬取&#xff0c;很顺利&#xff0c;无碍。 下一个目标是对baidu的搜索结果进行爬取 1&#xff0c;反爬虫 1.1 我先对ROBOTSTXT_OBEY进行设置&#xff0c;结果找到了scrapy的默认参…

Sublime Text 3 、WebStorm配置护眼主题(浅绿色)

本文所用软件版本Sublime Text 3(Build 3143)、WebStorm 2017.2.4(Build #WS-172.4155.35)&#xff0c;其他版本软件配置过程可能不一样&#xff0c;请知悉&#xff01; 1.Sublime Text 3护眼主题 &#xff08;1&#xff09;下载配置文件 链接&#xff1a;http://pan.baidu.…

angular - 如何运行在起来 - 使用nginx

nginx下载地址&#xff0c;使用的是标准版的&#xff1a; 点击下载nginx nginx下载完后&#xff0c;解压 dist文件夹下面所有angular文件放入html文件夹中. 最后命令行cd到当前nginx.exe目录&#xff0c;启动命令&#xff1a;nginx 再配置一下conf文件夹下面的nginx.conf 再loc…

深度学习之Batch Normalization

1、Batch Normalization的引入 在机器学习领域有个很重要的假设&#xff1a;IID独立同分布假设&#xff0c;也就是假设训练数据和测试数据是满足相同分布的&#xff0c;这是通过训练数据获得的模型能够在测试集上获得好的效果的一个基本保障。在深度学习网络中&#xff0c;后一…

调用支付宝接口 alipay.data.bill.accountlog.query,提示:ISV权限不足

使用环境&#xff1a;正式环境 接口名称&#xff1a;alipay.data.bill.accountlog.query(支付宝商家账户账务明细查询) 提示&#xff1a;ISV权限不足&#xff0c;建议在开发者中心检查签约是否已经生效 参考&#xff1a; 支付宝商家账户账务明细查询接口文档 自己按照支付宝官…

工作309:uni-获取vuex里面的值

marketId:this.vuex_user.market_id

web自动化测试(java)---测试过程中遇到的错误合集

摸索测试&#xff0c;不管是安装、调测第一个用例都会遇到各种各样的问题&#xff0c;或是自己的问题或是程序本身设置问题 只有把所有问题记录下来&#xff0c;才对得起自己的经历 1、设置firefox的执行文件错误 Exception in thread "main" org.openqa.selenium.We…

CentOS7 3.项目持续交付脚本

#停止原有工程 ps -ef | grep demo | grep -v grep | awk {print $2} | xargs kill#删除原有工程 rm -rf /opt/app/demo.jar#解压压缩包指定文件&#xff0c;并存入指定路径 #tar -zxf 压缩包 -C 解压到的路径 压缩包中指定文件名 tar -zxf /opt/app/demo.tgz -C /opt/app .…

工作312:uni-弹出框显示数据

<template><view class"wrap"><u-form :model"form" :rules"rules" ref"uForm" :errorType"errorType"><u-form-item label"标题" label-width"140" style"margin-left:30rp…

mysql8优化实战

最近上线了一个10万户的管理系统&#xff0c;以前的客户没有这么多用户量&#xff0c;隐藏在代码中的慢sql渐渐显现出来了。 下面是我最近一周慢sql优化的总结&#xff1a; 多表sql优化、count sql优化、超过10 0000条limit优化一、多表sql优化 二、count sql优化 该表有21350…

工作317:uni-修改其他页面整体样式

<template><view class"wrap"><u-form :model"form" :rules"rules" ref"uForm" :errorType"errorType"><u-form-item label"标题" class"label-left" style"margin-left:30r…

工作318:uni-切换tabber修改状态修饰

onLoad() {/* 调用市场信息的接口 分别 vuex获取 其他三项 */this.$u.api.getTreasureList({marketId: this.vuex_user.market_id,pageNo: 1,pageSize: 20,type:this.current1,releaseBureau:this.releaseBureau,name:this.name}).then(res > {if (res.data.code 200) {thi…

字节跳动小程序支付接入

字节跳动小程序支付接入躺过的坑流程签名支付宝配置问题java福利躺过的坑 流程 小程序申请流程业务调用流程 签名 请求字节跳动接口的签名请求预下单返回验签 支付宝配置问题 流程 小程序申请流程 字节跳动小程序开通申请有个渠道秘钥类型选择RSA2和RSA&#xff0c;不管你选择…