1. Posts/

使用 Docker 部署 NTP 时间服务器

·阅读预计 1 分钟
Docker NTP NTP Server
小北
作者
小北
目录

因为某些设备断电没有设置对时间,需要修改 NTP 服务器,当然你可以直接设置一些提供 NTP 服务的服务器,但你如果网络隔离的需要,所以就还是得自建一个,这里用的是 Docker 部署

建立时间服务器 #

拉取 Docker 镜像 #

其实 hub 里蛮多的,我找了个随便使用比较多的

docker pull cturra/ntp:latest

启动 #

docker run -d --name ntp --restart=always -p 123:123/udp cturra/ntp:latest

因为做服务的设备都能联网,所以不需要给容器开 SYS_TIME 注意防火墙开启 UDP 123 端口

还可以通过 NTP_SERVERS 环境变量指定多个不同的 NTP 服务器时间来源

--env NTP_SERVERS="ntp1.aliyun.com,ntp2.aliyun.com,ntp3.aliyun.com,ntp4.aliyun.com,time.cloudflare.com,time1.google.com,time2.google.com,time3.google.com,time4.google.com" 

设置时间服务器 #

这里我设置过两种设备,供参考

Android TV #

首先建立 adb 连接,192.168.xx.xx 换成对应 Android TV 的IP

adb connect 192.168.xx.xx

连接好设备后,假设刚刚的 NTP 服务器的IP为 192.168.30.1 (下同)

adb shell settings put global ntp_server 192.168.30.1

重启设备

adb shell reboot now

Debian 12 #

编辑 Debian NTP 服务器源

sudo vim /etc/chrony/chrony.conf

如果不连外网,也偷懒直接设置 pool 改为刚刚的NTP服务器,和 server 效果一样,pool 指的是一个服务器池,而 server 则指定单个的服务器,当然设 pool 更灵活,可以设置多个 poolserver

以下为 /etc/chrony/chrony.conf 文件片段

# Use Debian vendor zone.
pool 192.168.30.1 iburst
pool 2.debian.pool.ntp.org iburst

重启 chrony

sudo systemctl restart chrony

Related

PaddleOCR M1 MacBook 安装全记录
·阅读预计 4 分钟
PaddleOCR Homebrew Mac 记录