之前写的:Chrony时间同步服务器的搭建——筑梦之路_筑梦之路的博客-CSDN博客_搭建chrony服务器
linux 下部署NTP服务器 时间同步_筑梦之路的博客-CSDN博客
操作系统:centos7NTP 方式#作为客户端,同步公网的时间服务器
# 安装ntp服务
yum -y install ntpdate# 开始时间同步
ntpdate ntp3.aliyun.com定时任务:echo "*/5 * * * * /usr/sbin/ntpdate -u ntp3.aliyun.com"# 作为服务端,给局域网内主机提供时间同步服务
#配置ntp.conf
cat /etc/ntp.conf | grep -v ^# | grep -v ^$
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server cn.pool.ntp.org iburst
server cn.ntp.org.cn iburst
server 127.127.1.0
fudge 127.127.1.0 stratum 8
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor#启动服务并加入开机启动
systemctl enable ntpd --now#本机测试
ntpdate -u 127.0.0.1Chrony方式centos7 默认已安装#服务端配置文件cat /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.ntsc.ac.cn iburst # 在这里添加几个时间同步服务器
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server s1a.time.edu.cn iburst# 允许哪些NTP客户端通过本地网络同步主机的时间
allow 172.16.1.0/24# 本机没有同步任何主机时间的情况下,依然把本机作为时间源
local stratum 10
...systemctl restart chronyd && systemctl enable chronyd#客户端配置文件cat /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 # 0-3为系统默认时间服务器,注释掉
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 172.16.1.11 iburst # 添加指定的时间服务器
...systemctl restart chronyd上面的配置是把172.16.1.11作为时间服务器,本机同步172.16.1.11节点的时间验证:chronyc sources -v
输出的最后一行,有上面配置的IP,说明配置chronyd成功;输出IP前面有*号,则表示时间已经同步。
ntpd 和 chronyd 之间的区别
来自官方文档:第 18 章 使用 chrony 套件配置 NTP Red Hat Enterprise Linux 7 | Red Hat Customer Portal
chronyd
可以优于ntpd
:
chronyd
可以正常工作,其中对时间参考的访问是间歇性的,而ntpd
需要定期轮询时间引用才能正常工作。- 即使网络在较长时间内拥塞,chronyd
也能
表现良好。chronyd
通常可以更快准确地同步时钟。chronyd
能够快速适应时钟速率的突然变化,例如,由于碳粉电器温度的变化,ntpd
可能需要很长时间才能再次下降。- 在默认配置中,
chrony
d 从不调整时钟在系统启动时同步的时间,以便不设置其他正在运行的程序。ntpd
也可以配置为从不调整时间,但是它必须使用不同的调整时钟的方法,这种方法存在一些缺点,包括对时钟准确性的负面影响。chronyd
可以调整较大范围内 Linux 系统上的时钟速率,即使在时钟中断或不稳定的机器上运行。例如,在某些虚拟机上:chronyd
比较小,使用较少的内存,仅在需要时才会唤醒 CPU,这更有利于节能
chronyd
可以执行ntpd
不能执行的操作:
chronyd
支持隔离的网络,其中唯一的调整时间方法是手动输入。例如,管理员看一下时钟。chronyd
可以检查在不同更新中更正的错误,以估算计算机获得或丢失时间的速率,并随后使用此估算来调整计算机时钟。chronyd
支持降低实时时钟的增益或丢失率,例如维护关闭计算机时间的时钟。当系统引导时,它可以使用实时时钟调整时间值来设置系统时间。这些实时时钟设施目前仅在 Linux 系统上可用。chronyd
支持 Linux 上的硬件时间戳,允许在本地网络上进行非常准确的同步。
ntpd
可以执行chronyd
不能执行的操作:
ntpd
支持NTP
版本 4(RFC 5905)的所有工作模式,包括广播、多播和多播客户端和服务器。请注意,广播和多播模式本质上也不如普通服务器和客户端模式准确且安全性较低,因此通常应避免使用。ntpd
支持自动密钥协议(RFC 5906),用于通过公钥加密对服务器进行身份验证。请注意,该协议已被证明不安全,并可能替换为网络时间安全(NTS)规范的实施。ntpd
包含许多参考时钟的驱动程序,而chronyd
依赖于其他程序(如 gpsd )使用共享内存(SHM)或 Unix 域套接字(SOCK)从参考时钟访问数据。