场景

CentOS7中怎样设置静态IP:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/119242495

在上面给三台CentOS7的服务器配置了静态IP的基础上,怎样配置时钟同步。

集群中时间不同步有可能会让大数据的应用程序运行混乱,造成不可预知的问题,比如Hbase、mongodb副本集等,Hbase当时间差别过大时就会挂掉,mongodb如果副本时间过快,会出现时间栈帧溢出提前出发选举等,所以在大数据集群中,ntp服务,应该作为一种基础的服务。

NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。

首先检查系统中是否已经安装ntp包

rpm -q ntp

如果没有安装的话自行进行安装。

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

在master主服务器上搭建ntp服务器

修改/etc/ntp.conf文件

vi /ntp.conf

修改为如下

修改内容

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
#restrict default nomodify notrap nopeer noquery# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
#restrict 127.0.0.1
#restrict ::1restrict 192.168.148.2 mask 255.255.255.0 nomodify notrap# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst#server 0.cn.pool.ntp.org
#server 1.asia.pool.ntp.org
#server 2.192.168.148.128server ntp1.aliyun.com
server time1.aliyun.comrestrict time1.aliyun.com nomodify notrap noquery
restrict ntp1.aliyun.com nomodify notrap noqueryserver 127.0.0.1
fudge 127.0.0.1 stratum 10
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient   # broadcast client
#broadcast 224.0.1.1 autokey  # multicast server
#multicastclient 224.0.1.1  # multicast client
#manycastserver 239.255.254.254  # manycast server
#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.
#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys# Specify the key identifiers which are trusted.
#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.
#requestkey 8# Specify the key identifier to use with the ntpq utility.
#controlkey 8# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

修改说明

IP地址从192.168.148.2  到192.168.254.254,默认网关为255.255.255.0的机器都可以从NTP服务器进行同步时间

restrict 192.168.148.2 mask 255.255.255.0 nomodify notrap

定义使用的上游ntp服务器,将原来的注释掉

server ntp1.aliyun.com
server time1.aliyun.com

允许上层时间服务器主动修改本机时间

restrict time1.aliyun.com nomodify notrap noquery
restrict ntp1.aliyun.com nomodify notrap noquery

外部时间不可用时,使用本地时间作为时间服务。

server 127.0.0.1
fudge 127.0.0.1 stratum 10

配置文件修改完成之后,重启服务

service ntpd restart

ntp同步状态查看

ntpstat 命令查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。

ntpstat

还可通过

ntpq -p

查询ntp是否同步

ntp客户端配置

两个子节点服务器slave1和slave2服务器分别修改配置

vi /etc/ntp.conf

将内容修改为

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
#restrict default nomodify notrap nopeer noquery# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
#restrict 127.0.0.1
#restrict ::1server 192.168.148.128
restrict 192.168.148.128 nomodify notrap noqueryserver 127.0.0.1
fudge 127.0.0.1 stratum 10
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient   # broadcast client
#broadcast 224.0.1.1 autokey  # multicast server
#multicastclient 224.0.1.1  # multicast client
#manycastserver 239.255.254.254  # manycast server
#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.
#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys# Specify the key identifiers which are trusted.
#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.
#requestkey 8# Specify the key identifier to use with the ntpq utility.
#controlkey 8# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

修改说明

配置时间服务器为上面搭建的ntp服务器

server 192.168.148.128

配置允许ntp服务器主动修改本机的时间

restrict 192.168.148.128 nomodify notrap noquery

同样配置本地服务器

server 127.0.0.1fudge 127.0.0.1 stratum 10

然后配置完成后同样重启服务

service ntpd restart

同样通过

ntpstat
ntpq -p

查看同步的状态

也可以单次进行手动同步测试效果

在客户端slave1上,首先停止ntpd的服务 ,不然会提示: the NTP socket is in use, exiting

service ntpd stop

然后同步一次时间

ntpdate 192.168.148.128

同步成功之后记得开启服务

service ntpd start

CentOS7中多台服务器配置时钟同步相关推荐

  1. CentOS7中多台服务器配置SSH免密钥登录

    场景 CentOS7中怎样修改主机名和hosts文件(配置IP和主机名的对应管理): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details ...

  2. I2C中的时钟同步与仲裁

    文章目录 时钟同步和仲裁 1.时钟同步 2.仲裁 时钟拉伸 系列文章 <I2C总线(1)–数据传输格式与7位地址读写>: <I2C总线(2)–10位地址读写>: <I2C ...

  3. 时钟同步和时钟修正的小技巧

    引入: 时钟同步一直是一个比较热的话题.因为它涉及到许多具体场景. 场景A: 2个系统做交易,A系统下订单,B系统管理订单.结果因为B系统比A慢5分钟,A下单完了,B获得的时间居然是一个未来的时间. ...

  4. 时钟同步技术解析:原子钟实现 Ture-time 机制

    导读 在分布式数据库系统中,为了解决不同集群.节点事件发生的先后顺序问题,时钟同步至关重要.本文将为大家介绍业界现有的几种主流的时钟同步解决方案,以及分布式数据库云溪数据库基于原子钟技术实现的 Tur ...

  5. 【LoRaWAN 时钟同步】

    本文主要介绍了 LoRaWAN 自组网协议.设备工作模式.设备间的时间同步问题 LoRaWAN 时钟同步 1. 前言 2. 设备数据收发 2.1 数据帧格式 2.2 数据发送 2.3 数据接收 3. ...

  6. 出入口控制系统工程设计规范_[问答]连载77-控制系统之间如何时钟同步?

    仪表小猪 在控制系统中,趋势.报警.事件记录等都与时间相关,因此整个系统始终保持一个统一的时钟很关键.如果操作站和控制站时间不同步,操作员站上面显示的事件.趋势等也不能真正的反应出现场实际变化的时间, ...

  7. I2C协议研读(三):仲裁和时钟同步

    6. 仲裁和时钟生成:ARBITRATION AND CLOCK GENERATION (1)同步化:Synchronization 所有主机在SCL线上生成自己的时钟,以在I2C总线上传输消息. 数 ...

  8. gPTP时钟同步(时间同步)协议简介

    一.时间同步要解决的问题 不知道大家还记得军训练习齐步走的场景吗? 齐步走的动作要领你还记得吗? • 教官首先发出"齐步-–走"的命令,大家听到"齐步"二字后, ...

  9. Centos7 NTP时钟同步配置

    Centos7 NTP时钟同步配置 NTP在Linux下有两种时钟同步方式:直接同步(也称跳跃同步)和平滑同步(也称微调同步). 直接同步 使用ntpdate命令进行同步,直接进行时间变更. 如果服务 ...

最新文章

  1. C#发现之旅第一讲 C#-XML开发
  2. tcp转串口_PROFIBUS DP与Modbus/TCP网络转换操作指南
  3. linux mpstat命令
  4. 使用动态代理,提高工作效率
  5. [YTU]_2627 (职工工资统计)
  6. electron调试html,electron桌面应用程序开发入门
  7. Redis 缓存常见问题:缓存一致性的解决方案
  8. JavaScript, ABAP和Scala里的尾递归(Tail Recursion)
  9. python 取一个字前的文本的_python删除某一行字符前面的内容
  10. 33Exchange Server 2010跨站点部署-分支机构邮件从分支机构出
  11. 您如何从Python的stdin中读取信息?
  12. android 联系数据库
  13. pthread_join来接收线程的返回参数
  14. Spring + Spring MVC + mybatis 下的 junit4 注入单元测试
  15. 使用alias简化命令输入
  16. 韩顺平的php东方航空_韩顺平PHP从入门到精通视频教程
  17. CSS 3 动画 实现图片动态切换
  18. 制作自己的印章,和自己的爱人表白纪念!
  19. JavaScript之切换背景图片(并使)背景栏保持和背景色调相似
  20. php语言进销存单位换算,单位换算工具(在线换算单位器)

热门文章

  1. 轻轻松松明白什么是反射,反射有什么用,简单上手反射以及反射的优缺点
  2. Unity 3D 2019.3.12版本创建一个按钮,并为该按钮添加点击Click的消息响应函数以及点击按钮切换场景
  3. 河南省计算机大学应用水平考试,河南省大学计算机等级考试选择题(文管二级)...
  4. 数学建模c语言仿真软件,数学建模十五大经典数学模型
  5. Lambda使用——JDK8新特性
  6. spring BeanPostProcessor,BeanFactoryPostProcessor作用
  7. WinCE中的Data/ Prefetch Abort异常定位
  8. mysql中shift h_MySQL复制技术对比与容器化探究
  9. 科技边框_又一种新折叠屏曝光:极窄边框更具科技感
  10. vscode创建工作区_区民政局党员干部下沉社区,积极参与文明创建工作