安装
通过snap安装可以非常容易的搭建NTP server/Client.
snap 安装包 chroy-git, 链接地址,https://snapcraft.io/chrony-git
Versatile implementation of the Network Time Protocol (NTP)chrony is a versatile implementation of the Network Time Protocol (NTP). It can synchronise the system clock with NTP servers, reference clocks (e.g. GPS receiver), and manual input using wristwatch and keyboard. It can also operate as an NTPv4 (RFC 5905) server and peer to provide a time service to other computers in the network.
安装命令
sudo snap install chrony-git
国内网络可能安装会有问题,(我自己的网络大部分情况下,报错,can’t access store)
可以通过设置代理,有时多试几次也行
注意,只支持arm64, 如果是安装的hf的core, 会报错
我上传了一个下载链接
https://download.csdn.net/download/feiwatson/73860840
需要加上参数–dangerous, 否则会有签名的报错
sudo snap install --dangerous chrony-git
配置
下面是readme, 安装好后readme在snap目录下.
如果只需要用到client, 直接按照下面的步骤。
如果同时需要server, 在chrony.conf末尾加上一句 allow
1. Disable other NTP services:
-------------------------------------------
timesyncd:
# systemctl mask systemd-timesyncd.service
Check:
$ timedatectl status
2. Create a configuration file (Optional):
-------------------------------------------
Path: /var/snap/chrony-git/common/chrony.conf
See for an example: /snap/chrony-git/current/etc/default.conf
2. Connect to plugs:
-------------------------------------------
$ snap connect chrony-git:time-control
$ snap connect chrony-git:timeserver-control
3. Run services
-------------------------------------------
$ snap start --enable chrony-git.chronyd
4. Check:
-------------------------------------------
$ chrony-git.chronyc tracking
$ chrony-git.chronyc sourcestats
# chrony-git.chronyc ntpdata
作为server, 末尾加上allow
feitrump@ubuntu:~$ cat /var/snap/chrony-git/common/chrony.conf
pool time.google.com iburst minpoll 1 maxpoll 2 maxsources 3
pool ntp.ubuntu.com iburst minpoll 1 maxpoll 2 maxsources 3
pool us.pool.ntp.org iburst minpoll 1 maxpoll 2 maxsources 3
# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /snap/chrony-git/current/etc/default.keys
# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/snap/chrony-git/common/chrony.drift
# Uncomment the following line to turn logging on.
#log tracking measurements statistics
# Log files location.
logdir /var/snap/chrony-git/common/log
# Stop bad estimates upsetting machine clock.
maxupdateskew 5.0
# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync
# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 0.1 -1
allow
feitrump@ubuntu:~$
测试,
通过另外一个树莓派,上面跑python脚本来测试server的功能,以及wireshark (我安装的ubuntu server版本OS)
也可以通过在window下安装networktime应用测试server的功能, 安装包下载地址http://www.timesynctool.com/
将下面的server name改成树莓派的IP地址