Chrony可以更快的同步系统时钟,具有更好的时钟确切度,但是它对于这些不是仍然在线的系统很有帮助。
--Sk
有用的原文链接
请访问文末的“原文链接”获得可点击的文内链接、全规格原图和相关文章。
致谢
编译自|
作者|Sk
译者|zianglei共计翻译:2.0篇贡献时间:8天
在这个教程中,我们会讨论怎样安装和配置Chrony,一个类Unix系统上NTP顾客端和服务器的取代品。Chrony可以更快的同步系统时钟红旗linux操作系统,具有更好的时钟确切度,但是它对于这些不是仍然在线的系统很有帮助。Chrony是自由开源的linux 安装ntp服务器,而且支持GNU/Linux和BSD衍生版(例如FreeBSD、NetBSD)、macOS和Solaris等。
安装Chrony
Chrony可以从大多数Linux发行版的默认软件库中获得。假如你使用的是ArchLinux,运行下边的命令来安装它:
$ sudo pacman -S chrony
在Debian、Ubuntu、LinuxMint上:
$ sudo apt-get install chrony
在Fedora上:
$ sudo dnf install chrony
当安装完成后,假若之前没有启动过的话需启动chronyd.service守护进程:
$ sudo systemctl start chronyd.service
使用下边的命令让它每次重启系统后手动运行:
$ sudo systemctl enable chronyd.service
为了确认chronyd.service早已启动,运行:
$ sudo systemctl status chronyd.service
倘若一切正常,你将见到类似下边的输出:
● chrony.service - chrony, an NTP client/server
Loaded: loaded (/lib/systemd/system/chrony.service; enabled; vendor preset: ena
Active: active (running) since Wed 2018-10-17 10:34:53 UTC; 3min 15s ago
Docs: man:chronyd(8)
man:chronyc(1)
man:chrony.conf(5)
Main PID: 2482 (chronyd)
Tasks: 1 (limit: 2320)
CGroup: /system.slice/chrony.service
└─2482 /usr/sbin/chronyd
Oct 17 10:34:53 ubuntuserver systemd[1]: Starting chrony, an NTP client/server...
Oct 17 10:34:53 ubuntuserver chronyd[2482]: chronyd version 3.2 starting (+CMDMON
Oct 17 10:34:53 ubuntuserver chronyd[2482]: Initial frequency -268.088 ppm
Oct 17 10:34:53 ubuntuserver systemd[1]: Started chrony, an NTP client/server.
Oct 17 10:35:03 ubuntuserver chronyd[2482]: Selected source 85.25.84.166
Oct 17 10:35:03 ubuntuserver chronyd[2482]: Source 85.25.84.166 replaced with 2403
Oct 17 10:35:03 ubuntuserver chronyd[2482]: Selected source 91.189.89.199
Oct 17 10:35:06 ubuntuserver chronyd[2482]: Selected source 106.10.186.200
可以看见,Chrony服务早已启动而且正在工作!
配置Chrony
NTP顾客端须要晓得它要联接到那个NTP服务器来获取当前时间。我们可以直接在该NTP配置文件中的server或则pool项指定NTP服务器。一般,默认的配置文件坐落/etc/chrony/chrony.conf或则/etc/chrony.confqq for linux,取决于Linux发行版版本。为了更可靠的同步时间,建议指定起码三个服务器。
下边几行是我的Ubuntu18.04LTS服务器上的一个示例。
[...]
# About using servers from the NTP Pool Project in general see (LP: #104525).
# Approved by Ubuntu Technical Board on 2011-02-08.
# See http://www.pool.ntp.org/join.html for more information.
pool ntp.ubuntu.com iburst maxsources 4
pool 0.ubuntu.pool.ntp.org iburst maxsources 1
pool 1.ubuntu.pool.ntp.org iburst maxsources 1
pool 2.ubuntu.pool.ntp.org iburst maxsources 2
[...]
从里面的输出中你可以看见linux 安装ntp服务器,NTP服务器池项目[1]早已被设置成为了默认的时间服务器。对于这些好奇的人,NTP服务器池项目是一个时间服务器集群,拿来为全世界千万个顾客端提供NTP服务。它是Ubuntu以及其他主流Linux发行版的默认时间服务器。
在这儿,*iburst选项拿来加速初始的同步过程*maxsources代表NTP源的最大数目
请确保你选择的NTP服务器是同步的、稳定的、离你的位置较近的,便于使用这种NTP源来提高时间确切度。
在命令行中管理Chronyd
chrony有一个命令行工具称作chronyc拿来控制和监控chrony守护进程(chronyd)。
为了检测是否chrony早已同步,我们可以使用下边展示的tracking命令。
$ chronyc tracking
Reference ID : 6A0ABAC8 (t1.time.sg3.yahoo.com)
Stratum : 3
Ref time (UTC) : Wed Oct 17 11:48:51 2018
System time : 0.000984587 seconds slow of NTP time
Last offset : -0.000912981 seconds
RMS offset : 0.007983995 seconds
Frequency : 23.704 ppm slow
Residual freq : +0.006 ppm
Skew : 1.734 ppm
Root delay : 0.089718960 seconds
Root dispersion : 0.008760406 seconds
Update interval : 515.1 seconds
Leap status : Normal
我们可以使用命令确认现今chrony使用的时间源:
$ chronyc sources
210 Number of sources = 8
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^- chilipepper.canonical.com 2 10 377 296 +102ms[ +104ms] +/- 279ms
^- golem.canonical.com 2 10 377 302 +105ms[ +107ms] +/- 290ms
^+ pugot.canonical.com 2 10 377 297 +36ms[ +38ms] +/- 238ms
^- alphyn.canonical.com 2 10 377 279 -43ms[ -42ms] +/- 238ms
^- dadns.cdnetworks.co.kr 2 10 377 1070 +40ms[ +42ms] +/- 314ms
^* t1.time.sg3.yahoo.com 2 10 377 169 -13ms[ -11ms] +/- 80ms
^+ sin1.m-d.net 2 10 275 567 -9633us[-7826us] +/- 115ms
^- ns2.pulsation.fr 2 10 377 311 -75ms[ -73ms] +/- 250ms
chronyc工具可以对每位源进行统计,例如使用sourcestats命令获得甩尾速度和进行偏斜恐怕。
$ chronyc sourcestats
210 Number of sources = 8
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
==============================================================================
chilipepper.canonical.com 32 16 89m +6.293 14.345 +30ms 24ms
golem.canonical.com 32 17 89m +0.312 18.887 +20ms 33ms
pugot.canonical.com 32 18 89m +0.281 11.237 +3307us 23ms
alphyn.canonical.com 31 20 88m -4.087 8.910 -58ms 17ms
dadns.cdnetworks.co.kr 29 16 76m -1.094 9.895 -83ms 14ms
t1.time.sg3.yahoo.com 32 16 91m +0.153 1.952 +2835us 4044us
sin1.m-d.net 29 13 83m +0.049 6.060 -8466us 9940us
ns2.pulsation.fr 32 17 88m +0.784 9.834 -62ms 22ms
假如你的系统没有联接到互联网,你须要告知Chrony系统没有联接到互联网。为了这样做,运行:
$ sudo chronyc offline
[sudo] password for sk:
200 OK
为了确认你的NTP源的状态,只须要运行:
$ chronyc activity
200 OK
0 sources online
8 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address
可以看见,我的所有源此时都是离线状态。
一旦你联接到互联网,只须要使用命令告知Chrony你的系统早已回到在线状态:
$ sudo chronyc online
200 OK
为了查看NTP源的状态,运行:
$ chronyc activity
200 OK
8 sources online
0 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address
所有选项和参数的详尽解释,请参考其帮助指南。
$ man chronyc
$ man chronyd
这就是文章的所有内容。希望对你有所帮助。在此后的教程中,我们会听到怎样使用Chrony启动一个本地的NTP服务器而且配置顾客端来使用这个服务器同步时间。