The ntpd program is an operating system daemon which sets and maintains the system time of day in synchronism with Internet standard time servers. It is a complete implementation of the Network Time Protocol (NTP) version 4, but also retains compatibility with version 3, as defined by RFC-1305, and version 1 and 2, as defined by RFC-1059 and RFC-1119, respectively. ntpd does most computations in 64-bit floating point arithmetic and does relatively clumsy 64-bit fixed point operations only when necessary to preserve the ultimate precision, about 232 picoseconds. While the ultimate precision, is not achievable with ordinary workstations and networks of today, it may be required with future gigahertz CPU clocks and gigabit LANs.
官网:http://doc.ntp.org/4.1.0/ntpd.htm
NTP服务器【Network Time Protocol(NTP)】是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击。 官方文档: http://support.ntp.org/bin/view/Support/WebHome
配置文件 “/etc/ntp.conf :”
#记录系统时间与BIOS事件偏差的文件
driftfile /var/lib/ntp/drift
#server:指定ntp服务器
server 202.120.2.101 prefer iburst minpoll 1 maxpoll 8
## prefer:优先使用该时间服务器
## burst:当一个运程NTP服务器可用时,向它发送一系列的并发包进行检测。
## iburst:当一个运程NTP服务器不可用时,向它发送一系列的并发包进行检测。
## 参数minpoll和maxpoll指定NTP消息的最小和最大轮询间隔(以秒为单位)。
## 默认minpoll 6 maxpoll 10,表示的时间间隔分别为2的6次(64秒)方和2的10次方(1024秒)
## minpoll最小可设置为3(2的3次方=8s),maxpoll最大可设置为17(2的17次方=36h)
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org
# tinker [ allan allan | dispersion dispersion | freq freq | huffpuff huffpuff | panic panic | step step | stepout stepout ]
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1
restrict ::1
#restrict--控制相关权限:
#其中IP地址也可以是default ,default 就是指所有的IP
## ignore:关闭所有的 NTP 联机服务
## nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
## notrust:客户端除非通过认证,否则该客户端来源将被视为不信任子网
## noquery:不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器
## notrap:不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。
## nopeer:用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟
## kod:访问违规时发送 KoD 包。
## restrict -6 表示IPV6地址的权限设置。
总结一下,restrict用来设置访问权限,server用来设置上层时间服务器,driftfile用来设置保存漂移时间的文件。
官方参数解析:
ntpq是查询ntpd工作状态的命令,一般使用“ntpq -np”参数。
[root@host3 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
210.72.145.44 .INIT. 16 u - 64 0 0.000 0.000 0.000
+ntp1.ams1.nl.le 130.133.1.10 2 u 39 64 17 164.059 4.156 28.802
*sircabirus.von- 36.224.68.195 2 u 42 64 17 200.129 -2.154 5.885
-ntp2.flashdance 194.58.202.148 2 u 40 64 15 326.854 -2.366 29.832
+darwin.kenyonra 127.67.113.92 2 u 36 64 17 167.833 4.292 15.224
注意: NTP服务端重启后,客户机要等5分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。等待的时间可以通过命令 watch ntpq -p来监控。
这个使用特殊程序描述一个内核模型精确计时显示,他调用ntp_gettime()读取和显示时间相关的内核变量。类似的显示可以使用ntpdc程序的kerninfo命令。
[root@host2 ~]# ntptime
ntp_gettime() returns code 0 (OK)
time de5061d9.7034f000 Mon, Mar 12 2018 10:18:01.438, (.438308),
maximum error 116705 us, estimated error 7753 us, TAI offset 0
ntp_adjtime() returns code 0 (OK)
modes 0x0 (),
offset 0.000 us, frequency -13.286 ppm, interval 1 s,
maximum error 116705 us, estimated error 7753 us,
status 0x0 (),
time constant 4, precision 1.000 us, tolerance 500 ppm,
需要关注的数据:
用法指南:https://docs.oracle.com/cd/E56344_01/html/E54077/ntptime-1m.html#scrolltoc
ntpstat 命令查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。
[root@host2 ~]# ntpstat
timeout
[root@host2 ~]# ntpstat
unsynchronised
time server re-starting
polling server every 64 s
[root@host2 scripts]# ntpstat
unsynchronised
polling server every 8 s
设置本地日期和时间。它从指定的每个服务器获得了一些样本,并应用标准 NTP 时钟过滤器和选择算法来选择最好的样本。 语法: http://man.linuxde.net/ntpdate eg: 使用ntpdate命令同步网络时间
#安装ntpdate工具
[root@localhost sbin]# yum install -y ntp
##安装ntp的同时会同步安装ntpdate命令
#进行时间同步,语法:ntpdate ntp_server_address
[root@localhost sbin]# ntpdate ntp.ubuntu.com
3 Sep 20:28:54 ntpdate[3407]: step time server 91.189.91.157 offset 31565561.035581 sec
#查看时间:
[root@localhost sbin]# date
2017年 09月 03日 星期日 20:29:02 CST
注意:
<table><tr><td bgcolor=#00FFFF>因而,唯一一个可以令时间发生跳变的点,是计算机刚刚启动,但还没有启动很多服务的那个时候。其余的时候,理想的做法是使用ntpd来校准时钟,而不是调整计算机时钟上的时间。</td></tr></table>
参考:https://www.cnblogs.com/liuyou/archive/2012/07/29/2614330.html
公司部署的Hadoop(Kudu)集群总是因为节点之间的时差太大导致节点无法连接(服务宕机),经查看是因为节点之间的时间差导致的,所以需要手动调整系统时间后重启服务。
优化系统时间同步,减小系统时间偏移量。
过程: 服务宕机报错:
Error during hole punch test. The log block manager requires a
filesystem with hole punching support such as ext4 or xfs. On el6,
kernel version 2.6.32-358 or newer is required. To run without hole
punching (at the cost of some efficiency and scalability), reconfigure
Kudu with --block_manager=file. Refer to the Kudu documentation for more
details. Raw error message follows.
起初修复办法:https://kudu.apache.org/docs/troubleshooting.html#ntp (安装ntpd服务,重启服务,进行时间同步)
优化办法: 在ntp.conf配置文件中加入如下参数:
#调整时间同步的频率,将其限制在8秒到64秒之间
server 202.120.2.101 prefer iburst minpoll 3 maxpoll 6
#Apache的kudu官方建议(理由是缩小最大误差):
tinker dispersion 500
tinker allan 0
说明:通过调整系统时间的平滑同步平率来所需最大误差。 参考: http://www.mamicode.com/info-detail-1774325.html
(adsbygoogle = window.adsbygoogle || []).push({});