局域网中使用chrony使得Linux集群时间同步

安装

bash 复制代码
yum -y install chrony

两台主机:192.168.239.141(服务器)、192.168.239.142(客户端)

修改配置文件(服务器)vim /etc/chrony.conf

bash 复制代码
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 192.168.239.141 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 10.251.149.0/24

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

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

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

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

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

修改客户端:192.168.239.142

vim /etc/chrony.conf

bash 复制代码
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 10.251.149.40 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 10.251.149.0/24

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

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

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

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

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

配置文件说明

bash 复制代码
server
可用于时钟服务器,iburst 选项当服务器可达时,发送一个八个数据包而不是通常的一个数据包。 包间隔通常为2秒,可加快初始同步速度,这个可以添加外网服务器或者内网服务器,域名或者IP都可以。

driftfile
根据实际时间计算出计算机增减时间的比率,将它记录到一个文件中,会在重启后为系统时钟作出补偿

stratumweight
stratumweight指令设置当chronyd从可用源中选择同步源时,每个层应该添加多少距离到同步距离。默认情况下,CentOS中设置为0,让chronyd在选择源时忽略源的层级。

rtcsync
启用内核模式,系统时间每11分钟会拷贝到实时时钟(RTC)

allow / deny
指定一台主机、子网,或者网络以允许或拒绝访问本服务器

cmdallow / cmddeny
可以指定哪台主机可以通过chronyd使用控制命令

bindcmdaddress
允许chronyd监听哪个接口来接收由chronyc执行的命令

makestep
通常chronyd将根据需求通过减慢或加速时钟,使得系统逐步纠正所有时间偏差。在某些特定情况下,系统时钟可能会漂移过快,导致该调整过程消耗很长的时间来纠正系统时钟。该指令强制chronyd在调整期大于某个阀值时调整系统时钟

local stratum 10
即使server指令中时间服务器不可用,也允许将本地时间作为标准时间授时给其它客户端chronyc命令

启动服务

bash 复制代码
# 设置开机启动
[root@x~]# systemctl enable chronyd.service
# 重启服务
[root@x~]# systemctl restart chronyd.service
# 查看时间同步状态
[root@x~]# timedatectl status

# 手动强制同步下系统时钟
[root@x~]# chronyc -a makestep
# 查看时间同步源
[root@x~]# chronyc sources -v
# 查看时间同步源状态
[root@x~]# chronyc sourcestats -v
# 硬件时间默认为UTC
[root@x~]# timedatectl set-local-rtc 1
相关推荐
Lonwayne1 分钟前
Web服务器技术选型指南:主流方案、核心对比与策略选择
运维·服务器·前端·程序那些事
法迪14 分钟前
Linux电源管理(2)_常规的电源管理的基本概念和软件架构
linux·运维·服务器·功耗
Selina K26 分钟前
界面打印和重定向同时实现
linux
JhonKI38 分钟前
【Linux网络】构建与优化HTTP请求处理 - HttpRequest从理解到实现
linux·网络·http
古德赖可可38 分钟前
chrony服务器(2)
linux·运维·服务器
码码哈哈0.01 小时前
同样开源的自动化工作流工具n8n和Dify对比
运维·开源·自动化
running thunderbolt1 小时前
Linux:基础IO && 文件系统
linux·运维·性能优化
yangshuo12811 小时前
风车邮箱系统详细使用指南:Windows与Ubuntu双平台解析
linux·windows·ubuntu
GOATLong1 小时前
网络基础概念
linux·运维·服务器·网络·arm开发·c++
谢平康2 小时前
ubuntu扩展逻辑卷并调整文件系统大小步骤
linux·运维·ubuntu