• CentOS7 使用chrony搭建集群中的时间同步服务


    一、集群环境:

      系统:CentOS7-minimal

      集群中的两台主机ip:10.132.226.103/24  10.132.226.104/24

    二、CentOS7中时间相关命令timedatectl例子介绍:

      1.查看主机中的时间信息:timedatectl

    1 [root@controller ~]# timedatectl
    2       Local time: Tue 2018-07-24 00:27:53 CST
    3   Universal time: Mon 2018-07-23 16:27:53 UTC
    4         RTC time: Tue 2018-07-24 00:27:53
    5        Time zone: Asia/Shanghai (CST, +0800)
    6      NTP enabled: yes
    7 NTP synchronized: yes         //NTP时间同步开启
    8  RTC in local TZ: yes
    9       DST active: n/a

      2.查看可获取的时区:timedatectl list-timezones

    1 [root@controller ~]# timedatectl list-timezones
    2 Africa/Abidjan
    3 Africa/Accra
    4 Africa/Addis_Ababa
    5 ........

      3.设置本地时区:timedatectl set-timezone Asia/Shanghai

    1 # timedatectl set-timezone Asia/Shanghai

      4.设置时间日期等:

    1 [root@controller ~]# timedatectl set-time "2018-07-19 18:08:08"
    2 [root@controller ~]# timedatectl set-time "2018-07-19"
    3 [root@controller ~]# timedatectl set-time "18:08:08"

      5.将硬件时钟设置为本地时区:

    1 [root@controller ~]# timedatectl set-local-rtc 1

      6.将硬件时钟设置为协调世界时(UTC):

    [root@controller ~]# timedatectl set-local-rtc 0

     三、安装配置chrony

      1.主节点安装:

    1 [root@controller ~]# yum install -y chrony

        2.主节点配置:编辑 /etc/chrony.conf文件

    [root@controller ~]# vim /etc/chrony.conf
    
    # Use public servers from the pool.ntp.org project.
    # Please consider joining the pool (http://www.pool.ntp.org/join.html).
    #以下0.centos.pool.ntp.org等为远程时间同步服务器可自行更改
    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  
    #~~~~~~~~~~~省略若干~~~~~~~~#
    # Allow NTP client access from local network.
    #allow 192.168.0.0/16
    #修改!!!
    #此处添加子节点的IP
    allow 10.132.226.104/24
    #~~~~~~~~~~~省略若干~~~~~~~~#

      3.主节点重启NTP服务

    1 [root@controller ~]# systemctl enable chronyd.service
    2 [root@controller ~]# systemctl start chronyd.service

      4.子节点安装:

    1 [root@compute1 ~]# yum install -y chrony

      5.子节点配置:编辑 /etc/chrony.conf文件

     1 [root@compute1 etc]# vim /etc/chrony.conf
     2 
     3 # Use public servers from the pool.ntp.org project.
     4 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
     5 #修改 把其他远程同步节点全部注释,并添加主节点ip或者hosts
     6 #server 0.centos.pool.ntp.org iburst
     7 #server 1.centos.pool.ntp.org iburst
     8 #server 2.centos.pool.ntp.org iburst
     9 #server 3.centos.pool.ntp.org iburst
    10 server controller iburst

    四、验证同步服务是否搭建成功:

      1.使用命令 chronyc sources

    1 [root@compute1 etc]# chronyc sources
    2 210 Number of sources = 1
    3 MS Name/IP address         Stratum Poll Reach LastRx Last sample               
    4 ===============================================================================
    5 ^* controller                    3   6   377    22  -5232us[-6125us] +/-   47ms

        注意:如果controller前为^? 可能是主节点防火墙开启,导致子节点无法进行时间同步。

      可以也可以通过timedatectl命令查看:

    1 [root@compute1 etc]# timedatectl
    2       Local time: Mon 2018-07-23 23:41:49 CST
    3   Universal time: Mon 2018-07-23 15:41:49 UTC
    4         RTC time: Mon 2018-07-23 23:41:49
    5        Time zone: Asia/Shanghai (CST, +0800)
    6      NTP enabled: yes
    7 NTP synchronized: yes           //此处如果为no说明NTP时钟为开启
    8  RTC in local TZ: yes
    9       DST active: n/a

      解决方法:关闭主节点防火墙

     

  • 相关阅读:
    CentOS6.4 安装nmon
    CentOS6.4 访问域局网中Windows的共享
    将类似 12.56MB 36.89KB 转成 以K为单位的数字【备忘】
    ICE中间件相关
    HDFS介绍
    漫画描述HDFS工作原理
    离线安装Cloudera Manager 5和CDH5
    storm集群相关资料
    kafka相关资料
    jstatd
  • 原文地址:https://www.cnblogs.com/joy9707/p/9357728.html
Copyright © 2020-2023  润新知