时间同步服务

chrony介绍

chrony 的优势:

  • 更快的同步只需要数分钟而非数小时时间,从而最大程度减少了时间和频率误差,对于并非全天 24 小时运行的虚拟计算机而言非常有用
  • 能够更好地响应时钟频率的快速变化,对于具备不稳定时钟的虚拟机或导致时钟频率发生变化的节 能技术而言非常有用
  • 在初始同步后,它不会停止时钟,以防对需要系统时间保持单调的应用程序造成影响
  • 在应对临时非对称延迟时(例如,在大规模下载造成链接饱和时)提供了更好的稳定性
  • 无需对服务器进行定期轮询,因此具备间歇性网络连接的系统仍然可以快速同步时钟

chrony官网:https://chrony.tuxfamily.org

chrony官方文档:https://chrony.tuxfamily.org/documentation.html

chrony 文件组成

包:chrony

两个主要程序:chronyd和chronyc chronyd:

  • 后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算 机增减时间的比率,并对此进行补偿
  • chronyc:命令行用户工具,用于监控性能并进行多样化的配置。它可以在chronyd实例控制的计 算机上工作,也可在一台不同的远程计算机上工作
  • 服务unit 文件: /usr/lib/systemd/system/chronyd.service

监听端口: 服务端: 123/udp,客户端: 323/udp

配置文件: /etc/chrony.conf

安装包:

yum -y install chrony

启动服务并开机自启

systemctl enable --now chronyd.service

更改配置文件

[root@CentOS8-8 ~]# 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 ntp.aliyun.com iburst     #设置阿里时间同步
server time1.cloud.tencent.com iburst
server 210.72.145.44 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.0.0.0/24 #作为公司内部服务器更改为同一网段 如果是客户端不需要更改

# Serve time even if not synchronized to a time source.
local stratum 10  #作为服务器端更改                                                                                   

查看时间同步详细信息

chronyc sources -v

将时间改错,稍等几分钟会自动同步

date -s '-1 year'

作为客户端

[root@centos7-7 ~]# 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 10.0.0.8 iburst  #指定服务地址

注意:重启服务

systemctl restart chronyd

 

posted @ 2021-01-19 14:07  浩浩呀  阅读(201)  评论(0)    收藏  举报