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

安装

yum -y install chrony

两台主机:192.168.239.141(服务器)、192.168.239.142(客户端)
修改配置文件(服务器)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).
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

# 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

配置文件说明

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命令

启动服务

# 设置开机启动
[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

你可能感兴趣的:(linux,运维,服务器)