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

相关推荐
玖剹几秒前
多线程编程:从日志到单例模式全解析
java·linux·c语言·c++·ubuntu·单例模式·策略模式
Monody_R5 分钟前
rhce作业
linux·服务器·apache
dessler6 分钟前
MYSQL-外键(Foreign Key)
linux·运维·mysql
随机昵称_12345612 分钟前
Linux如何从docker hub下载arm镜像
java·linux·arm开发·docker
q***098017 分钟前
在linux(Centos)中Mysql的端口修改保姆级教程
linux·mysql·centos
BD_Marathon20 分钟前
将 CentOS 风格的命令行提示符(如 [root@slave1 ~]#)修改为 Ubuntu 风格
linux·ubuntu·centos
muxue17822 分钟前
Hadoop集群搭建(下):centos 7为例(已将将安装所需压缩包统一放在了/opt/software目录下)
大数据·hadoop·centos
liu****24 分钟前
16.udp_socket(三)
linux·开发语言·数据结构·c++·1024程序员节
q***718524 分钟前
海康威视摄像头RTSP使用nginx推流到服务器直播教程
运维·服务器·nginx
不会写程序的未来程序员25 分钟前
Linux 虚拟机设置静态 IP 地址指南
linux·运维·tcp/ip