局域网中使用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
相关推荐
檀越剑指大厂14 分钟前
【Python系列】异步 Web 服务器
服务器·前端·python
楚疏笃16 分钟前
linux安全管理-账号口令
linux·服务器·安全
Hello Dam17 分钟前
基于 Spring Boot 实现图片的服务器本地存储及前端回显
服务器·前端·spring boot
LightOfNight18 分钟前
Redis设计与实现第14章 -- 服务器 总结(命令执行器 serverCron函数 初始化)
服务器·数据库·redis·分布式·后端·缓存·中间件
沐多18 分钟前
linux实时操作系统xenomai看门狗(watchdog)机制及作用介绍
linux·xenomai·实时linux
孤邑18 分钟前
【Linux】网络通信
linux·服务器·网络·笔记·学习
qq_4489410821 分钟前
1、正则表达式
linux·正则表达式
9毫米的幻想28 分钟前
【Linux系统】—— 基本指令(四)
linux·c语言·c++·学习
cykaw259030 分钟前
Linux和Ubuntu的关系
linux·运维·服务器
安替-AnTi32 分钟前
linux远程多开jupyter notebook
linux·jupyter·远程·多开