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

相关推荐
爱吃山竹的大肚肚4 小时前
EasyPOI 大数据导出
java·linux·windows
极地星光5 小时前
dmesg 工具的核心功能与作用
linux
雾削木5 小时前
k230 Pyhton三角形识别
运维·服务器·网络·stm32·智能路由器
福尔摩斯张6 小时前
C++核心特性精讲:从C语言痛点出发,掌握现代C++编程精髓(超详细)
java·linux·c语言·数据结构·c++·驱动开发·算法
hgz07106 小时前
Linux服务器环境部署与JMeter压测准备
linux·服务器·jmeter
ShirleyWang0126 小时前
VMware如何导入vmdk文件
linux·数据库
大连好光景6 小时前
Python打日志
运维·python·运维开发
Lueeee.6 小时前
内核menuconfig配置实验
linux
遇见火星7 小时前
常见Systemctl语句
linux·服务器·网络·systemctl
月明长歌7 小时前
【码道初阶】【LeetCode 110】平衡二叉树:如何用一个“Magic Number”将复杂度从O(N²)降为 O(N)?
linux·算法·leetcode