网络时间协议NTP配置
今天在windows上接入了GPS时钟,在日期和时间里面设置Internet时间设置,将服务器的默认time.windows.com改为GPS时钟的IP地址。同时需要保证Windows Time服务在运行,此服务维护在网络上的所有客户端和服务器的时间和日期同步。如果此服务被停止,时间和日期的同步将不可用。


现在来看一下Linux的NTP设置,本文以腾讯云的轻量应用服务器为例。看看腾讯云文档中心关于配置 NTP 服务的说明:ntpd(Network Time Protocol daemon)是 Linux 操作系统的一个守护进程,用于校正本地系统与时钟源服务器之前的时间,完整的实现了 NTP 协议。ntpd 与 ntpdate 的区别是 ntpd 是步进式的逐渐校正时间,不会出现时间跳变,而 ntpdate 是断点更新。
执行以下命令,判断是否安装 ntpd:rpm -qa | grep ntp
可以通过yum -y install ntp来安装ntpd。
NTP 服务的通信端口为 UDP 123。
systemctl status ntpd.service命令,可查看ntpd.service 状态。
systemctl is-active ntpd.service 命令,可查看 ntpd 是否正在运行。
systemctl is-enabled ntpd.service 命令,可查看 ntpd 是否开机自启动。

ntpq -p获取NTP 服务信息,前面的*表示正在使用的时间同步服务器。

腾讯云文档对于参数的解释如下:

/etc/ntp.conf 配置文件。
1、restrict管理权限控制
参数nomodify ,客户端不能使用ntpc与ntpq这两个程序来修改服务器的时间参数
参数notrap,不提供trap这个远程事件登录(remote event logging)的功能

2、server设定上层NTP服务器。
可以设置prefer,表示优先使用的服务器。

3、driftfile记录时间差异
NTP Server本身的时间计算是依据BIOS的芯片震荡周期频率来计算的,但是这个数值与上层Time Server不见得一致。所以NTP 守护进程(ntpd) 会自动的去计自己主机的频率与上层Time server的频率,并且将两个频率的误差记录下来。

4、增强 ntpd 安全性
忽略所有端口之上的监听,只监听 eth0。
