在Linux服务器中如果咱们心愿所有Linux服务器都具备正确的工夫,则必须配置一些NTP客户端,该客户端将始终从近程NTP服务器获取正确的工夫。装置chrony应用上面命令在Centos8中装置chrony:[root@server1 ~]# yum -y install chrony
chrony装置实现之后,会有两个可执行程序:chronyc: chrony命令行工具chronyd: chrony的守护过程Chrony的配置文件Chrony的配置文件是/etc/chrony.conf,上面列出了示例chrony.conf文件:[root@server1 ~]# cat /etc/chrony.conf
pool 2.centos.pool.ntp.org iburst chrony将从中获取工夫的近程NTP服务器。driftfile /var/lib/chrony/drift 零碎时钟频率都有小小的误差,这个就是为什么计算机运行一段时间后工夫会不准确。NTP会主动来监测咱们时钟的误差值并予以调整,所以它会把记录下来的误差先写入driftfile,重新启动零碎后,之前的计算结果也就不会失落了。keyfile /etc/chrony.keys 该文件蕴含用于NTP身份验证的密钥。logdir /var/log/chrony 它是记录Chrony的日志文件。测试chrony就像ntpdate命令一样,咱们能够应用chronyd手动将Linux服务器的工夫与近程NTP服务器进行同步。语法:chronyd -q ‘server {ntp_server_name} iburst’
上面应用实例:[root@server1 ~]# chronyd -q 'server s1a.time.edu.cn iburst'
2021-05-25T01:59:38Z chronyd version 3.5 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
2021-05-25T01:59:38Z Initial frequency -4.035 ppm
2021-05-25T01:59:42Z System clock wrong by -0.006248 seconds (step)
2021-05-25T01:59:42Z chronyd exiting
从下面的输入中能够看到,chrony已校对了零碎工夫。Start和Enable chronyd服务运行以下命令以启用chronyd服务:[root@server1 ~]# systemctl enable chronyd
[root@server1 ~]# systemctl start chronyd
运行上面命令查看chronyd的服务状态:[root@server1 ~]# systemctl status chronyd
验证chrony的同步要验证零碎工夫是否已应用chrony同步,应用以下命令查看:[root@server1 ~]# chronyc tracking
Reference ID : 4E2E66B4 (electrode.felixc.at)
Stratum : 4
Ref time (UTC) : Tue May 25 02:04:47 2021
System time : 0.000002501 seconds slow of NTP time
Last offset : +0.016273908 seconds
RMS offset : 0.016273908 seconds
Frequency : 98.064 ppm fast
Residual freq : +1.774 ppm
Skew : 155.311 ppm
Root delay : 0.227135062 seconds
Root dispersion : 0.028634518 seconds
Update interval : 64.4 seconds
Leap status : Normal
Reference ID 是零碎工夫以后同步到的服务器的ID和名称。查看chrony起源要列出无关chronyd应用的以后工夫源的信息,请运行以下命令:[root@server1 ~]# chronyc sources
210 Number of sources = 4
MS Name/IP address Stratum Poll Reach LastRx Last sample
^- electrode.felixc.at 3 6 377 29 -14ms[ -14ms] +/- 137ms
^- ntp7.flashdance.cx 2 6 377 91 +2336us[+2505us] +/- 174ms
^? ntp8.flashdance.cx 0 6 0 - +0ns[ +0ns] +/- 0ns
^* 111.230.189.174 2 6 377 28 +423us[ +648us] +/- 50ms
要列出无关chronyd应用的每个源的漂移速度和偏移预计的信息,请运行以下命令:[root@server1 ~]# chronyc sourcestats -v
210 Number of sources = 4
.- Number of sample points in measurement set. / .- Number of residual runs with same sign. | / .- Length of measurement set (time). | | / .- Est. clock freq error (ppm). | | | / .- Est. error in freq. | | | | / .- Est. offset. | | | | | | On the -. | | | | | | samples. \ | | | | | | |
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
electrode.felixc.at 12 5 527 -2.019 22.417 -13ms 2921us
ntp7.flashdance.cx 10 5 397 +1.957 29.018 +2410us 2684us
ntp8.flashdance.cx 0 0 0 +0.000 2000.000 +0ns 4000ms
111.230.189.174 12 9 527 -0.001 10.537 -60ns 1360us
配置Chrony NTP服务如果你要将Linux服务器配置为所有外部零碎的Chrony NTP服务器。咱们须要在/etc/chrony.conf配置文件中稍作批改:[root@server1 ~]# sed -i "s/#local stratum 10/local stratum 10/g" /etc/chrony.conf
[root@server1 ~]# sed -i "s/#allow 192.168.0.0/16/allow 192.168.0.0/16/" /etc/chrony.conf
当咱们勾销正文local stratum 10行时,则使咱们的Linux服务器成为实时NTP服务器,即便它与网络断开连接也能够持续失常工作。而allow 192.168.0.0/26示意容许该网段的设施连贯到咱们的Chrony NTP服务器以进行工夫同步。更改后,重启chrony服务并跟踪chrony:[root@server1 ~]# systemctl restart chronyd ; watch chronyc tracking
应用以下命令在防火墙中容许NTP服务:[root@server1 ~]# firewall-cmd --permanent --add-service=ntp
success
[root@server1 ~]# firewall-cmd --reload
success
总结这就是本文的全部内容,心愿你能理解如何应用chrony服务将Linux的工夫与NTP服务器同步。