手把手教你搭建Linux时间同步服务器

简介: 手把手教你搭建Linux时间同步服务器


文章目录

1. NTP简介

NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。还可介由加密确认的方式来防止恶毒的协议攻击。时间按NTP服务器的等级传播。按照离外部UTC源的远近把所有服务器归入不同的Stratum(层)中。NTP服务器就是利用NTP协议提供时间同步服务的。

2. NTP服务器安装

#一般服务器都会自带ntp服务
[root@nfs01 ~] rpm -qa|grep ntp
ntp-4.2.6p5-10.el6.centos.2.x86_64
ntpdate-4.2.6p5-10.el6.centos.2.x86_64
如果没有,直接利用yum进行安装
[root@nfs01 ~] yum install -y ntp

3. 配置NTP服务

在配置文件vim /etc/ntp.conf中修改参数

[root@nfs01 ~] vim /etc/ntp.conf
# restrict default kod nomodify notrap nopeer noquery
restrict default nomodify
# nomodify客户端可以同步
# 将默认时间同步源注释改用可用源
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
#在文章末端加入下列命令
server ntp1.aliyun.com
server time.nist.gov

4. 启动NTP服务器

#如果计划任务有时间同步,先注释,两种用法会冲突。
#如果没有则进行下一步
1.[root@nfs01 ~] crontab -e
no crontab for root - using an empty one
#启动ntp服务
2.[root@nfs01 ~] /etc/init.d/ntpd start
Starting ntpd:                [  OK  ]
3.[root@nfs01 ~]  ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 120.25.115.20   10.137.53.7      2 u   51   64    3   37.536  1742252   0.498
 time-a-wwv.nist .NIST.           1 u   49   64    3  203.111  1742252  11.005
4.[root@nfs01 ~] ntpstat
unsynchronised
polling server every 64 s
#测试ntp服务
5.[root@nfs01 ~]# ntpdate 172.16.1.31
11 Oct 19:12:04 ntpdate[2072]: the NTP socket is in use, exiting

5. 客户端时间同步

客户机要等10分钟左右再与新启动的ntp服务器进行时间同步,否则会报错no server suitable for synchronization found。

[root@backup ~]# ntpdate 172.16.1.32
21 Sep 15:46:00 ntpdate[2011]: no server suitable for synchronization found

过10分钟左右后,客户端开始与ntp服务端进行时间同步后结果;

[root@backup ~]# ntpdate 172.16.1.31
11 Oct 19:42:35 ntpdate[2349]: step time server 172.16.1.31 offset 1740585.341828 sec


相关文章
|
4天前
|
消息中间件 安全 Linux
服务器(Linux)在线下载activeMQ以及配置打开
服务器(Linux)在线下载activeMQ以及配置打开
14 3
|
4天前
|
Java Linux
Linux(服务器) 装JDK
Linux(服务器) 装JDK
19 1
|
3天前
|
Linux 网络安全
linux/服务器使用scp将一个服务器文件转移到另一个服务器上
linux/服务器使用scp将一个服务器文件转移到另一个服务器上
29 3
|
4天前
|
监控 JavaScript 网络协议
Linux系统之安装uptime-kuma服务器监控面板
【5月更文挑战第12天】Linux系统之安装uptime-kuma服务器监控面板
14 0
|
4天前
|
关系型数据库 MySQL Linux
服务器Linux系统配置mysql数据库主从自动备份
这是一个基本的配置主从复制和设置自动备份的指南。具体的配置细节和命令可能因您的环境和需求而有所不同,因此建议在操作前详细阅读MySQL文档和相关资源,并谨慎操作以避免数据丢失或不一致。
16 3
|
4天前
|
Oracle Java 关系型数据库
【服务器】python通过JDBC连接到位于Linux远程服务器上的Oracle数据库
【服务器】python通过JDBC连接到位于Linux远程服务器上的Oracle数据库
16 6
|
Linux 网络安全
Linux时间同步服务 - chronyd
Linux时间同步服务 - chronyd
528 0
|
Linux 网络安全 数据库