linux ntp时间同步

简介:
+关注继续查看

一、搭建时间同步服务器

1、编译安装ntp server
rpm -qa | grep ntp
若没有找到,则说明没有安装ntp包,从光盘上找到ntp包,使用
rpm -Uvh ntp***.rpm
进行安装
2、修改ntp.conf配置文件
vi /etc/ntp.conf
①、第一种配置:允许任何IP的客户机都可以进行时间同步
将“restrict default nomodify notrap noquery”这行修改成:
restrict default nomodify notrap
配置文件示例:/etc/ntp.conf
②、第二种配置:只允许192.168.211.***网段的客户机进行时间同步
在restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行:
restrict 192.168.211.0 mask 255.255.255.0 nomodify notrap



各个选项信息:

#系统时间与BIOS事件的偏差记录

driftfile /etc/ntp/drift

 

restrict 控制相关权限。

语法为: restrict IP地址 mask 子网掩码 参数

其中IP地址也可以是default ,default 就是指所有的IP

参数有以下几个:

ignore  :关闭所有的 NTP 联机服务

nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。

notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网

noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器

notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。

nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟

kod : 访问违规时发送 KoD 包。

restrict -6 表示IPV6地址的权限设置。


设定NTP主机来源(其中prefer表示优先主机)



server time.pool.aliyun.com prefer
server time.windows.com
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org



3、启动ntp服务
service ntpd start
开机启动服务
chkconfig ntpd on
4、ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。


二、配置时间同步客户机

手工执行 ntpdate <ntp server> 来同步
或者利用crontab来执行
crontab -e
0 0 * * * /usr/sbin/ntpdate 192.168.191.59 && hwclock -w

每天晚上24点进行同步


查看ntp服务器有无和上层ntp连通

1
2
3
4
[root@DNS-176241 slaves]# ntpstat 
synchronised to NTP server (182.92.12.11) at stratum 3 
   time correct to within 41 ms
   polling server every 1024 s

 

查看ntp服务器与上层ntp的状态

1
2
3
4
5
6
7
8
9
10
11
12
[root@DNS-176241 slaves]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time5.aliyun.co 10.137.38.86     2 u  219  512  377   26.131    2.621   0.252
+13.79.239.69    128.138.141.172  2 u  187  512  377  220.562   15.592   0.737
 dns2.ustb.edu.c 130.149.17.8     2 u  20h  128    0   25.792   -1.642   0.000
+85.199.214.101  .GPS.            1 u   60   16  377  287.174    9.750   2.376
 202.120.2.101.d 85.199.214.100   2 u  466  512  213    3.067   17.591   0.781
-202.118.176.2   202.118.177.155  4 u  145  512  377   44.478    6.772   0.499
 ntp.wdc1.us.lea .INIT.          16 u    - 1024    0    0.000    0.000   0.000
+213.227.164.24  162.23.41.56     2 u  120  512  377  197.167   17.568   0.262
 LOCAL(0)        .LOCL.          10 l   59   64  377    0.000    0.000   0.001


以上命令列出了所有作为时钟源校正过本地NTP服务器时钟的上层NTP服务器的列表,每一列的含义如下所示:

◆ remote: 远程NTP服务器的IP地址或域名,带 “*” 的表示本地NTP服务器与该服务器同步。

◆ refid: 远程NTP服务器的上层服务器的IP地址或域名。

◆ st: 远程NTP服务器所在的层数。

◆ t: 本地NTP服务器与远程NTP服务器的通信方式,u: 单播; b: 广播; l: 本地。

◆ when: 上一次校正时间与现在时间的差值。

◆ poll: 本地NTP服务器查询远程NTP服务器的时间间隔。

◆ reach: 是一种衡量前8次查询是否成功的位掩码值,377表示都成功,0表示不成功。

◆ delay: 网络延时,单位是10的-6次方秒。

◆ offset: 本地NTP服务器与远程NTP服务器的时间偏移。

◆ jitter: 查询偏差的分布值,用于表示远程NTP服务器的网络延时是否稳定,单位为10的-6次方秒。














本文转自leonardos51CTO博客,原文链接:http://blog.51cto.com/leomars/1975925 ,如需转载请自行联系原作者


相关文章
|
5月前
|
Linux 网络安全
Linux系统之NTP服务器配置
Linux系统之NTP服务器配置
327 1
|
7月前
|
安全 Linux 网络安全
Linux 时间同步 -NTP 服务器
本文主要介绍如何配置 Linux 服务器集群的时间同步,技术实现上使用 NTP 服务器和客户端同步时间。
330 0
|
11月前
|
Unix Linux
Linux 使用 chrony 进行 NTP 时间同步及自建方法
chrony是网络时间协议的实现。它可以替代ntpd,后者是NTP的参考实现。它在类Unix操作系统上运行,并在GNU GPL v2下发布。
243 0
|
Linux 网络安全
linux篇-CentOS7搭建NTP服务器
linux篇-CentOS7搭建NTP服务器
680 0
linux篇-CentOS7搭建NTP服务器
Linux7搭建NTP服务实践
Linux7搭建NTP服务实践
312 0
Linux7搭建NTP服务实践
|
Web App开发 Linux
Linux NTP原理及配置使用
NTP原理及配置使用 一、NTP简介 1.NTP简介   NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。
1352 0
|
Linux
Linux 国内公共ntp服务器
210.72.145.44 (国家授时中心服务器IP地址) 133.100.11.8  日本 福冈大学 time-a.nist.gov 129.6.15.
1098 0
|
NoSQL Linux
Linux下GDB调试NTP时间同步问题
最近有遇到一例比较有趣的Linux下NTP时间同步问题,尝试了使用GDB调试的方法解决,在这里分享一些个人的心得,希望对大家有些帮助。 问题现象:ECS Linux CentOS实例中时间经常出现偏差,客户已经根据官方文档配置了NTP时间同步,同步源为文档中指定的公网NTP服务器:https://help.aliyun.com/knowledge_detail/40583.html 尝试调整一些同步频率的参数,并没有实际效果。
2817 0
|
网络协议 Linux
Linux(Centos7.4和RHEL7.4)环境下基于chrony的NTP服务器的构建
一、操作环境 操作系统:CentOS Linux release 7.4.1708 (Core) 最小化安装版 chrony版本:chrony-3.1-2.x86_64 二、配置过程 由于在CentOS7.4系统中以默认安装chrony,因此无需再执行安装过程。
2573 0
相关产品
云迁移中心
推荐文章
更多