linux-ntp 使用

fei890910發表於2014-09-11
---伺服器端      
[oracle@node1:/home/oracle]#more /etc/ntp.conf
server 127.127.1.0 
fudge 127.127.1.0 stratum 8 
driftfile /var/lib/ntp/drift
broadcastdelay 0.0008

--客戶端 
[root@node2 ~]# more /etc/ntp.conf
server 192.168.10.21 prefer
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
----客戶端和伺服器都啟動ntp              
[root@node1:/etc/]#service ntpd start
Starting ntpd:                                             [  OK  ]

[root@node2 ~]# service ntpd start
Starting ntpd:                                             [  OK  ]
---首次時鐘同步之前               
[oracle@node1:/home/oracle]#ssh node2 date;date
Thu Sep 11 21:58:03 CST 2014
Thu Sep 11 21:58:01 CST 2014

客戶端停止ntp服務,並 等三五分鐘都在進行首次時鐘同步                                               
[root@node2 ~]# service ntpd stop
Shutting down ntpd:                                        [  OK  ]

[root@node2 ~]# ntpdate 192.168.10.21
11 Sep 21:59:13 ntpdate[10950]: step time server 192.168.10.21 offset -2.455153 sec
[root@node2 ~]# service ntpd start
Starting ntpd:                                             [  OK  ]
---時鐘同步之後           
[oracle@node1:/home/oracle]#ssh node2 date;date
Thu Sep 11 21:59:34 CST 2014
Thu Sep 11 21:59:34 CST 2014

如果有問題可以用這個命令檢視
[root@node2 ~]# ntpdate -d 192.168.10.21
11 Sep 21:56:30 ntpdate[10713]: ntpdate 4.2.2p1@1.1570-o Thu Nov 26 11:35:07 UTC 2009 (1)
Looking for host 192.168.10.21 and service ntp
host found : node1
transmit(192.168.10.21)
receive(192.168.10.21)
transmit(192.168.10.21)
receive(192.168.10.21)
transmit(192.168.10.21)
receive(192.168.10.21)
transmit(192.168.10.21)
receive(192.168.10.21)
transmit(192.168.10.21)
server 192.168.10.21, port 123
stratum 9, precision -20, leap 00, trust 000
refid [192.168.10.21], delay 0.02592, dispersion 0.00008
transmitted 4, in filter 4
reference time:    d7bc2857.2d44dc93  Thu, Sep 11 2014 21:55:35.176
originate timestamp: d7bc288d.4a7d86ad  Thu, Sep 11 2014 21:56:29.290
transmit timestamp:  d7bc288e.5b6cdf26  Thu, Sep 11 2014 21:56:30.357
filter delay:  0.02592  0.02599  0.02612  0.02596 
         0.00000  0.00000  0.00000  0.00000 
filter offset: -1.06622 -1.06634 -1.06628 -1.06634
         0.000000 0.000000 0.000000 0.000000
delay 0.02592, dispersion 0.00008
offset -1.066229
11 Sep 21:56:30 ntpdate[10713]: step time server 192.168.10.21 offset -1.066229 sec
                         

為了使NTP服務可以在系統引導的時候自動啟動,執行:

# chkconfig ntpd on 

配置了服務端後(並啟動SSH)在客戶端用:

# Crontab -e

*/5 * * * * /usr/sbin/ntpdate 192.168.8.240 >/dev/null 2>&1


     

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29108064/viewspace-1268037/,如需轉載,請註明出處,否則將追究法律責任。

相關文章