关于nginx:Centos8中如何使用Chrony同步时间

4次阅读

共计 3140 个字符,预计需要花费 8 分钟才能阅读完成。

在 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 服务器同步。

正文完
 0