Linux时间同步服务NTP和Chrony

NTP

NTP全称Network Time Protocol网络时间协议,用于同步计算机时间,帮助计算机与时间服务器的时间保持一致,并支持使用加密确认的方式防止恶意协议攻击。

在Linux上,NTP并非默认安装,但其使用仍然非常简单,以CentOS为例:

安装:yum install ntp

启动:systemctl start ntpd

查看状态:systemctl status ntpd

设置开机启动:systemctl enable ntpd

Chrony

然而,在某些系统上,你可能无法安装NTP。

# yum install ntp

Repository AppStream is listed more than once in the configuration

Repository extras is listed more than once in the configuration

Repository PowerTools is listed more than once in the configuration

Repository centosplus is listed more than once in the configuration

上次元数据过期检查:0:04:58 前,执行于 2022年07月05日 星期二 17时42分21秒。

未找到匹配的参数: ntp

错误:没有任何匹配: ntp

这是因为传统的NTP已经成为过去式,NTP安装包已被安装源移除,取而代之的是Chrony。自CentOS 7.2后,官方正式使用chronyd服务代替原来的ntpd服务。

Chrony是网络时间协议(NTP)的另一种实现,是类Unix系统上NTP客户端和服务器的替代品。它可以通过NTP服务或者类似GPS时钟接收器的硬件级参考时钟来同步系统时钟,具有更好的时钟准确度,并且对于那些间歇性互联网连接的系统很有帮助。Chrony是免费开源的,并且支持GNU/Linux和BSD衍生版(比如:FreeBSD、NetBSD)、macOS和Solaris等。

具体来说,根据红帽文档,Chronyd与Ntpd的区别在于:

1. chronyd使用更好的算法,同步精度、速度与对系统的影响都比ntpd更好。

2. chronyd可以在更大的范围内调整系统时间速率,且能在时钟损坏或不稳定的计算机上正常工作。

3. 当网络故障时,chronyd仍能很好地工作,而ntpd必须定时轮询时间参考才能正常工作。

4. chronyd可以快速适应时钟速率的突然变化,ntpd则需要一段时间才能稳定。

5. chronyd提供对孤立网络的支持,手动输入校准时间,并通过算法计算实时时间,估计计算机增减时间的速率,从而调整时间。

Chronyd的唯一劣势可能仅在于其名称不如Ntp这般容易记忆。

Chrony的使用同样非常简单,以CentOS为例:

安装:yum install chrony

启动:systemctl start chronyd

查看状态:systemctl status chronyd

设置开机启动:systemctl enable chronyd

猜你喜欢

转载自blog.csdn.net/Dancen/article/details/125626790