一. 定义
1) 两个服务都是centos自带的(centos7中不自带ntp)。ntp的安装包名是ntp;ntpdate的安装包是ntpdate。他们并非由一个安装包提供。
2) ntp守护进程为ntpd,配置文件是/etc/ntp.conf
3) ntpdate用于客户端的时间矫正,非NTP服务器可以不启动NTP。
二. 项目要求
服务器 |
IP |
备注 |
NTP服务端 |
192.168.5.15 |
Cenost7 |
客户端 |
192.168.5.9 |
ubuntu (docker 容器内) |
三. 部署服务端
yum install -y ntp
service ntpd start
[root@kq_mysql ~]
driftfile /var/lib/ntp/drift
restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap
restrict 127.0.0.1
restrict ::1
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
server 127.127.1.0 prefer
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
注意:这里只添加下面两行即可
server 127.127.1.0 prefer
restrict 192.168.5.0
restrict 192.168.5.0 mask 255.255.255.0
1)检查进程
[root@kq_mysql ~]
Redirecting to /bin/systemctl start ntpd.service
[root@kq_mysql ~]
udp 0 0 172.17.0.1:123 0.0.0.0:* 16712/ntpd
udp 0 0 172.18.0.1:123 0.0.0.0:* 16712/ntpd
udp 0 0 192.168.5.15:123 0.0.0.0:* 16712/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 16712/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 16712/ntpd
udp6 0 0 :::123 :::* 16712/ntpd
2)检查服务
[root@kq_mysql ~]
remote refid st t when poll reach delay offset jitter
==============================================================================
+stratum2-1.ntp. 194.190.168.1 2 u 56 64 377 102.792 -0.286 6.553
+119.28.206.193 100.122.36.196 2 u 65 64 377 51.545 0.244 10.349
+ntp1.flashdance 194.58.202.20 2 u 65 64 377 289.813 16.525 13.405
+tick.ntp.infoma .GPS. 1 u 55 64 377 147.590 6.641 8.143
*LOCAL(0) .LOCL. 5 l 32 64 377 0.000 0.000 0.000
解释下:ntpq -p:此命令可以列出当前主机的NTP和上层NTP的状态。
四. 部署客户端
apt-get install -y ntp
root@centos_4c8g:/
driftfile /var/lib/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst
pool ntp.ubuntu.com
server 192.168.5.15
restrict 192.168.5.15 nomodify notrap noquery
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery
客户端需要修改/etc/ntp.conf,添加以下内容
server 192.168.5.15
restrict 192.168.5.15
restrict 192.168.5.15 nomodify notrap noquery
root@centos_4c8g:/
root@centos_4c8g:/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)