centos7 时间同步服务部署

查看日期时间、时区及 NTP 状态

timedatectl

Centos7 默认使用 chrony 作为时间同步服务

#修改配置文件
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 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org 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 10.0.0.0/8

# 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

配置完成后 需要重启服务

systemctl restart chronyd.service

#启用服务
systemctl enable chronyd.service

其他内网客户端把同步服务器改为此服务器即可

客户端设备配置文件

server 172.28.12.1 iburst

driftfile /var/lib/chrony/drift
makestep 1.0 3

rtcsync

logdir /var/log/chrony

参考命令


#校准时间服务器
chronyc tracking
chronyc tracking -a #强制同步一次,默认时间差超过3秒 无法自动同步


#查看时间同步源
chronyc sources -v


#在客户端报告已访问到服务器
chronyc clients 

#查看 ntp server 是否在线
chronyc activity -v