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

一、集群环境:

系统:CentOS7-minimal

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

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

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

[root@controller ~]# timedatectl
Local time: Tue 2018-07-24 00:27:53 CST
Universal time: Mon 2018-07-23 16:27:53 UTC
RTC time: Tue 2018-07-24 00:27:53
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes //NTP时间同步开启
RTC in local TZ: yes
DST active: n/a
  2.查看可获取的时区:timedatectl list-timezones

[root@controller ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa

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

timedatectl set-timezone Asia/Shanghai

4.设置时间日期等:

[root@controller ~]# timedatectl set-time “2018-07-19 18:08:08”
[root@controller ~]# timedatectl set-time “2018-07-19”
[root@controller ~]# timedatectl set-time “18:08:08”
  5.将硬件时钟设置为本地时区:

[root@controller ~]# timedatectl set-local-rtc 1
  6.将硬件时钟设置为协调世界时(UTC):

[root@controller ~]# timedatectl set-local-rtc 0
三、安装配置chrony

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服务

[root@controller ~]# systemctl enable chronyd.service
[root@controller ~]# systemctl start chronyd.service
  4.子节点安装:

[root@compute1 ~]# yum install -y chrony
  5.子节点配置:编辑 /etc/chrony.conf文件

[root@compute1 etc]# 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).

#修改 把其他远程同步节点全部注释,并添加主节点ip或者hosts
#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 controller iburst
四、验证同步服务是否搭建成功:

1.使用命令 chronyc sources

[root@compute1 etc]# chronyc sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample

^* controller 3 6 377 22 -5232us[-6125us] +/- 47ms
    注意:如果controller前为^? 可能是主节点防火墙开启,导致子节点无法进行时间同步。

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

[root@compute1 etc]# timedatectl
Local time: Mon 2018-07-23 23:41:49 CST
Universal time: Mon 2018-07-23 15:41:49 UTC
RTC time: Mon 2018-07-23 23:41:49
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes //此处如果为no说明NTP时钟为开启
RTC in local TZ: yes
DST active: n/a
  解决方法:关闭主节点防火墙

 2. 手动同步:

chronyc makestep
————————————————
版权声明:本文为CSDN博主「Dolphinsz」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Dolphinsz/article/details/81299253

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值