1、搭建時間同步服務器
一、編譯安裝ntp server
rpm -qa | grep ntp
若沒有找到,則說明沒有安裝ntp包,從光盤上找到ntp包,使用
rpm -Uvh ntp***.rpm
進行安裝
二、修改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
三、啓動ntp服務
service ntpd start
開機啓動服務
chkconfig ntpd on
四、ntpd啓動後,客戶機要等幾分鐘再與其進行時間同步,不然會提示「no server suitable for synchronization found」錯誤。服務器
2、配置時間同步客戶機
手工執行 ntpdate <ntp server> 來同步
或者利用crontab來執行
crontab -e
0 21 * * * ntpdate 192.168.211.22 >> /root/ntpdate.log 2>&1
天天晚上9點進行同步
附:
當用ntpdate -d 來查詢時會發現致使 no server suitable for synchronization found 的錯誤的信息有如下2個:
錯誤1.Server dropped: Strata too high
在ntp客戶端運行ntpdate serverIP,出現no server suitable for synchronization found的錯誤。
在ntp客戶端用ntpdate –d serverIP查看,發現有「Server dropped: strata too high」的錯誤,而且顯示「stratum 16」。而正常狀況下stratum這個值得範圍是「0~15」。
這是由於NTP server尚未和其自身或者它的server同步上。
如下的定義是讓NTP Server和其自身保持同步,若是在/ntp.conf中定義的server都不可用時,將使用local時間做爲ntp服務提供給ntp客戶端。
server 127.127.1.0
fudge 127.127.1.0 stratum 8
在ntp server上從新啓動ntp服務後,ntp server自身或者與其server的同步的須要一個時間段,這個過程多是5分鐘,在這個時間以內在客戶端運行ntpdate命令時會產生no server suitable for synchronization found的錯誤。
那麼如何知道什麼時候ntp server完成了和自身同步的過程呢?
在ntp server上使用命令:
# watch ntpq -p
出現畫面:
Every 2.0s: ntpq -p Thu Jul 10 02:28:32 2008
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.30.22 LOCAL(0) 8 u 22 64 1 2.113 179133. 0.001
LOCAL(0) LOCAL(0) 10 l 21 64 1 0.000 0.000 0.001
注意LOCAL的這個就是與自身同步的ntp server。
注意reach這個值,在啓動ntp server服務後,這個值就從0開始不斷增長,當增長到17的時候,從0到17是5次的變動,每一次是poll的值的秒數,是64秒*5=320秒的時間。
若是以後從ntp客戶端同步ntp server還失敗的話,用ntpdate –d來查詢詳細錯誤信息,再作判斷。
錯誤2.Server dropped: no data
從客戶端執行netdate –d時有錯誤信息以下:
transmit(192.168.30.22) transmit(192.168.30.22)
transmit(192.168.30.22)
transmit(192.168.30.22)
transmit(192.168.30.22)
192.168.30.22: Server dropped: no data
server 192.168.30.22, port 123
.....
28 Jul 17:42:24 ntpdate[14148]: no server suitable for synchronization found出現這個問題的緣由可能有2:
1。檢查ntp的版本,若是你使用的是ntp4.2(包括4.2)以後的版本,在restrict的定義中使用了notrust的話,會致使以上錯誤。
使用如下命令檢查ntp的版本:
# ntpq -c version
下面是來自ntp官方網站的說明:
The behavior of notrust changed between versions 4.1 and 4.2.
In 4.1 (and earlier) notrust meant "Don't trust this host/subnet for time".
In 4.2 (and later) notrust means "Ignore all NTP packets that are not cryptographically authenticated." This forces remote time servers to authenticate themselves to your (client) ntpd
解決:
把notrust去掉。
2。檢查ntp server的防火牆。多是server的防火牆屏蔽了upd 123端口。
能夠用命令
#service iptables stop
來關掉iptables服務後再嘗試從ntp客戶端的同步,若是成功,證實是防火牆的問題,須要更改iptables的設置。網站