• 图解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实时时钟
  • 相关阅读:
    如何找回这个辅助窗口
    动态内存管理
    在vue项目中使用less全局变量
    LeetCode刷题之数组篇(三)
    [附源码]Python计算机毕业设计Django高校实验室仪器设备管理系统
    maven 常用知识速记
    javascript中的new原理及实现
    豆包MarsCode Agent 登顶 SWE-bench Lite 评测集
    Docker(七)—— 如何制作自己的镜像
    X3E伺服转矩模式参数设置
  • 原文地址:https://blog.csdn.net/Yellow_python/article/details/127881552