欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

时间同步-ntp服务器的搭建(docker版本)

发布时间:2025/4/16 编程问答 2 豆豆
生活随笔 收集整理的这篇文章主要介绍了 时间同步-ntp服务器的搭建(docker版本) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

introduce

用于构建cdm所需要的ntp服务器镜像,实现宿主机和ntpserver同步,ntpserver于ntpclient的同步

项目地址

项目github

image build

docker image build -t docker.finogeeks.club/linzhihuang/fino-cdm-ntp:v2.0

run

docker run --rm -it docker.finogeeks.club/linzhihuang/fino-cdm-ntp:v2.0

run cluster

docker compose up

config

我们通过下面的几步来完成ntp服务端和客户端的搭建

  • 在server的服务机器上我们通过

    volumes:- /etc/localtime:/etc/localtime:ro

    让docker和服务器的时间保持一致

  • 在server的服务上还需要配置/etc/ntp.conf,方式如下shell

    rm /etc/ntp.conf cat >> /etc/ntp.conf <<EOF # 中国这边最活跃的时间服务器 : http://www.pool.ntp.org/zone/cn server 0.ubuntu.pool.ntp.org server 1.ubuntu.pool.ntp.org server 2.ubuntu.pool.ntp.org server 3.ubuntu.pool.ntp.org # allow update time by the upper server restrict 0.cn.pool.ntp.org nomodify notrap noquery restrict 0.asia.pool.ntp.org nomodify notrap noquery restrict 3.asia.pool.ntp.org nomodify notrap noquery # Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available. # 外部时间服务器不可用时,以本地时间作为时间服务 server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 EOF
  • 在client的服务上对/etc/ntp/。方式如下shell

    echo "server ${NTP_SERVER_HOSTNAME} prefer" >> /etc/ntp.conf echo "restrict ${NTP_SERVER_HOSTNAME} " >> /etc/ntp.conf
  • 总结

    以上是生活随笔为你收集整理的时间同步-ntp服务器的搭建(docker版本)的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。