linux NTP協議配置
現在的網絡由于各種原因 對于時間同步要求很高——如電力、金融、通信、交通、廣電、安防、石化、冶金、水利、國防、醫療、教育、政府機關、IT等領域的網絡系統需要在大范圍保持計算機的時間同步和時間準確。
配置ntp協議就是他們要面對的一個問題,在NTP中有Ntp,xntp等各種軟件。我們選用Rad Hat中標配的NTP協議。
首先讓大家了解下NTP協議:
使用端口123
協議 UDP
用處 同步網絡時鐘源
首先到下載ntp-4.1.1-1.i386.rpm
(ftp://rpmfind.net/linux/redhat/7.3/en/....1.1-1.i386.rpm)
不下載的,因為高版本可能你的linux版本(AS 3.1)不支持,并且不要選4.0.9版本(有溢出漏洞)
如果鏈接失效推薦一個不錯的搜索引擎(http://rpmfind.net/linux/rpm2html/search.php)
#wget ftp://rpmfind.net/linux/redhat/7.3/en/....1.1-1.i386.rpm
#rpm -ivh ntp-4.1.1-1.i386.rpm //默認安裝即可
接下來編輯 /etc/ntp.conf
首先你可以去ntp.org上找到哪些ntp服務器離你較近
ntp.conf
#############################################################################################
server clock.tl.fukuoka-u.ac.jp #校對服務器1
server clock.uregina.ca
server swisstime.ethz.ch
server ntp0.fau.de # 比較多的服務器可以防止因為網絡故障導致無法校對時間
server 127.127.1.1 #這行可刪除
fudge 127.127.1.1 stratum 10 #同上
driftfile /etc/ntp/drift #/etc/ntp/drift 可能是ntp.drift 這無所謂,看你的版本號
restrict clock.tl.fukuoka-u.ac.jp
restrict clock.cuhk.edu.hk
restrict swisstime.ethz.ch
restrict ntp0.fau.de
restrict 127.0.0.1
restrict 192.168.x.y #x.y為自己的IP
restrict 192.168.x.x mask 255.255.255.0 nomodify #讓x網段的機器都能訪問自己,進行時間校對
#restrict default ignore #這行刪除或注釋都可以
#############################################################################################
#/sbin/service ntpd start //啟動ntpd 參數可為restart start stop
#/sbin/chkconfig --add ntpd
#/sbin/chkconfig --level 234 ntpd on //配置在開機時運行
接下來在客戶端安裝NTP
安裝過程同上
接下來編輯 /etc/ntp.conf
ntp.conf
#############################################################################################
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
server stdtime.gov.hk # A stratum 1 server at server.org
server 192.168.x.y #x.y為你前面所裝機器在局域網里的IP
driftfile /etc/ntp/drift
broadcastdelay 0.008
authenticate no
keys /etc/ntp/keys
restrict 192.168.x.0 mask 255.255.255.0 notrust nomodify notrap//x.0為你所在局域網段
restrict 127.0.0.1
restrict 192.168.x.y #x.y為你前面所裝機器在局域網里的IP
#restrict default ignore
#############################################################################################
同時配置
#/sbin/service ntpd start //啟動ntpd 參數可為restart start stop
#/sbin/chkconfig --add ntpd
#/sbin/chkconfig --level 234 ntpd on //配置在開機時運行
如何檢查?
#netstat -unl | grep 123 //查看123端口
#ndptrace 192.168.x.y //看校對時間過程,出現offset即為正常 否則為time out
# ntpq -p
如果出現 jitter的值 為4000則是防火墻或者網絡問題
正常為
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
LOCAL(0) LOCAL(0) 5 l 45 64 37 0.000 0.000 0.001
幾點注意:
1.雖然ntp溢出問題較少 ,但建議配置大型網羅的時候,不要裝在重要數據庫服務器或者Web主機上(Ntp是root權限)
2.在遇到問題之前,先看看ntp協議自帶的文檔
3.防火墻問題的話,送一句配置
$TMP -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT
也就是123 udp in 全部接受