一、chrony介绍
chrony是网络时间协议 (NTP) 的通用实现。它可以将系统时钟与 NTP 服务器、参考时钟(例如 GPS 接收器)以及使用手表和键盘的手动输入同步。
二、容器镜像介绍
默认情况下,此容器使用 CloudFlare 的时间服务器 (time.cloudflare.com)。如果您想使用一个或多个不同的 NTP 服务器,您可以向该容器传递一个NTP_SERVERS 环境变量。
env=NTP_SERVERS=""
三、检查本地docker状态
[root@jeven docs]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2022-12-02 0405 CST; 12h ago Docs: https://docs.docker.com Main PID: 10004 (dockerd) Tasks: 77 Memory: 2.0G CGroup: /system.slice/docker.service ├─10004 /usr/bin/dockerd -H fd:// --cnotallow=/run/containerd/containerd.sock ├─12091 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8190 -container-ip 172.17.0.2 -container-port 8090 ├─12097 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8190 -container-ip 172.17.0.2 -container-port 8090 ├─12109 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8016 -container-ip 172.31.0.2 -container-port 80 ├─12115 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8016 -container-ip 172.31.0.2 -container-port 80 ├─12127 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 453 -container-ip 172.31.0.2 -container-port 443 ├─12133 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 453 -container-ip 172.31.0.2 -container-port 443 ├─14964 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3300 -container-ip 192.168.64.2 -container-port 3300 ├─14970 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3300 -container-ip 192.168.64.2 -container-port 3300 ├─43254 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 7890 -container-ip 172.17.0.3 -container-port 8000 └─43261 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 7890 -container-ip 172.17.0.3 -container-port 8000 Dec 02 15:45:55 jeven dockerd[10004]: time="2022-12-02T1555.364855562+08:00" level=info msg="ignoring event" cnotallow=59ece461228f7c0...skDelete" Dec 02 1556 jeven dockerd[10004]: time="2022-12-02T15:45:56.582197016+08:00" level=info msg="ignoring event" cnotallow=59ece461228f7c0...skDelete" Dec 02 15:45:58 jeven dockerd[10004]: time="2022-12-02T1558.010358602+08:00" level=info msg="ignoring event" cnotallow=59ece461228f7c0...skDelete" Dec 02 1559 jeven dockerd[10004]: time="2022-12-02T15:45:59.822979906+08:00" level=info msg="ignoring event" cnotallow=59ece461228f7c0...skDelete" Dec 02 15:46:02 jeven dockerd[10004]: time="2022-12-02T1502.451854240+08:00" level=info msg="ignoring event" cnotallow=59ece461228f7c0...skDelete" Dec 02 1506 jeven dockerd[10004]: time="2022-12-02T15:46:06.662259690+08:00" level=info msg="ignoring event" cnotallow=59ece461228f7c0...skDelete" Dec 02 15:46:14 jeven dockerd[10004]: time="2022-12-02T1514.083579709+08:00" level=info msg="ignoring event" cnotallow=59ece461228f7c0...skDelete" Dec 02 1528 jeven dockerd[10004]: time="2022-12-02T15:46:28.185437247+08:00" level=info msg="ignoring event" cnotallow=59ece461228f7c0...skDelete" Dec 02 15:46:55 jeven dockerd[10004]: time="2022-12-02T1555.193222004+08:00" level=info msg="ignoring event" cnotallow=59ece461228f7c0...skDelete" Dec 02 1550 jeven dockerd[10004]: time="2022-12-02T15:47:50.424840407+08:00" level=info msg="ignoring event" cnotallow=c16d42dd96e202a...skDelete" Hint: Some lines were ellipsized, use -l to show in full.
四、下载ntp镜像
1.创建ntp容器
[root@jeven ~]# docker pull cturra/ntp Using default tag: latest latest: Pulling from cturra/ntp 59bf1c3509f3: Already exists 45b0d9aa13f5: Pull complete 7b02bd2e0aba: Pull complete Digest: sha256:b4cf0bb0aba53b4438605ef30913f1fbf69d0f5ad5d3781ead43353cd64d5b92 Status: Downloaded newer image for cturra/ntp:latest docker.io/cturra/ntp:latest
2.查看ntp容器状态
[root@jeven ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 58091922ab8d cturra/ntp "/bin/sh /opt/startu…" 20 seconds ago Up 20 seconds (health: starting) 0.0.0.0:123->123/udp, :::123->123/udp ntp
六、检查ntp服务器的时间源
检测为阿里的时间源,ntp服务器配置正确
[root@jeven ~]# docker exec ntp chronyc sources MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 203.107.6.88 2 6 377 13 +532us[+1324us] +/- 21ms
七、客户端测试
客户端查看chronyd服务状态
[root@server001 ~]# systemctl status chronyd ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-12-02 0411 EST; 3min 27s ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 4479 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS) Process: 4476 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 4478 (chronyd) Tasks: 1 Memory: 304.0K CGroup: /system.slice/chronyd.service └─4478 /usr/sbin/chronyd Dec 02 04:22:11 server001 systemd[1]: Starting NTP client/server... Dec 02 04:22:11 server001 chronyd[4478]: chronyd version 3.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SECHASH +SIGND +ASY... +DEBUG) Dec 02 04:22:11 server001 chronyd[4478]: Frequency -12.895 +/- 0.065 ppm read from /var/lib/chrony/drift Dec 02 04:22:11 server001 systemd[1]: Started NTP client/server. Dec 02 04:22:15 server001 chronyd[4478]: Selected source 192.168.3.166 Hint: Some lines were ellipsized, use -l to show in full.
2.修改配置文件
[root@server001 ~]# grep iburst /etc/chrony.conf server 192.168.3.166 iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst
3.查看时间同步状态
[root@server001 ~]# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 192.168.3.166 3 6 377 19 -233us[-1027us] +/- 26ms
审核编辑:汤梓红
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。
举报投诉
-
接收器
+关注
关注
14文章
2214浏览量
70670 -
服务器
+关注
关注
12文章
8120浏览量
82521 -
NTP
+关注
关注
1文章
93浏览量
13779 -
Docker
+关注
关注
0文章
437浏览量
11603
原文标题:docker部署NTP时间服务器 chrony
文章出处:【微信号:magedu-Linux,微信公众号:马哥Linux运维】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
用NTP服务器自动设置BB Black的时间
/8/ntpd的内容。现在大部分操作系统和硬件都包含了一个时间芯片,用来在电源关闭时维持时间。当设备启动时,该芯片可以初始化操作系统的时间。在设备与NTP
发表于 04-25 16:22
互联网可用时间服务器地址(NTP时间服务器地址)
ntp3.aliyun.com &>/dev/null运维人员也可以在网内搭建NTP时间服务器,老男孩课程教学中都有讲,故不在累述。
发表于 08-15 17:10
如何利用WIFI模块获取NTP服务器中的网络时间
There are different ways to be brave.勇敢有不同种方式。一、需求在单片机上实现RTC的驱动,利用WIFI模块获取NTP服务器中的网络时间,并将其更新至RTC上。二
发表于 01-21 07:32
有人知道使用GPS/RTC模块作为时间源的ESP8266 NTP服务器吗?
有人知道使用 GPS/RTC 模块作为时间源的 ESP8266 NTP 服务器吗?我有一个 WiFi 项目,我想在其中联网很多 ESP 板。我需要时间,但无法访问互联网。我想让正常工作
发表于 02-24 07:48
如何验证NTP服务器?
BearSSL_Validation 示例显示来自服务器的证书部分通过确认证书的验证日期与 NTP 服务器验证的时间一致来验证。但是我们如何验证 N
发表于 02-24 07:13
什么是NTP服务器 NTP服务器如何工作
为一种通过一组分散的客户端和服务器来同步多个网络时钟的协议。它的前身是时间协议和 IC MP时间戳报文,它们的功能合并在网络时间协议中。NTP
NTP服务器配置概述
服务器进行自动同步。 ntp server与客户端必须要ping通 none配置: clock protocol none #时间协议clock timezone beijing add
【时间同步】NTP网络时间服务器
的Internet协议之一。它的目的是在国际互联网上传递统一、标准的时间。具体的实现方案是在网络上指定若干时钟源网站,为用户提供授时服务,并且这些网站间应该能够相互比对,提高准确度。 NTP网络
评论