chrony时间同步

本文介绍了在微服务架构中,如何使用chrony进行时间同步,包括公网设备通过阿里云时间服务器同步,以及内网设备通过指定IP服务器同步的方法,并解释了chrony的timedrift概念。
摘要由CSDN通过智能技术生成
1.需求

公司的平台采用的是微服务平台,不下20个,所以日常排查的时候会调取多个服务的日志,时间就是排查的重要依据,时间同步的重要性不言而喻。

linux日常使用的时间同步器有两种ntp、chrony,个人建议使用chrony,为什么,简单!!!

2.时间同步
2.1 公网设备

下载chrony

[root@localhost ~]# yum -y install chrony

修改chrony配置文件chrony.conf,设置同步阿里云时间服务器

[root@localhost ~]# 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).
server ntp.aliyun.com iburst
#同步阿里云时间
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
allow all
#允许所有服务器访问
# Serve time even if not synchronized to a time source.
local stratum 10
#默认情况下当主机无法同步到时间源时,无法向下级同步时间,开启后可以向下级知己提供时间同步服务
# Specify file containing keys for NTP authentication.
keyfile /etc/chrony.keys

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

开启chrony服务

[root@localhost a]# systemctl start chronyd
[root@localhost a]# systemctl enable chronyd
2.2 内网设备时间同步

服务器在内网的同学应该怎么办呢,是这样的,一般情况下当公司服务器较多,且在内网环境下,那么公司一般会具有一台时间同步服务器,只需要询问相关人员即可。但我这种就很拉,没有时间同步服务器,怎么办,找领导,让领导放开323 123端口,链接阿里云就好。

想的很好,但是领导不会让你很舒服,只给你放开一台,搭建一台时间同步器,其余的去同步时间同步器,我直接哭死,还好比较简单

chrony server端配置与上面的一致

chrony client端配置

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.40.184 iburst
#服务端IP
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#allow 192.168.0.0/16

# Serve time even if not synchronized to a time source.
local stratum 10

# Specify file containing keys for NTP authentication.
keyfile /etc/chrony.keys

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

注:Chrony使用一种被称为"时间漂移"(time drift)的概念来调整系统时钟,以逐渐将其与NTP服务器的时间同步。

故当你使用date -s改变时间后,你会发现时间并没有恢复成服务端的时间,可以仔细观察下,客户端与服务端的时间差距会一点点的缩小。

或者重启chrony会直接同步

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值