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时间同步

相关推荐
云泽80834 分钟前
不止是命令:Linux 高频指令实战 + 芯片架构底层逻辑
linux·运维·服务器
j_xxx404_38 分钟前
Linux:基础IO
linux·运维·服务器
wdfk_prog1 小时前
[Linux]学习笔记系列 -- [drivers][i2c]i2c-dev
linux·笔记·学习
angushine2 小时前
银河麒麟V10创建用户
运维
Trouvaille ~3 小时前
【Linux】网络编程基础(二):数据封装与网络传输流程
linux·运维·服务器·网络·c++·tcp/ip·通信
久绊A3 小时前
春节前云平台运维深度巡检-实操经验
运维·安全·容器·kubernetes·云平台
旅途中的宽~3 小时前
【深度学习】通过nohup后台运行训练命令后,如何通过日志文件反向查找并终止进程?
linux·深度学习
梦想的旅途24 小时前
企业微信API外部群自动化推送:从“群发工具”到“智能触达”的架构实践
运维·自动化·企业微信
yuezhilangniao4 小时前
Next.js 项目运维手册-含-常用命令-常见场景
运维·开发语言·reactjs
dump linux4 小时前
内核驱动调试接口与使用方法入门
linux·驱动开发·嵌入式硬件