1. 概述
记录下NTP服务器的使用步骤以及注意事项,供自己以后参考,同时希望能够帮助大家。
2. 原理
C/S模型:客户端通过ntp服务从服务端获取时间信息同步客户端的时间。LAN上同步误差可达到1ms,WAN上可达到几十毫秒。
ntp 服务既是客户端又是服务器端,可以通过配置文件看到。
2. 安装
版本 ubuntu1804
2.1 ntp
需要安装NTP服务所需要的程序,使用命令
sudo apt-get install ntpstat ntp ntpdate
ntp服务使用123端口
关于ntp的相关命令有
- service ntp是渐进式同步,并且会一直运行
- ntpdate是立即同步
启动服务 service ntp start
查询状态 service ntp status
重启服务 service ntp stop
关闭服务 service ntp restart
查询当前同步状态 ntpq -p 或者 watch ntpq -p
使用ntpdate立即同步 ntpdate xxx.xxx.xx.x服务器ip地址
查看ntp服务器有无和上层连通
~$ ntpstat
synchronised to NTP server (192.168.0.100) at stratum 2
time correct to within 17 ms
polling server every 64 s
2.2 文件
因为涉及到服务器的ip地址以及其他可配置参数,因此需要进行配置文件编写。文件路径为/etc/ntp.conf
$ sudo gedit /etc/ntp.conf
具体内容如下,主要添加server 信息,设置指定同步的服务器
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
# 时间差异文件
driftfile /var/

本文详细介绍了如何在Ubuntu 18.04上设置和使用NTP服务器进行时间同步。首先,解释了NTP服务的C/S模型工作原理,接着通过步骤指导安装ntp服务,包括配置文件的编辑。还提供了查询和评估同步状态的方法,以及在不严格要求时间一致性的场景下,如何立即同步和渐进式同步。最后,列出了一些参考资料。
最低0.47元/天 解锁文章
3175

被折叠的 条评论
为什么被折叠?



