server 0.centos.pool.ntp.org iburst     #默認的上層時間服務(wù)器 server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst includefile /etc/ntp/crypto/pw keys /etc/ntp/keys

修改配置

cat /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery     #對默認的client拒絕所有操作
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1                                      #允許本機的一切操作
restrict 192.168.1.0 mask 255.255.255.0 nomodify    #允許局域網(wǎng)內(nèi)所有client連接到這臺服務(wù)器
restrict -6 ::1                                         同步時間.但是拒絕讓他們修改服務(wù)器上的時間
#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
server ntp1.aliyun.com          #同步公網(wǎng)的時間
server 127.127.1.0              #如果無法連接公網(wǎng),則使用自己本身的時間作為標準時間。
fudge 127.127.1.0 stratum 10    #設(shè)置stratum級別
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
3.4 restrict安全相關(guān)參數(shù)

ignore:關(guān)閉所有的 NTP 聯(lián)機服務(wù) 
nomodify:客戶端不能更改服務(wù)端的時間參數(shù),但是客戶端可以通過服務(wù)端進行網(wǎng)絡(luò)校時 
notrust:客戶端除非通過認證,否則該客戶端來源將被視為不信任子網(wǎng) 
noquery:不提供客戶端的時間查詢 

4   Client的安裝和配置

客戶端的安裝同服務(wù)器,如上。

4.1 配置文件
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery    
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
#server 0.centos.pool.ntp.org iburst #<==注釋默認的上層時間服務(wù)器 #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server ntpserver        #<==添加自己的時間服務(wù)器 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
5    服務(wù)器端啟動

在服務(wù)器端啟動NTP服務(wù),命令如下:

/etc/init.d/ntpd start

添加開啟啟動:

chkconfig ntpd on
6    NTP的啟動與觀察
6.1 查看啟動的端口

這樣就表示我們的 NTP 服務(wù)器已經(jīng)啟動了,不過要與上層 NTP 服務(wù)器聯(lián)機則還需要一些時間, 通常啟動 NTP 后約在 15 分鐘內(nèi)才會和上層 NTP 服務(wù)器順利連接上。 那要如何確認我們的 NTP 服務(wù)器有順利的更新自己的時間呢?你可以使用底下幾個指令來查閱喔 (請自行等待數(shù)分鐘后再以下列指令查閱):

6.2 查看NTP服務(wù)器上層聯(lián)機

這個指令可以列出我們的 NTP 服務(wù)器有跟上層聯(lián)機否。由上述的輸出結(jié)果可以知道,時間有校正約 258 * 10^(-3) 秒,且每隔 512秒會主動去更新時間喔!

6.3 列出目前我們的NTP與相關(guān)的上層NTP的狀態(tài)

各個參數(shù)的含義:

事實上這個輸出的結(jié)果告訴我們,時間真的很準了啦!因為差異都在 0.001 秒以內(nèi), 可以符合我們的一般使用了。另外,你也可以檢查一下你的 BIOS 時間與 Linux 系統(tǒng)時間的差異,   就是 /var/lib/ntp/drift 這個檔案的內(nèi)容,就能了解到咱們的 Linux 系統(tǒng)時間與 BIOS 硬件時鐘到底差多久?單位為 10^(-6) 秒啦!

7    注意

要讓你的 NTP Server/Client 真的能運作,在上述的動作中得注意:

上述的 ntpstat 以及 ntpq -p 的輸出結(jié)果中,你的 NTP 服務(wù)器真的要能夠連結(jié)上層 NTP 才行! 否則你的客戶端將無法對你的 NTP 服務(wù)器進行同步更新的!重要重要!

你的 NTP 服務(wù)器時間不可與上層差異太多。

服務(wù)器防火墻在 UDP port 123 有沒有開啊?要特別注意的呢!

更多關(guān)于云服務(wù)器域名注冊,虛擬主機的問題,請訪問三五互聯(lián)官網(wǎng):m.shinetop.cn

贊(0)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享網(wǎng)絡(luò)內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。郵箱:3140448839@qq.com。本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明出處:三五互聯(lián)知識庫 » 時間服務(wù)器-NTP

登錄

找回密碼

注冊