004.NTP多層級架設

一 環境需求

1.1 需求

User-client:局域網全部節點主機;
IN-NTP Server:隱藏於局域網內部的NTP服務器;
Border-NTP:邊界NTP服務器,用於同步外部時鐘,同時對內部IN-NTP服務器提供校對;
亞洲授時中心:公網NTP授時中心。
內部局域網全部節點client須要和IN-NTP Server同步,IN-NTP Server對外隱藏,同時經過 Border-NTP進行同步, Border-NTP邊界NTP服務器實時同步公網授時中心。

1.2 架構

08
主機名
IP
備註
border_ntp
內網IP:172.24.8.71
邊界NTP服務器
in_ntp01
172.24.8.72
內部NTP服務器01
in_ntp02
172.24.8.73
內部NTP服務器02
client
172.24.8.74
模擬局域網內部客戶端節點
注意:
  • Border-NTP部署在邊界上,做爲和互聯網(亞洲授時中心)同步,同時爲局域網內部IN-NTP提供同步服務。
  • User-client,包括全部局域網內客戶端等,從兩臺(一主一備)IN-NTP進行同步。

二 Border-NTP配置

2.1 服務包安裝

  1 [root@border_ntp ~]# rpm -qa | grep ntp
  2 [root@border_ntp ~]# yum -y install ntp			#安裝ntp服務

2.2 ntp配置

  1 [root@border_ntp ~]# vi /etc/ntp.conf
  2 driftfile /var/lib/ntp/drift
  3 #定義與上級時間服務器聯繫時所花費的時間,記錄在driftfile參數後面的文件內。
  4 driftfile   /var/lib/ntp/drift
  5 pidfile     /var/run/ntpd.pid				#進程pid文件
  6 logfile     /var/log/ntp.log				#開啓日誌記錄
  7 #定義與上級時間服務器聯繫時所花費的時間,記錄在driftfile參數後面的文件內。
  8 
  9 restrict default nomodify notrap nopeer noquery	        #默認拒絕全部NTP鏈接
 10 restrict 127.0.0.1
 11 restrict ::1 						#開啓本地受權
 12 
 13 restrict 172.24.8.72 mask 255.255.255.255 nomodify notrap	#添加IN-NTP Server容許校時
 14 restrict 172.24.8.73 mask 255.255.255.255 nomodify notrap	#添加IN-NTP Server容許校時
 15 
 16 #server 0.cn.pool.ntp.org
 17 #server 1.asia.pool.ntp.org
 18 #restrict 0.cn.pool.ntp.org nomodify notrap noquery
 19 #restrict 1.asia.pool.ntp.org nomodify notrap noquery
 20 #添加Border-NTP的上一級時間中心,即亞洲授時中心服務器,此處建議註釋,轉而採用國內阿里雲時鐘,相對網絡更穩定,以下。
 21 server ntp1.aliyun.com iburst minpoll 4 maxpoll 10
 22 restrict ntp1.aliyun.com nomodify notrap nopeer noquery
 23 server ntp2.aliyun.com iburst minpoll 4 maxpoll 10
 24 restrict ntp2.aliyun.com nomodify notrap nopeer noquery
 25 #容許阿里授時中心修改本地時間。
 26 server 127.127.1.0
 27 fudge 127.127.1.0 stratum 4
 28 #當授時不可用,採用本地時間,stratum級別爲4。

2.3 其餘配置

  1 [root@border_ntp ~]# chown ntp:ntp /var/log/ntp.log
  2 [root@border_ntp ~]# chcon -t ntpd_log_t /var/log/ntp.log
  3 [root@border_ntp ~]# firewall-cmd --permanent --add-service=ntp
  4 [root@border_ntp ~]# firewall-cmd --reload
  5 [root@border_ntp ~]# setenforce 0
提示:若開啓日誌功能,須要ntp進程具有寫入日誌權限。同時防火牆開放ntp服務,SELinux寫入上下文受權。
建議:若沒有特殊必要,建議關閉SELinux和防火牆。

2.4 開啓服務

  1 [root@border_ntp ~]# systemctl start ntpd.service
  2 [root@border_ntp ~]# systemctl enable ntpd.service
提示:開啓ntp server後,須要等待必定時間(一般爲5分鐘之內),才能實現和亞洲授時中心的同步。

2.5 驗證

  1 [root@border_ntp ~]# ntpq -np
09
提示:ntpq相關含義見附錄一。

三 IN-NTP Server配置

3.1 服務包安裝

  1 [root@in_ntp01 ~]# rpm -qa | grep ntp			#查看是否安裝ntp
  2 [root@in_ntp01 ~]# yum -y install ntp			#安裝ntp服務

3.2 ntp配置

  1 [root@in_ntp01 ~]# vi /etc/ntp.conf
  2 driftfile   /var/lib/ntp/drift
  3 pidfile     /var/run/ntpd.pid				#進程pid文件
  4 logfile     /var/log/ntp.log				#開啓日誌記錄
  5 #定義與上級時間服務器聯繫時所花費的時間,記錄在driftfile參數後面的文件內。
  6 tinker stepout 0
  7 restrict    default ignore				        #默認拒絕全部鏈接
  8 restrict -6 default ignore				        #默認拒絕全部ipv6鏈接
  9 restrict    127.0.0.1
 10 restrict    -6 ::1					        #開啓本地受權
 11 
 12 restrict 172.24.8.0 mask 255.255.255.0 nomodify notrap	#容許局域網內網段校時
 13 
 14 restirct 172.24.8.71 nomodify notrap nopeer noquery
 15 #容許根據上一級時間修改本地時間
 16 server 172.24.8.71  iburst minpoll 3 maxpoll 3 prefer
 17 #添加上一層Border-NTP服務地址
 18 
 19 #peer 172.24.8.72 iburst minpoll 4 maxpoll 6
 20 #peer 172.24.8.73 iburst minpoll 4 maxpoll 6
 21 #服務器接收其餘服務器的地址,同時也會爲其餘設備提供NTP服務器,即互相同步,用於在孤島環境中,若同時具有上層時鐘,可註釋掉。
 22 
 23 server 127.127.1.0
 24 fudge 127.127.1.0 stratum 8			#上一級不可用,使用本地時間,stratum爲8

3.3 其餘配置

參考2.3.

3.4 開啓服務

  1 [root@in_ntp01 ~]# systemctl start ntpd
  2 [root@in_ntp01 ~]# systemctl enable ntpd

3.5 驗證

  1 [root@in_ntp01 ~]# ntpq -np
10
注意:兩臺IN-NTP Server都須要配置。

四 user-client配置

4.1 服務包安裝

  1 [root@client ~]# rpm -qa | grep ntp			#查看是否安裝ntp
  2 [root@client ~]# yum -y install ntp			#安裝ntp服務

4.2 ntp配置

  1 [root@client ~]# vi /etc/ntp.conf
  2 driftfile   /var/lib/ntp/drift
  3 pidfile     /var/run/ntpd.pid				#進程pid文件
  4 logfile     /var/log/ntp.log				#開啓日誌記錄
  5 #定義與上級時間服務器聯繫時所花費的時間,記錄在driftfile參數後面的文件內。
  6 
  7 tinker panic 600
  8 #當client和server時差在600秒之內,使用漸變調整client時間,超過600秒,ntpd進程自動終止,須要手動進行調整。
  9 restrict    default ignore				        #默認拒絕全部鏈接
 10 restrict -6 default ignore				        #默認拒絕全部ipv6鏈接
 11 restrict    127.0.0.1					#開啓本地受權
 12 
 13 restrict 172.24.8.72 nomodify notrap noquery		#容許根據上一級時間修改本地時間
 14 restrict 172.24.8.73 nomodify notrap noquery		#容許根據上一級時間修改本地時間
 15 
 16 server 172.24.8.72 iburst minpoll 4 maxpoll 6 prefer
 17 server 172.24.8.73 iburst minpoll 4 maxpoll 6

4.3 其餘配置

參考2.3.

4.4 開啓服務

  1 [root@client ~]# systemctl start ntpd
  2 [root@client ~]# systemctl enable ntpd

4.5 驗證

  1 [root@client ~]# ntpq -np
11
  1 [root@client ~]# ntpstat
12

附錄一

ntpq參數解釋:
remote:本地服務器所鏈接的遠程NTP服務器。
refid:NTP服務器使用的上一級ntp服務器,即給遠程ntp服務器提供時間同步是服務器。。
st :remote遠程服務器的級別,因爲NTP是層型結構,有頂端的服務器,多層的Relay Server再到客戶端。因此服務器從高到低級別能夠設定爲1-16,爲了減
緩負荷和網絡堵塞,原則上應該避免直接鏈接到級別爲1的服務器的。
when: 上一次成功請求以後到如今的秒數。
poll : 本地機和遠程服務器多少時間進行一次同步(單位爲秒),在一開始運行NTP的時候這個poll值會比較小,那樣和服務器同步的頻率也就增長了,能夠儘快調
整到正確的時間範圍,以後poll值會逐漸增大,同步的頻率也就會相應減少。
reach:這是一個八進制值,用來測試可否和服務器鏈接,每成功鏈接一次它的值就會增長
delay:從本地機發送同步要求到ntp服務器的round trip time
offset:主機經過NTP時鐘同步與所同步時間源的時間偏移量,單位爲毫秒(ms)。offset越接近於0,主機和ntp服務器的時間越接近。
jitter:這是一個用來作統計的值,它統計了在特定個連續的鏈接數裏offset的分佈狀況,簡單地說這個數值的絕對值越小,主機的時間就越精確。
『 * 』:表明目前正在做用當中的NTP,即主NTP Server;
『 + 』:表明輔助的NTP Server和帶有*號的服務器一塊兒爲咱們提供同步服務, 當主NTP Server服務器不可用時備服務器接管,即做爲下一個提供時間更新的候
選者。
『 - 』:遠程服務器被認爲是不合格的NTP Server。
『 x 』:遠程服務器不可用。

附錄二

ntp服務,默認只會同步系統時間。若須要ntp同時同步硬件時間,能夠在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes ,則可讓硬件時間與系統時間一塊兒同步。
SYNC_HWCLOCK=yes
注意:容許BIOS與系統時間同步,也能夠經過hwclock -w 命令。
相關文章
相關標籤/搜索