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

相关推荐
LH_R10 小时前
OneTerm开源堡垒机实战(四):访问授权与安全管控
运维·后端·安全
用户311879455921811 小时前
Kylin Linux 10 安装 glib2-devel-2.62.5-7.ky10.x86_64.rpm 方法(附安装包)
linux
Raymond运维11 小时前
MariaDB源码编译安装(二)
运维·数据库·mariadb
涛啊涛11 小时前
Centos7非LVM根分区容量不足后扩容,对调硬盘挂载/
linux·磁盘管理
JuiceFS1 天前
从 MLPerf Storage v2.0 看 AI 训练中的存储性能与扩展能力
运维·后端
CYRUS_STUDIO1 天前
用 Frida 控制 Android 线程:kill 命令、挂起与恢复全解析
android·linux·逆向
熊猫李1 天前
rootfs-根文件系统详解
linux
chen9451 天前
mysql 3节点mgr集群部署
运维·后端
LH_R1 天前
OneTerm开源堡垒机实战(三):功能扩展与效率提升
运维·后端·安全
dessler1 天前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs