ntp時間服務器搭建實例

ntp時間服務器采用stratum分級架構來處理時間同步;舉例說明:你搭建了一臺ntp服務器,然后同步的server為stratum-1,你的ntp則為stratum-2,你的下級ntp則為tratum-3。依此類推,最多為15層。

1.ntp server安裝:

[root@localhost ~]# yum -y install ntp tzdata

ntp相關文件說明:

/etc/ntp.conf        ntp server配置文件
/usr/sbin/ntpd       ntp server程序
/usr/sbin/ntpdate    ntp client校正工具
/etc/sysconfig/clock 時區配置文件

2./etc/ntp.conf配置文件說明,主要配置restrict和server

#restrict設置格式:
#restrict [授權同步的網段] mask [netmask] [parameter]
例:restrict 192.168.6.0 mask 255.255.252.0 nomodify

parameter說明:
kod         kod技術可以阻止“Kiss of Death “包對服務器的破壞
nomodity    client可通過ntp進行時間同步,但不能更改server參數
notrap      不提供trap遠程登陸功能
nopeer      不與其它同一層的ntp server進行時間同步
noquery     拒絕ntp時間同步
notrust     拒絕無認證的client
ignore      拒絕連接到ntp server

#server設置格式
#server [hostname|ip][parameter]
例:server   server asia.pool.ntp.org prefer
parameter說明:
prefer      最高優先級
burst       當一個運程NTP服務器可用時,向它發送一系列的并發包進行檢測。
iburst      當一個運程NTP服務器不可用時,向它發送一系列的并發包進行檢測。

3.ntp配置實例 server端

1)配置/etc/ntp.conf
[root@localhost ~]# vim /etc/ntp.conf
  1 # For more information about this file, see the man pages
  2 # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
  3 
  4 driftfile /var/lib/ntp/drift
  5 
  6 # Permit time synchronization with our time source, but do not
  7 # permit the source to query or modify the service on this system.
  8 restrict default kod nomodify notrap nopeer noquery
  9 restrict -6 default kod nomodify notrap nopeer noquery
 10 
 11 # Permit all access over the loopback interface.  This could
 12 # be tightened as well, but to do so would effect some of
 13 # the administrative functions.
 14 restrict 127.0.0.1
 15 restrict -6 ::1
 16 
 17 # Hosts on local network are less restricted.
 18 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
 19 restrict 192.168.6.0 mask 255.255.252.0 nomodify
 20 
 21 # Use public servers from the pool.ntp.org project.
 22 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 23 #server 0.centos.pool.ntp.org iburst
 24 #server 1.centos.pool.ntp.org iburst
 25 #server 2.centos.pool.ntp.org iburst
 26 #server 3.centos.pool.ntp.org iburst
 27 server asia.pool.ntp.org prefer
 28 server 0.asia.pool.ntp.org
 29 server 1.asia.pool.ntp.org
 30 server 2.asia.pool.ntp.org
 31 server time.nist.gov
 32 
 33 #broadcast 192.168.1.255 autokey        # broadcast server
 ...

2)NTP啟動與端口檢查:
[root@localhost ~]# service ntpd start
Starting ntpd:
[root@localhost ~]# chkconfig ntpd on
[root@localhost ~]# chkconfig --list |  grep ntp
ntpd           	0:關閉	1:關閉	2:啟用	3:啟用	4:啟用	5:啟用	6:關閉
ntpdate        	0:關閉	1:關閉	2:關閉	3:關閉	4:關閉	5:關閉	6:關閉
[root@localhost ~]# netstat -nutlp | grep ntp
udp        0      0 192.168.2.213:123           0.0.0.0:*                               21798/ntpd          
udp        0      0 192.168.6.213:123           0.0.0.0:*                               21798/ntpd          
udp        0      0 127.0.0.1:123               0.0.0.0:*                               21798/ntpd          
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               21798/ntpd          
udp        0      0 fe80::221:f6ff:fed4:d502:123 :::*                                    21798/ntpd          
udp        0      0 fe80::221:f6ff:fed4:d501:123 :::*                                    21798/ntpd          
udp        0      0 ::1:123                     :::*                                    21798/ntpd          
udp        0      0 :::123                      :::*                                    21798/ntpd  

3)ntp server與上聯是否同步
#查看server與上聯是否同步,時間校正約8279ms,每64s輪循更新一次。
[root@localhost ~]# ntpstat 
synchronised to NTP server (62.201.225.9) at stratum 3   #==>上層ntp
   time correct to within 8279 ms                        #==>校正時間差
   polling server every 64 s                             #==>下次同步時間
   
#查看server與上聯的狀態
[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time.iqnet.com  62.201.214.162   2 u  146   64  124  393.411  -101.29  40.435
-220.231.122.105 123.204.45.116   4 u   20   64  377  341.475   58.745  47.945
+vps.jre655.com  10.84.87.146     2 u   24   64  377  211.095    0.177  38.002
 web10.hnshostin 158.43.128.33    2 u   17   64  177  392.506  -134.76  39.146
+24.56.178.140   .ACTS.           1 u   27   64  377  282.739  -59.521  42.959

參數說明:
reomte    server上聯的ntp主機名或ip;
          注意最左端符號;*表示當前正使用的上層ntp;+代表與本機server也有連接,作為侯選ntp
refid     給上層ntp提供時間校對的服務器
st        上層npt stratum級別
when      上一次與上層ntp同步的時間,單位為秒。
poll      下一次與上層ntp同步的時間
reach     已經同上層ntp同步更新的次數
delay     網絡傳輸過程中的延遲時間,單位為10^(-6)s
offset    時間補償,單位為10^(-3)s
jitter    系統時間與bios硬件時間差,單位為10^(-6)s

4.ntp配置實例client端

通過crontab設置更新時間
[root@dns-2-253 ~]# crontab -l
*/5 * * * * /usr/sbin/ntpdate 192.168.6.213 &> /dev/null

client測試是否同步成功
[root@dns-2-253 ~]# ntpdate 192.168.6.213
10 Nov 21:25:43 ntpdate[26381]: step time server 192.168.6.213 offset 1.318393 sec

備注:如果無法同步,需查是否開啟了防火墻。

原創文章,作者:老鼠上了貓,如若轉載,請注明出處:http://www.www58058.com/9226

(0)
老鼠上了貓老鼠上了貓
上一篇 2015-11-10
下一篇 2015-11-10

相關推薦

  • linux磁盤管理

    硬盤接口類型:         IDE:并口,133M/s;100個IO/s        SCSI:并口,UltraSCSI320,320M/s UltraSCSI640 640M/s 150-200IO/s&nbsp…

    Linux干貨 2016-08-29
  • Week9’s homework

    Week9's homework 1、寫一個腳本(1)判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin)(2)分別統計兩類用戶的個數;通過字符串比較來實現。 #!/bin/bash # for i in $(cat /etc/passwd |…

    Linux干貨 2016-12-24
  • lvs–各類型的原理及實現—(原理篇)

    前言:    LVS即是linux虛擬服務器,是一個虛擬的服務器集群系統,目的是使用集群技術和linux操作系統實現一個高性能、高可用的服務器。采用IP負載均衡技術和基于內容請求分發技術,將請求負載均衡地轉移到不同的服務器上執行,從而將一組服務器構成一個高性能、高可用的虛擬服務器。此篇的內容只包含兩種較為常用的LVS技術,分別是LVS-N…

    Linux干貨 2016-10-27
  • nginx+tomcat+memcached構建session共享集群

    一、安裝配置tomcat 配置前說明: 系統為centos7 m1.xsllqs.com地址為192.168.1.107 c1.xsllqs.com地址為192.168.1.114 c2.xsllqs.com地址為192.168.1.113 安裝tomcat需要配合JDK使用,JDK有oracle JDK和open JDK兩種 oracle JDK8的下載地…

    Linux干貨 2016-06-26
  • linux —————-目錄配配置【FHS】

    linux 目錄配配置【FHS】 /根目錄的意義與內容 根目錄是整個系統最重要的一個目錄;根目錄與開機、還原、系統修復等操作有關 FHS建議標準: 根目錄所在的分區應該越小越好,且應用程序所安裝的軟件最好不要與根目錄放在同一個分區內,保持根目錄越小越好 FHS定義的目錄含義 /bin :系統存放執行文件的目錄,但是bin比較特殊【bin放置的是在單用戶維護?!?/p>

    Linux干貨 2017-04-17
  • LB-lvs

    Linux Cluster: Cluster:計算機集合,為解決某個特定問題組合起來形成的單個系統; Linux Cluster類型: LB:Load Balancing,負載均衡; HA:High Availiablity,高可用; A=MTBF/(MTBF+MTTR) (0,1):90%, 95%, 99%, 99.5%, 99.9%, 99.99%, …

    Linux干貨 2017-06-25

評論列表(2條)

  • stanley
    stanley 2015-11-10 22:41

    非常有參考價值,上次我們部署crond的時候遇到不少問題,一個crond不生效,一個報錯已有進程運行中

    • 老鼠上了貓
      老鼠上了貓 2015-11-13 20:44

      @stanley這樣配置有個奇怪的地方,restrict明明只放行了內網,但在機房外部卻可通過服務器的外網ip進行ntp同步。

欧美性久久久久