CentOS 8系统时间校准

本地搭建chrony服务器+所有客户端同步服务器时间

# 安装
yum install -y chrony
# 启动
systemctl start chronyd
# 注册成开机启动
systemctl enable chronyd

如上配置好了以后,现行配置文件的修改

vim  /etc/chrony.conf

配置文件如下:

# 使用pool.ntp.org项目中的公共服务器。以server开,理论上你想添加多少时间服务器都可以。
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 注释掉 server 0.centos.pool.ntp.org iburst
# 新增
server cn.ntp.org.cn iburst
server time.windows.com iburst

# 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。
driftfile /var/lib/chrony/drift

# chronyd根据需求减慢或加速时间调整,
# 在某些情况下系统时钟可能漂移过快,导致时间调整用时过长。
# 该指令强制chronyd调整时期,大于某个阀值时步进调整系统时钟。
# 只有在因chronyd启动时间超过指定的限制时(可使用负值来禁用限制)没有更多时钟更新时才生效。
makestep 1.0 3

# 将启用一个内核模式,在该模式中,系统时间每11分钟会拷贝到实时时钟(RTC)。
rtcsync

# Enable hardware timestamping on all interfaces that support it.
# 通过使用hwtimestamp指令启用硬件时间戳
#hwtimestamp eth0
#hwtimestamp eth1
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# 指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器
#allow 192.168.0.0/16
#deny 192.168/16
allow 0.0.0./0 # 允许所有

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

# 指定包含NTP验证密钥的文件。
#keyfile /etc/chrony.keys

#从system tz数据库中获取TAI-UTC偏移量和闰秒。
leapsectz right/UTC

# 指定日志文件的目录。
logdir /var/log/chrony

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

或者添加如下两行

server 210.72.145.44 iburst
server ntp.aliyun.com iburst

重新加载文件,同步时间,就能看到时间是正常的

systemctl restart chronyd.service    
chronyc sources -y

命令timedatectl

# 查看
timedatectl 
# 删除 localtime
rm /etc/locatime
# 从/usr/share/zoneinfo/中创建软连接以替换当前的时区信息
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 再次查看系统时间
timedatectl

 

posted @ 2021-10-25 10:12  netlock  阅读(1019)  评论(0编辑  收藏  举报