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 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 #允許局域網內所有client連接到這臺服務器 restrict -6 ::1 同步時間.但是拒絕讓他們修改服務器上的時間 #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 #同步公網的時間 server 127.127.1.0 #如果無法連接公網,則使用自己本身的時間作為標準時間。 fudge 127.127.1.0 stratum 10 #設置stratum級別 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
ignore:關閉所有的 NTP 聯機服務
nomodify:客戶端不能更改服務端的時間參數,但是客戶端可以通過服務端進行網絡校時
notrust:客戶端除非通過認證,否則該客戶端來源將被視為不信任子網
noquery:不提供客戶端的時間查詢
客戶端的安裝同服務器,如上。
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 #<==注釋默認的上層時間服務器
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntpserver #<==添加自己的時間服務器
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
在服務器端啟動NTP服務,命令如下:
/etc/init.d/ntpd start
添加開啟啟動:
chkconfig ntpd on
這樣就表示我們的 NTP 服務器已經啟動了,不過要與上層 NTP 服務器聯機則還需要一些時間, 通常啟動 NTP 后約在 15 分鐘內才會和上層 NTP 服務器順利連接上。 那要如何確認我們的 NTP 服務器有順利的更新自己的時間呢?你可以使用底下幾個指令來查閱喔 (請自行等待數分鐘后再以下列指令查閱):
這個指令可以列出我們的 NTP 服務器有跟上層聯機否。由上述的輸出結果可以知道,時間有校正約 258 * 10^(-3) 秒,且每隔 512秒會主動去更新時間喔!
各個參數的含義:
事實上這個輸出的結果告訴我們,時間真的很準了啦!因為差異都在 0.001 秒以內, 可以符合我們的一般使用了。另外,你也可以檢查一下你的 BIOS 時間與 Linux 系統時間的差異, 就是 /var/lib/ntp/drift 這個檔案的內容,就能了解到咱們的 Linux 系統時間與 BIOS 硬件時鐘到底差多久?單位為 10^(-6) 秒啦!
要讓你的 NTP Server/Client 真的能運作,在上述的動作中得注意:
上述的 ntpstat 以及 ntpq -p 的輸出結果中,你的 NTP 服務器真的要能夠連結上層 NTP 才行! 否則你的客戶端將無法對你的 NTP 服務器進行同步更新的!重要重要!
你的 NTP 服務器時間不可與上層差異太多。
服務器防火墻在 UDP port 123 有沒有開啊?要特別注意的呢!
更多關于云服務器,域名注冊,虛擬主機的問題,請訪問三五互聯官網:m.shinetop.cn