在RHEL 7上使用Chrony设置时间同步
时间:2020-03-21 11:47:26 来源:igfitidea点击:
chronyd服务是在RHEL 7上同步时间的默认服务。
服务器配置
我们有两台RHEL 7.0服务器可用:
- srv1.rhce.local(10.8.8.71)
- srv2.rhce.local(10.8.8.72)
我们将配置服务器srv1和srv2,以与我们的中央NTP服务器ipa.rhce.local同步时间,并使用对等同步作为备份。
SELinux设置为强制模式。
Chronyd配置
在服务器srv1和srv2上都安装软件包:
[ALL]# yum install -y chrony
在服务器srv1上,打开“ /etc/chrony.conf”并添加指向NTP服务器的行,在本例中为ipa.rhce.local:
server ipa.rhce.local iburst peer srv2.rhce.local local stratum 10
服务器应将与服务器srv2的对等同步用作备份。
如果无法访问外部服务器,则最后一行使服务器能够使用内部本地硬件时钟。
当没有可用的时间服务器时,使用local表示本地时钟是第10层,从而使chrony使用本地时钟。
这很好,因为它确保我们可以在不使时钟混乱的情况下将服务器与Internet断开连接。
在服务器srv2上执行相同的操作,但是将对等地址替换为服务器srv1.
在两个服务器上启用并启动chronyd服务:
[ALL]# systemctl enable chronyd && systemctl start chronyd
确保已启用基于NTP的网络时间同步:
[ALL]# timedatectl set-ntp true
检查确认:
[srv1]# chronyc sources 210 Number of sources = 2 MS Name/IP address Stratum Poll Reach LastRx Last sample ========================================================================== ^* ipa.rhce.local 3 6 17 3 +252us[ +335us] +/- 1523ms =? srv2.rhce.local 0 6 0 10y +0ns[ +0ns] +/- 0ns