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 22:39
下一篇 2015-11-10 22:42

相關推薦

  • 文本處理及正則表達式

    文本處理工具:     more:分頁查看文件     less:分頁控制顯示文件     head 查看文件的前幾行         -n 3   顯示前三行      &nbs…

    Linux干貨 2017-05-31
  • 馬哥教育網絡班22期+第4周課程練習 忍者亂太郎喻成

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。   cp -rp /etc/skel /home/tuser1   chmod -R 700 /home/tuser1 2、…

    Linux干貨 2016-10-09
  • 配置基于mysql的虛擬用戶認證vsftp服務器

    1.安裝vsftp、mysql、epel_release(epel源,后面要安裝的pam_mysql認證模塊需要這個源)、pam_mysql 2.剛裝的mysql運行一下/usr/bin/mysql_secure_installation 3.建立數據庫vsftpd,建表user,     create database vsftpd; …

    Linux干貨 2016-06-22
  • Linux基礎命令及獲取命令幫助

    何為命令?         linux命令是對Linux系統進行管理的命令。對于Linux系統來說,無論是中央處理器、內存、磁盤驅動器、鍵盤、鼠標,還是用戶等都是文件,Linux系統管理的命令是它正常運行的核心,與之前的DOS命令類似。linux命令在系統中有兩種類型:內置She…

    Linux干貨 2016-10-25
  • git

    1.1 Git的安裝 1.1.1 版本 # cat /etc/redhat-release CentOS release 6.8 (Final) # uname -r 2.6.32-642.4.2.el6.x86_64 # uname -m x86_64 1.1.2 安裝 可以直接通過源碼安裝。先從Git官網下載源碼,然后解壓,…

    Linux干貨 2016-10-31
  • Linux之DNS服務

    DNS服務 DNS: Domain Name Service,協議(C/S, 53/udp, 53/tcp)應用層協議 BIND:BekerleyInternatName Domain, ISC (www.isc.org) 本地名稱解析配置文件:hosts     /etc/hosts   &nbs…

    Linux干貨 2016-10-05

評論列表(2條)

  • stanley
    stanley 2015-11-10 22:41

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

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

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

欧美性久久久久