• 图解CentOS7集群时钟同步chronyd


    概述

    对于物理机集群,需要使用统一的时间,本文使用时钟同步技术来实现

    图

    图解

    默认的 外部网络的 时钟服务器 在国外,速度较慢

    0.centos.pool.ntp.org
    1.centos.pool.ntp.org
    2.centos.pool.ntp.org
    3.centos.pool.ntp.org
    
    • 1
    • 2
    • 3
    • 4

    换成 国内的 时钟服务,速度较快

    ntp1.aliyun.com
    ntp2.aliyun.com
    ntp3.aliyun.com
    ……
    
    • 1
    • 2
    • 3
    • 4

    步骤

    1、修改时区

    每台机执行

    # 修改时区
    timedatectl set-timezone Asia/Shanghai
    # 设置硬件时钟为UTC时间
    timedatectl set-local-rtc 0
    # 启动NTP时间同步(含ntpd服务或chrony服务)
    timedatectl set-ntp true
    # 最后检查一下
    timedatectl
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    2、安装chrony

    每台机执行,查看有无安装chrony

    rpm -qa | grep chrony
    
    • 1

    每台机执行,安装chrony

    yum install -y chrony
    
    • 1

    每台机执行,设置chrony开机自启

    systemctl start chronyd
    systemctl enable chronyd
    systemctl status chronyd
    
    • 1
    • 2
    • 3

    3、选1台机作为时钟服务器

    以node100作为内网集群的时钟服务器,其它机与本机时间进行同步
    而本机与阿里云时间进行同步,配置chrony

    vim /etc/chrony.conf
    
    • 1

    做如下修改

    # 注释掉默认的4个ntp服务器,因为慢
    #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
    
    # 新加3个快的,是阿里云的ntp服务
    server ntp1.aliyun.com iburst
    server ntp2.aliyun.com iburst
    server ntp3.aliyun.com iburst
    
    # 允许所有主机从server端同步时间
    # Allow NTP client access from local network.
    allow all
    
    # 即使server端无法从互联网同步时间,也同步本机时间至client
    # Serve time even if not synchronized to a time source.
    local stratum 10
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    改完后,重启chrony服务

    systemctl restart chronyd
    
    • 1

    4、其他机器同步时间

    vim /etc/chrony.conf
    
    • 1

    注释掉默认的4个ntp服务器

    # 注释掉默认的4个ntp服务器
    #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 node100 iburst
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    改完后,重启chrony服务

    systemctl restart chronyd
    
    • 1

    检验:每台机同时发送date命令,看看时间是否一致


    Appendix

    英🔉中
    NTPNetwork Time Protocol网络时间协议
    chronkrɑːncomb. 时;时间
    RTCReal_Time Clock实时时钟
  • 相关阅读:
    win11-qt5.14配置
    10.01
    【MySQL】MySQL事务隔离机制与实现原理详解(MySQL专栏启动)
    标签类目体系(面向业务的数据资产设计方法论)-读书笔记8(完结)
    专利快速预审的办理流程
    虚幻引擎4利用粒子系统实现物体轨迹描绘2- 消除轨迹
    网红和主播们是用的什么美颜工具?深入剖析美颜sdk与美颜Api
    接口测试框架:Http+Requests(1)
    数据库范式理论
    基于SuperMap iObjects C++之地形凹凸点提取
  • 原文地址:https://blog.csdn.net/Yellow_python/article/details/127881552