CentOS自己搭建时钟同步服务实操

目录

1、产生背景

2、操作过程

3、客户端操作

4、ntpd和ntpdate的区别

5、参考文章


1、产生背景

因为公司业务,需要使用一些网关设备上报监测实时数据,为了保障数据时钟一致性,所以需要提供一天时钟校验服务器。因为原来这个厂家的网关设备以前使用过其他时钟同步服务。但是最近发现设备掉线率很高,于是经过研究需要我们这边提供时钟同步服务器。

2、操作过程

2.1、准备一台授时服务器

检查是否安装ntp

bash 复制代码
[root@lh-mqtt ~]# rpm -q ntp
ntp-4.2.6p5-28.el7.centos.x86_64

如果没有则执行安装操作如下命令

bash 复制代码
安装ntp服务

yum -y install ntp

修改配置文件

bash 复制代码
vi /etc/ntp.conf

修改如下:

bash 复制代码
driftfile /var/lib/ntp/drift

restrict default nomodify

restrict 127.0.0.1
restrict ::1
# 配置允许连接服务端的网段
restrict 10.10.20.* mask 255.255.255.0 nomodify notrap
# 配置时间服务器
server ntp.neu.edu.cn iburst
server ntp.aliyun.com iburst
server ntp.ntsc.ac.cn iburst


# 配置在无法连接到时间服务器时将本地时间同步到客户端
server 127.127.1.0
fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

启动ntp服务并配置开机自启

bash 复制代码
systemctl start ntpd
systemctl enable ntpd

查看状态,前面带*号表示当前连接的时间服务器

bash 复制代码
ntpq -p

[root@lh-mqtt ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp2.neu.edu.cn .BDS.            1 u  424 1024  351   78.285  -23.443  16.037
+203.107.6.*    100.107.25.114   2 u  902 1024  377   15.739    3.737  79.777
 114.118.7.*   123.139.33.3     2 u 134m 1024  200   68.171    4.728  18.907
 LOCAL(0)        .LOCL.          10 l  15d   64    0    0.000    0.000   0.000
复制代码
remote: *表示目前使用的ntp server;+表示备用服务器

st:即stratum阶层,值越小表示ntp serve的精准度越高;

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

Poll表示,每隔多少毫秒与ntp server同步一次;

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

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

offset:时间补偿的结果;

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

设置NTP开机自动启动

bash 复制代码
chkconfig ntpd on

查看NTP是否正常运行

bash 复制代码
netstat -tlunp | grep ntp

手工同步一次时间

bash 复制代码
/usr/sbin/ntpdate ip地址

查看时间同步结果

bash 复制代码
root@lh-mqtt ~]# ntpstat
synchronised to NTP server (202.118.1.47) at stratum 2 
   time correct to within 113 ms
   polling server every 1024 s

3、客户端操作

安装ntp服务,同服务端

修改配置文件

bash 复制代码
driftfile /var/lib/ntp/drift

restrict default nomodify notrap nopeer noquery

restrict 127.0.0.1 
restrict ::1# 配置服务端地址
server 10.10.20.5 iburst

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

启动ntp服务并配置开机自启

bash 复制代码
systemctl start ntpd
systemctl enable ntpd

查看状态 ntpq -p

bash 复制代码
ntpq -p

4、ntpd和ntpdate的区别

ntpd在实际同步时间时是一点点的校准过来时间的,最终把时间慢慢的校正对。而ntpdate不会考虑其他程序是否会阵痛,直接调整时间。

5、参考文章

ntp同步Linux服务器时间

Linux配置NTP时间同步

相关推荐
地球被支点撬走啦3 分钟前
jetson ubuntu 打不开 firefox和chromium浏览器
linux·firefox·jetson
Lovyk12 分钟前
完整实验命令解析:从集群搭建到负载均衡配置
linux·运维·服务器
qq_3411604417 分钟前
文件系统挂载详细分析(《图解Linux内核》虚拟文件系统篇笔记二)
linux·服务器·笔记
Yyyy48239 分钟前
MyCAT高可用
java·运维
Fireworkitte1 小时前
Ubuntu 系统 tar 包源码安装 Nginx
linux·nginx·ubuntu
熬夜苦读学习1 小时前
Reactor 反应堆模式
运维·服务器·网络·网络协议·http·智能路由器·php
刘一说1 小时前
CentOS安装Maven详细教程
linux·centos·maven
ElendaLee1 小时前
笔记本电脑Windows+Ubuntu 双系统,Ubuntu无法挂载Windows的硬盘 报错问题解决
linux·运维·ubuntu
QtSeeker2 小时前
Ubuntu22.04安装VMware Tools
linux·ubuntu
大只鹅3 小时前
Centos7.9 Docker26容器化部署 MySql9.4 一主一从的同步复制部署
mysql·centos