CentOS7 搭建 NTP时间同步服务器


网络时间协议,是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击。NTP的目的是在无序的Internet环境中提供精确和健壮的时间服务。

部署环境
192.168.116.129 服务端
192.168.116.130 客户端

1、服务端

查看是否安装NTP

rpm -q ntp

安装NTP服务

yum -y install ntp

编辑配置文件

vi /etc/ntp.conf

centos7 ntp服务端 centos7开启ntp服务_ntp


重启NTP服务

systemctl restart ntpd

配置防火墙,开放UDP的123端口

iptables -I INPUT -p udp --dport 123 -j ACCEPT
service iptables save
service iptables restart

配置认证密码

vi /etc/ntp/keys

通过id引用key(客户端配置会配)

centos7 ntp服务端 centos7开启ntp服务_centos7 ntp服务端_02


手动同步

ntpdate -u ntp1.aliyun.com

框里为与上层NTP服务器时间差异,值特别小说明最近同步过时间

centos7 ntp服务端 centos7开启ntp服务_linux_03


查看NTP状态

ntpstat

未同步:

centos7 ntp服务端 centos7开启ntp服务_linux_04


配置完成后几分钟内出现红框内容,表示同步成功

centos7 ntp服务端 centos7开启ntp服务_centos7 ntp服务端_05


查看NTP服务列表

ntpq -p

可以通过watch监控列表变化

watch ntpq -p

refid:参考的上一层NTP主机的地址(配置中的Server)

when:几秒前曾做过时间同步更新的操作

poll:下次更新在几秒之后

reach:已经向上层NTP服务器要求更新的次数

delay:网络传输过程钟延迟的时间

offset:时间补偿的结果

jitter:Linux系统时间与BIOS硬件时间的差异时间

centos7 ntp服务端 centos7开启ntp服务_udp_06


2、客户端配置

安装和keys的配置与服务端一致


修改配置文件

vi /etc/ntp.conf

在server处引用key ID (1)

centos7 ntp服务端 centos7开启ntp服务_udp_07


重启NTP

systemctl restart ntpd

手动与服务端同步

ntpdate -u 192.168.116.129

centos7 ntp服务端 centos7开启ntp服务_udp_08


配置密码后上面的会报错
no server suitable for synchronization found

通过密码认证

ntpdate -a 1 -k /etc/ntp/keys 192.168.116.129

如果还是报错可以增加 -d 查看报错详情

ntpdate -d -a 1 -k /etc/ntp/keys 192.168.116.129

常见报错

1.Server dropped: Strata too high

说明服务端还没有和其自身或者它的server同步上。

2.Server dropped: no data

1、防火墙没关
2、UDP的123端口没开
3、认证没通过