NTP时钟同步学习记录

# NTP机制流程学习小记  2016-12-1
要点回顾 . 1. NTP唯一配置文件:/etc/ntp.conf . 2. NTP系统日志记录:/var/log/ntp . 3. ntp.conf简要介绍
- 利用 restrict 来管理权限控制:
   
restrict IP地址 #允许该IP在本机NTP服务器进行查询和同步
- 利用server设定NTP上级服务器:
server [IP or hostname] [prefer] . 4. 手动同步上级IP时间(可用于检测上级ntp服务是否正常):
   # ntpdate IP地址
   或者:
# sntp
-P no -r IP地址 // 备注:Suse 11版本中摒弃了ntpdate命令,采用新的sntp命令操作
1   查询命令"ntpq -p"
1.1 "ntpq -p"展示server顺序:与ntp.conf中server配置的前后顺序一致。
    # 查询状态如下:
    svr-0:/opt/***/bin # ntpq -np
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    *10.148.146.28   LOCAL(0)        11 u   55   64  377    0.449    0.021   0.022
     LOCAL(0)        .LOCL.           5 l   27   64  377    0.000    0.000   0.001
     # 备注:『*』代表目前正在使用的上级NTP;『+』代表已经连上,作为下一个供对时的侯选者
     
1.2 ntp获取上级时钟源顺序,按照配置文件上下先后顺序,优选prefer。
    
2   时钟跳变时处理机制
2.1 有多个server,正在对时的server跳变超过1000S(默认), 会取消从该server对时,并尝试切换至其他可用时钟源。
    # 例如:上级时钟源跳变后,示例环境会切换至本地时钟源。查询状态如下: 
    svr-0:/opt/***/bin # service ntp status
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
     10.148.146.28   LOCAL(0)        11 u   50   64  377    0.442  -424067 320564.
    *LOCAL(0)        .LOCL.           5 l   18   64  377    0.000    0.000   0.001
    # 对应/var/log/ntp日志记录:synchronized to LOCAL(0), stratum 5 
    
2.2 取消从上级server对时后,如果没有其他可用(含本地)的时钟源,则本机ntp服务%dead%。
    # 查询状态如下:
    svr-0:/opt/***/bin # ntpq -np
    ntpq: read:Connection refused
    svr-0:/opt/***/bin # service ntp status
    Checking for netword time protocol daemon (NTPD)           dead
    # 对应/var/log/ntp日志记录:time correction of 334 seconds exceeds sanity limit (60); set clock manually to the correct UTC time.
    @@ 注意:该句日志也是我们上报告警与否的重要依据。
    
2.3 只有本地时钟源,本地时钟源跳变(date -s修改时间),不会使得本机ntp服务挂掉,状态正常。
    # 对应/var/log/ntp日志会有记录:kernel time sync status change 2001


 
原文地址:https://www.cnblogs.com/eaglediao/p/6606795.html