版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、Network Time Protocol(NTP,網(wǎng)絡時間協(xié)議)用于同步它所有客戶端時鐘的服務。NTP 服務器將本地系統(tǒng)的時鐘與一個公共的NTP服務器同步然后作為時間主機提供服務,使 本地網(wǎng)絡的所有客戶端能同步時鐘。同步時鐘最大的好處就是相關系統(tǒng)上旦志文件中的數(shù)據(jù),如果網(wǎng)絡中使用中央日志主 機集中管理日志,得到的日志結(jié)果就更能反映真實情況。在同步了時鐘的網(wǎng)絡中,集中 式的性能監(jiān)控、服務監(jiān)控系統(tǒng)能實時的反應系統(tǒng)信息,系統(tǒng)管理員可以快速的檢測和解 決系統(tǒng)錯誤。安裝配置NTP服務下面將介紹NTP服務器的簡單配置第一步,安裝NTP服務一般的Linux發(fā)行版都會帶ntp軟件包,如果你的系統(tǒng)中還沒有安裝
2、,就使用rpm 命令安裝此包,以下以centos系統(tǒng)為例配置一臺時間服務器:查找當前系統(tǒng)是否已安裝ntprootlocalhost # rpm -qa | grep ntp chkf on tpath-1.10.1-1.1ntp-422p1-8.el5.centos.1(這個就是已經(jīng)安裝的RPM包)如果沒有安裝,可用下例命令安裝:rootlocalhost # rpm -ivh ntp-422p1-8.el5.centos.1.rpm第二步,配置NTP服務器NTP服務器配置如下:編輯配置文件/etc/ ntp.c onfrestrict default kod no modify no tra
3、p no peer no queryrestrict -6 default kod no modify no trap n opeer no queryrestrict restrict -6 :1restrict 192.16810 mask 2552552550 nomodify notrapserver 192 168 146225server 0.server 1.ce ntos.pool. server 2.server # local clockfudge stratum 10配置文件說明如下:第一行restrict、default定義默認訪問規(guī)則,nomodify禁止遠程主機修改
4、本地服務器 配置,notrap拒絕特殊的ntpdq捕獲消息,noquery拒絕btodq/ntpdc查詢(這里的查 詢是服務器本身狀態(tài)查詢)。restrict mask nomodify notrap這句是手動增加的,意思是從-54的服務器都可以使用我們 的NTP服務器來同步時間。server 25這句也是手動增加的,指明局域網(wǎng)中作為NTP服務器的IP;配置文件的最后兩行作用是當服務器與公用的時間服務器失去聯(lián)系時以本地時間為 客戶端提供時間服務。端口ntp使用udp協(xié)議,記得開放其123端口。啟動NTPD為了使NTP服務可以在系統(tǒng)引導的時候自動啟動,執(zhí)行:#chkc on fig n tpd
5、on啟動ntpd:service ntpd startNTP客戶端配置:在客戶端手動執(zhí)行“ntpdate服務器IP”來同步時間;另可以使用crond來定時同步時間:以root身份運行周期性任務:rootsupers un root# cron tab -e添加以下內(nèi)容,每15分鐘更新一下時間:15 * * * * ntpdate 服務器 IP此處的ntpdate命令包含在ntp軟件包中,記得確認系統(tǒng)中是否已安裝。第三步,檢査時間服務器是否正確同步使用下面的命令檢查時間服務器同步的狀態(tài):#ntpq -p一個可以證明同步有問題的證據(jù)是:所有遠程服務器的jitter值是4000并且delay和 re
6、ach的值是0??赡艿脑蛴校河蟹阑饓ψ钄嗔伺cserver之間的通訊,即123端口是否正常開放;此外每次重啟NTP服務器之后大約要35分鐘客戶端才能與server建立正常的通 訊連接,否則你在客戶端執(zhí)行“ntpdate服務器ip”的時候?qū)⒎祷兀?7 Jun 10:20:17 ntpdate21920: no server suitable for synchronization foundLinux下NTP服務器的配置Linux下的ntp軟件不但能自動與互聯(lián)網(wǎng)上的時鐘保持同步,同時本身已經(jīng)是一臺 SNTP服務器了,可以供局域網(wǎng)內(nèi)的電腦校對時間。服務配置如下:第一步安裝軟件包我用的是RPM包安裝
7、的,或者到/ntp/去下載xntp重 新編譯一個新的。#rpm -qa | grep ntpnt p-4.2.0-7chkfo ntpat h-1.10.0T第二步 讓LAN的時間服務器(第三級)與互聯(lián)網(wǎng)上的時間服務器(第一或者第二級)同步修改/e tc/n tp.conf這是NTP的主要配置文件,里面設置了你用來同步時間的時間服務器的域名或者IP 地址,下面是到 互聯(lián)網(wǎng)同步時間的最基本的配置:首先定義我們喜歡的時間服務器:server nt server ot her nt 接下來,我們設置上面兩臺服務器的訪問權限,在這個例子中我們不允許它們修改 或者查詢我們配置在Linux上的NTP服務器
8、res trie t nt mask 55 nomodify not rap noqueryres trie t ot her nt mask 55 nomodify not rap noquery掩碼55是用來 限制遠程NTP服務器的掩碼地址。接下來設置允許訪問我們時間服務器的客戶機地址,通常這些服務器都應該位于我 們自己局域網(wǎng)內(nèi)。請注意,配置中noquery已經(jīng)去掉了:res trie t mask not rus t nomodify not rap在上例中,掩碼地址擴展為255,因此從-54的服 務器都 可以使用我們的NTP服務器來同步時間。最后,也是最重要的是默認的限制配置要從你配置
9、文件中刪除,否則它將覆蓋你所 有的配置選項,你將發(fā)現(xiàn)如果不刪除該配置,你的時間服務器將只能和自己通訊。如果 ntp.conf中有以下一行,請將它注釋:#restriet default ignore保存你的配置文件,然后對每個你在nt p.conf里配置的時間服務器執(zhí)行2編查詢命 令:#nt pda te nt 27 Jun 10:12:01 ntpdate25475: adjust time server offset -0.127154 sec#nt pda te nt 27 Jun 10:12:06 ntpdate25478: adjust time server offset 0.01
10、0008 sec第三步啟動NTP進程為了使NTP服務可以在系統(tǒng)引導的時候自動啟動,執(zhí)行:#chkconfig ntpd on啟動/關閉/重啟NTP/查看狀態(tài)的命令是:#/etc/init .d/ntpd start#/etc/init .d/ntpd stop#/etc/init .d/ntpd restart#/etc/init .d/ntpd status切記每次修改了配置文件后都需要重新啟動服務來使配置生效。可以使用下面的命 令來檢查NTP服務 是否啟動,你應該可以得到一個進程ID號:#pgrep ntpd 第四步 檢査時間服務器是否正確同步使用下面的命令檢查時間服務器同步的狀態(tài):#nt
11、pq -p一個可以證明同步問題的證據(jù)是所有遠程服務器的jitter值是4000并且delay和reach的值是0??赡艿脑蛴校号渲梦募械膔estrict default ignore沒有被注釋有防火墻阻斷了與server之間的通訊此外每次重啟NTP服務器之后大約要3 5分鐘客戶端才能與server建立正常的通 訊連接,否則你執(zhí)行nt pda te ip的時候?qū)⒎祷兀?7 Jun 10:20:17 nt pda te21920: no server suit able for synchroniza tion found第五步客戶端與ntp服務器同步時間在客戶端安裝NTP,安裝過程同NTP在
12、服務器端??蛻舳碎_啟ntp服務#service ntpd start與ntp服務器同步#ntpdate (ntp服務器地址)接下來編輯/et c/n tp.confnt p.conf# #server # local clockfudge stratum 10server stdti .hk # A stratum 1 server at server 192.168.x.y #x.y為你前面所裝機器在局域網(wǎng)里的IPdriftfile /etc/ntp/driftbroadcastdelay 0.008authenticate nokeys /etc/ntp/keysres trie t 19
13、2.168.X.0 mask not rus t nomodify not rap/x.0 為你 所在局域網(wǎng)段res trie t restrict 192.168.x.y #x.y為你前面所裝機器在局域網(wǎng)里的IP#restriet default ignore# #同時配置#/sbin/service ntpd start /啟動 ntpd 參數(shù)可為 res tart start stop#/sbin/chkconfig -add ntpd#/sbin/chkconfig -level 234 nt pd on /配置在開機時運行如何檢查?#netstat -unl | grep 123 /
14、查看 123 端口#ndptrace 192.168.x.y /看校對時間過程,出現(xiàn)offset即為正常 否則為time out# ntpq -p如果出現(xiàn)jitter的值為4000則是防火墻或者網(wǎng)絡問題正常為remote refid st t when poll reach delay offset jitter*clock.nc.fukuok .GPS. 1 u 43 64 37 19.067 -6.884 10.339+clock. tl.fukuok .GPS. 1 u 36 64 35 19.670 -3.259 2.341 L0CAL(0) L0CAL(0) 5 l 45 64 37
15、 0.000 0.000 0.001幾點注意:1雖然ntp溢出問題較少,但建議配置大型網(wǎng)羅的時候,不要裝在重要數(shù)據(jù)庫服務 器或者Web主機上(Ntp是root權限)2在遇到問題之前,先看看ntp自帶的文檔。3防火墻問題的話,送一句配置$TMP -t filter -A INPUT -p udp -destination-port 123 -j ACCEPT 也就是123 udp in全部接受。如果子網(wǎng)IP仍然提示4000錯誤,可以把res trie t mask not rus t nomodify not rap改為res trie t mask nomodify對于權限參數(shù)的說明可以參考臺
16、灣鳥哥的文章的說明:rootroot# vi /etc/ntp.conf1.關於權限設定部分權限的設定主要以restrict這個參數(shù)來設定,主要的語法為:restriet IP mask netmask_IP parameter其中IP可以是軟體位址,也可以是default , default就類似咯!至於param ter則有:ignore:關閉所有的NTP連線服務nomodify:表示Client端不能更改Server端的時間參數(shù),不過,Client端仍然可以透過Server端來進行網(wǎng)路校時。notrust:該Client除非通過認證,否則該Client來源將被視為不信任網(wǎng)域noquery
17、 :不提供Client端的時間查詢?nèi)绻鹥aram ter完全沒有設定,那就表示該IP (或網(wǎng)域)沒有任何限制!#在我們這個例子當中,因為拒絕所有,僅開放/24,並且讓以及本機IP 可以不受限制,所以: restrict default ignore #關閉所有的NTP要求封包res trict #開啟內(nèi)部遞迴網(wǎng)路介面lorestrict #主機本身的IP也同時開啟!res trict 0mask 55 nomodify#針對另一個IP開放讓他可以更新時間!res trict mask nomodify#在網(wǎng)域裡面的client可以進行網(wǎng)路校時,但不會影響Server !2.上層主機的設定上層主
18、機我們選擇. tw,要設定上層主機主要以server這個參數(shù)來設定,語法為:#server IP|FQDN prefer#Server後面接的就是我們上層Time Server囉!而如果Server參數(shù)後面加上perfer的話,那表示我們的NTP主機主要以該部主機來作為時間校正的對應。另外,為了解決更新時間封包的傳送延遲動作,所以可以使用driftfile來規(guī)定我們的主機在與Time Server溝通時所花費的時間,可以記錄在driftfile後面接的檔案內(nèi),例如下面的範例中,我們的NTP server與. tw連線時所花費的時間會記錄在/etc/ntp/drift檔案內(nèi)#先輸入第二層主機的I
19、Pserver 0 preferserver 0 prefer server 55 prefer#第一層的主機就列為參考用!server 0server 1server 51#當然要讓Server可以進入我們的NTP主機啦!權限要開放啊!res trict 0restrict 0restrict 55restrict 0res trie t 1restrict 51driftfile /etc/ntp/drift最后附上我的修改過后的/etc/ntp.conf文件。參考了以下幾篇文章:在RedHat9下配置時間服務器時間同步NTP服務器的配置 原創(chuàng)linux NTP配置 簡易 NTP 伺服器設
20、定Prohibit general access to this service.#restriet default ignoreres trie tmask55nomodifynot rapnoqueryres trie tmask55nomodifynot rapnoqueryres trie tmask55nomodifynot rapnoqueryres trie tmask55nomodifynot rapnoqueryPermit all access over the loopback interface. This couldbe tightened as well, but
21、to do so would effect some ofthe administrative functions.res trie t CLIENT NETWORK Permit systems on this network to synchronize with thistime service. Do not permit those systems to modify theconfiguration of this service. Also, do not use thosesystems as peers for synchronization.res trie t mask
22、nomodifyOUR TIMESERVERSor remove the default restriet linePermit time synchronization with our time source, but do notpermit the source to query or modify the service on this system.restriet mytrustedtimeserverip mask 55 nomodify notrap noqueryserver mytrustedtimeserveripNTP MULTICASTCLIENT#mu lti c
23、as tclien t# lis ten on defau lt res trie t mask 55 not rus t nomodify not rapres trie t mask not rus t nomodify not rapGENERAL CONFIGURATION#Undisciplined Local Clock. This is a fake driver intended for backupand when no outside source of synchronized time is available. Thedefault stratum is usuall
24、y 3, but in this case we elect to use stratum0. Since the server line does not have the prefer keyword, this driveris never used for synchronization, unless no other othersynchronization source is available. In case the local host iseontrolled by some external source, such as an external oscillator
25、oranother protocol, the prefer keyword would cause the local host todisregard all other synchronization sources, unless the kernelmodifications are in use and declare an unsynchronized condition.#server fudge stratum 10#Drift file. Put this in a directory which the daemon can write to.No symbolic li
26、nks allowed, either, since the daemon updates the fileby creating a temporary in the same directory and then rename()ingit to the file.#driftfile /var/lib/ntp/driftbroadcastdelay 0.008#Authentication delay. If you use, or plan to use someday, theauthentication facility you should make the programs i
27、n the auth_stuffdirectory and figure out what this number should be on your machine.#authenticate yes#Keys file. If you want to diddle your server at run time, make akeys file (mode 600 for sure) and define the key number to beused for making requests.#PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick
28、 your own, or remotesystems might be able to reset your clock at will. Note also thatntpd is started with a -A flag, disabling authentication, thatwill have to be removed as well.#keys/etc/ntp/keysLinux 配置 NTP 服務器2012-06-14 11:11:41| 分類:Linux字號 訂閱1驗證Server上的NTP版本 roottestdb # rpm -q ntp n tp-4.2.2p1
29、-9.el5_4.1如果沒有安裝,需要在安裝光盤的Server目錄下找到ntp-*.rpm并安裝2修改有關權限的設置roottestdb # vim /etc/ ntp.conf常用選項:ignore:禁止所有的NTP請求包進入nomodify:禁止其他計算機更改本機NTP服務的設置,但可以通過NTP服務器進行網(wǎng) 絡校時notrust:禁止所有未通過認證的NTP包進入 noquery:禁止其他計算機查詢本機NTP服務的狀態(tài)我這里的設置:restrict default no modify no trap no queryrestrict restrict mask nomodify notra
30、prestrict mask nomodify notrapserver 0.asia.pool. server 1.asia.pool. server 2.asia.pool. server 3.asia.pool. server fudge stratum 103啟動NTProottestdb # /etc/ in it.d/ntpd start4停止NTProottestdb # /etc/ in it.d/ntpd stop5重啟NTProottestdb # /etc/ in it.d/ntpd restart6設置NTP隨系統(tǒng)啟動自動加載roottestdb # chkc on f
31、ig n tpd on7檢查NTP服務同步狀態(tài)roottestdb # n tpq -p8客戶端時間同步命令ntpdate 8 (此IP地址為配置的本地NTP服務器的IP地址)當用 ntpdate -d 來查詢時會發(fā)現(xiàn)導致 no server suitable for synchronization found 的 錯誤的信息有以下2個:錯誤 1.Server dropped: Strata too high在 ntp 客戶端運行 ntpdate serverIP,出現(xiàn) no server suitable for synchronization found 的錯誤。在 ntp 客戶端用 ntpdate -d serverIP 查看,發(fā)現(xiàn)有Server dropped: strata too high”的 錯誤,并且顯示stratum 16”。而正常情況下stratum這個值得范圍是015”。這是因為NTP server還沒有和其自身或者它的server同步上。以下的定義是讓NTP Server和其自身保持同步,如果在/etc/ntp.conf中定義的server 都不可用時,將使
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年“新九論”學習心得體會例文(3篇)
- 2025年湖南貨運從業(yè)資格證新政
- 2025年濰坊b2貨運資格證多少道題
- 二零二五版籃球場地租賃及賽事門票銷售合同3篇
- 2025版體檢服務信息化建設合作合同協(xié)議2篇
- 2024跨國公司研發(fā)中心合作合同
- 二零二五年度城市綜合體消防安全管理代理服務合同3篇
- 二零二五年度合同擔保制度標準合同范本匯編3篇
- 2025版天然氣發(fā)電機組購銷合同范本3篇
- 2025年度個人對公司借款及稅收優(yōu)惠合同規(guī)范4篇
- 無人化農(nóng)場項目可行性研究報告
- 《如何存款最合算》課件
- 社區(qū)團支部工作計劃
- 拖欠工程款上訪信范文
- 2024屆上海市金山區(qū)高三下學期二模英語試題(原卷版)
- 《wifi協(xié)議文庫》課件
- 《好東西》:女作者電影的話語建構(gòu)與烏托邦想象
- 教培行業(yè)研究系列(七):出國考培的再研究供需變化的新趨勢
- 真人cs基于信號發(fā)射的激光武器設計
- 2024年國信證券招聘筆試參考題庫附帶答案詳解
- 道醫(yī)館可行性報告
評論
0/150
提交評論