CentOS搭建NTP伺服器

來源:互聯網
上載者:User

標籤:default   service   設定檔   伺服器   客戶機ntp   時間伺服器   

一、搭建時間同步伺服器
1、編譯安裝ntp server
rpm -qa | grep ntp
若沒有找到,則說明沒有安裝ntp包,從光碟片上找到ntp包,使用
rpm -Uvh ntp***.rpm
進行安裝
2、修改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
3、啟動ntp服務
service ntpd start
開機啟動服務
chkconfig ntpd on
4、ntpd啟動後,客戶機要等幾分鐘再與其進行時間同步,否則會提示“no server suitable for synchronization found”錯誤。


二、配置時間同步客戶機

手工執行 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的設定。


本文出自 “Elephant” 部落格,請務必保留此出處http://zlyang.blog.51cto.com/1196234/1739478

CentOS搭建NTP伺服器

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.