树莓派搭建NTP Server/Client

前文记录了树莓派安装ubuntu core

安装

通过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地址
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值