-
http://www.ntp.org.cn/index.php
全球可用的NTP服務(wù)器列表與解析服務(wù) - ntp.org.cn & ntpdate.net
同步時鐘最大的好處就是相關(guān)系統(tǒng)上日志文件中的數(shù)據(jù),如果網(wǎng)絡(luò)中使用中央日志主機集中管理日志,得到的日志結(jié)果就更能反映真實情況。在同步了時鐘的網(wǎng)絡(luò)中,集中式的性能監(jiān)控、服務(wù)監(jiān)控系統(tǒng)能實時的反應(yīng)系統(tǒng)信息,系統(tǒng)管理員可以快速的檢測和解決系統(tǒng)錯誤。
ntp時間服務(wù)器是一個簡單的常用的服務(wù)器,工作中我們只要做到會用就行,能搭建起來就可以了,不用太去深入研究ntp時間服務(wù)器的原理。
服務(wù)端的配置:
第一步,安裝NTP服務(wù):
1)rpm -ivh ntp-4.2.2p1-8.el5.centos.1.rpm
2)yum install -y ntp ntpdate
第二步,配置NTP服務(wù):
編輯配置文件/etc/ntp.conf ,配置之前記得先備份文件。
我的文件為

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
restrict 192.168.20.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.50.0 mask 255.255.255.0 nomodify notrap
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
- restrict default kod nomodify notrap nopeer noquery
restrict、default定義默認訪問規(guī)則,nomodify禁止遠程主機修改本地服務(wù)器 - restrict -6 default kod nomodify notrap nopeer noquery =====
配置,notrap拒絕特殊的ntpdq捕獲消息,noquery拒絕btodq/ntpdc查詢
restrict 127.0.0.1 (這里的查詢是服務(wù)器本身狀態(tài)的查詢)。
restrict -6 ::1
restrict 192.168.20.0 mask 255.255.255.0 nomodify notrap ===== 這句是手動增加的,意思是指定的192.168.20.1--192.168.20.254的服務(wù)器都
可以使用ntp服務(wù)器來同步時間。
server 192.168.1.117 ===== 手動添加,可以將局域網(wǎng)中的指定ip作為局域網(wǎng)內(nèi)的ntp服務(wù)器。
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
這3個域名都是互聯(lián)網(wǎng)上的ntp服務(wù)器,也還有許多其他可用的ntp服務(wù)器,能連上外網(wǎng)時,本地會跟這幾個ntp服務(wù)器上的時間保持同步。
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
當服務(wù)器與公用的時間服務(wù)器失去聯(lián)系時,就是連不上互聯(lián)網(wǎng)時,以局域網(wǎng)內(nèi)的時間服務(wù)器為客戶端提供時間同步服務(wù)。
第三步,啟動NTP服務(wù):
/etc/init.d/ntpd start 當前啟動ntpd服務(wù)
chkconfig ntpd on 下次開機自啟ntpd服務(wù)
第四步,檢查時間服務(wù)器是否正確同步
在服務(wù)端執(zhí)行 ntpq -p 下面是我在自己的服務(wù)器上面的測試的結(jié)果,僅供參考:

當所有遠程服務(wù)器(不是本地服務(wù)器)的jitter值都為4000,并且reach和dalay的值是0時,就表示時間同步有問題??赡茉蛴?個:
1)服務(wù)器端的防火墻設(shè)置,阻斷了123端口
(可以用 iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT 解決)
2)每次重啟ntp服務(wù)器之后,大約3-5分鐘客戶端才能與服務(wù)端建立連接,建立連接之后才能進行時間同步,否則客戶端同步時間時會顯示
no server suitable for synchronization found的報錯信息,不用擔(dān)心,等會就可以了。
客戶端的配置:
第一步,客戶端安裝NTP服務(wù):
yum install -y ntp
第二步,同步時間:
ntpdate 服務(wù)器IP或者域名