局域网中使用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
相关推荐
活跃的煤矿打工人13 分钟前
【星海saul随笔】Ubuntu基础知识
linux·运维·ubuntu
北京智和信通1 小时前
云平台和虚拟化智慧运维监控,全面提升故障感知与处置能力
运维·虚拟化·云平台·虚拟机监控
fasewer1 小时前
第五章 linux实战-挖矿 二
linux·运维·服务器
楚灵魈1 小时前
[Linux]从零开始的网站搭建教程
linux·运维·服务器
小小不董1 小时前
《Linux从小白到高手》理论篇:深入理解Linux的网络管理
linux·运维·服务器·数据库·php·dba
豆豆2 小时前
为什么用PageAdmin CMS建设网站?
服务器·开发语言·前端·php·软件构建
这可就有点麻烦了2 小时前
强化学习笔记之【TD3算法】
linux·笔记·算法·机器学习
DY009J2 小时前
深度探索Kali Linux的精髓与实践应用
linux·运维·服务器
程序员-珍2 小时前
虚拟机ip突然看不了了
linux·网络·网络协议·tcp/ip·centos
什么鬼昵称3 小时前
Pikachu- Over Permission-垂直越权
运维·服务器