立即注册 登录
About云-梭伦科技 返回首页

heraleign的个人空间 https://www.aboutyun.com/?14519 [收藏] [复制] [分享] [RSS]

日志

NTP

已有 826 次阅读2018-7-1 11:51 |个人分类:NTP|系统分类:大数据| NTP

安装:
服务端
[root@hd150 ~]# yum install ntp
[root@hd150 ~]# chkconfig ntpd on
[root@hd150 ~]# ntpdate -u 202.112.10.36
[root@hd150 ~]# more /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1 
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# ***************add by luoyw***************************
restrict 192.168.137.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# *************** comment by luoyw *********************
#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 210.72.145.44 perfer      # china public
server 202.112.10.36             # 1.cn.pool.ntp.org
server 59.124.196.83             # 0.asia.pool.ntp.org

#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 autokey            # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# ***************add by luoyw***************************
restrict 210.72.145.44 nomodify notrap noquery
restrict 202.112.10.36 nomodify notrap noquery
restrict 59.124.196.83 nomodify notrap noquery
# ***************add by luoyw***************************
server  127.127.1.0 # local clock
fudge   127.127.1.0 stratum 10

# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

service ntpd start
netstat -tlunp | grep ntp
ntpq -p
ntpstat 

客户机
[root@hd151 ~]# yum install ntp
[root@hd151 ~]# chkconfig ntpd on
[root@hd151 ~]# vi /etc/ntp.conf
[root@hd151 ~]# more /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict -6 ::1

# server
server 192.168.137.150
 
restrict 192.168.137.150 nomodify notrap noquery
 
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10
 
includefile /etc/ntp/crypto/pw
 
keys /etc/ntp/keys

[root@hd151 ~]# ntpdate -u 192.168.137.150

[root@hd151 ~]# scp /etc/ntp.conf root@hd152:/etc/ntp.conf
[root@hd151 ~]# service ntpd start
[root@hd151 ~]# ntpstat


# watch ntpq -p
Every 2.0s: ntpq -p                                  Sat Jul  7 00:41:45 2007
     remote           refid      st t when poll reach   delay   offset  jitter
===========================================================
+193.60.199.75   193.62.22.98     2 u   52   64  377    8.578   10.203 289.032
*mozart.musicbox 192.5.41.41      2 u   54   64  377   19.301  -60.218 292.411

现在我就来解释一下其中的含义
  remote: 它指的就是本地机器所连接的远程NTP服务器
      refid: 它指的是给远程服务器(e.g. 193.60.199.75)提供时间同步的服务器
          st: 远程服务器的层级别(stratum). 由于NTP是层型结构,有顶端的服务器,多层的Relay Server再到客户端. 所以服务器从高到低级别可以设定为1-16. 为了减缓负荷和网络堵塞,原则上应该避免直接连接到级别为1的服务器的.
            t: 这个.....我也不知道啥意思^_^
    when: 我个人把它理解为一个计时器用来告诉我们还有多久本地机器就需要和远程服务器进行一次时间同步
       poll: 本地机和远程服务器多少时间进行一次同步(单位为秒). 在一开始运行NTP的时候这个poll值会比较小,那样和服务器同步的频率也就增加了,可以尽快调整到正确的时间范围.之后poll值会逐渐增大,同步的频率也就会相应减小
    reach: 这是一个八进制值,用来测试能否和服务器连接.每成功连接一次它的值就会增加
    delay: 从本地机发送同步要求到服务器的round trip time
    offset: 这是个最关键的值, 它告诉了我们本地机和服务器之间的时间差别. offset越接近于0,我们就和服务器的时间越接近
     jitter: 这是一个用来做统计的值. 它统计了在特定个连续的连接数里offset的分布情况. 简单地说这个数值的绝对值越小我们和服务器的时间就越精确


路过

雷人

握手

鲜花

鸡蛋

全部作者的其他最新日志

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

关闭

推荐上一条 /2 下一条