ntp時間服務器

前言

  ntp(Network Time protocol)是網絡時間協議,是用來使網絡中的各個計算機時間同步的一種協議。

ntp配置

 1)ntp是由ntp軟件提供,如果沒有可以使用yum進行安裝

 2)ntp配置文件介紹:/etc/ntp.conf

  利用restrict來管理權限控制;語法格式:restrict IP mask MASK [parameter]

   常用的parameter有以下幾類:

     ignore:拒絕所類型的ntp連接

     nomodify:客戶端只能通過此服務器進行時間同步;不能使用ntpc或ntpq這兩種方式來修改時間;

     noquery:不提供網絡時間校驗功能

     notrap:不支持遠程登錄的時間戳

     notust:拒絕認證不通過的客戶端

   注意:如果parameter沒有任何參數,表示來接受自任何網絡的時間同步請求  

  利用server定義上層ntp服務器;語法格式 server SERVER_IP [prefer];prefer表示首先使用此服務器地址

  利用driftfile記錄時間差異;默認記錄位置是/var/lib/ntp/drift;

   注意:若果要修改保存路徑,要確保ntpd用戶對目標文件有寫入權限

  利用key提高安全性;語法格式: key  key_file 

 3)配置實例:  

  # vim /etc/ntp.conf 

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift  \\定義時間差異保存位置
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery \\拒絕所有ipv4用戶
restrict -6 default kod nomodify notrap nopeer noquery \\拒絕所有ipv6用戶

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict  202.120.2.101  \\放行來自202.120.2.101地址進入本服務器
restrict 127.0.0.1     \\放行本機來源
restrict -6 ::1       \\放行本機來源

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 172.16.2.0 mask 255.255.255.0 nomodify \\放行本地局域網絡進入本機

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#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 202.120.2.101 prefer   \\定義此服務器為首先使用的時間服務器
server s1b.time.edu.cn      \\定義備用的時間服務器
server s1c.time.edu.cn      \\定義備用的時間服務器
#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                   # broadcast client
#broadcast 224.0.1.1 autokey           # multicast server
#multicastclient 224.0.1.1            # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw  \\保持默認即可

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys  \\如果沒有配置秘鑰,保持默認即可

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

 4)啟動ntpd服務;查看監聽端口

# service ntpd start
#netstat -upln
Proto Recv-Q Send-Q Local Address   Foreign Address      State       PID/Program name 
udp   0    0   172.16.2.13:123    0.0.0.0:*                        11303/ntpd
udp   0    0      0.0.0.0:123     0.0.0.0:*                 11303/ntpd

 5)等待大約15分鐘左右,使用ntpstat查看,自己定義的ntp服務器已經開始與網絡時間服務器進行同步

 # ntpstat
synchronised to NTP server (202.120.2.101) at stratum 4 
   time correct to within 176 ms
   polling server every 64 s

 6)  使用ntpq -p可以查看ntp服務器狀態

# ntpq -p
  remote          refid    st t when poll reach   delay   offset  jitter
==================================================================================================
*dns.sjtu.edu.cn 202.118.1.130 3  u  60  64  275   34.939   -5.211   4.329
 ntpa.nic.edu.cn  .STEP.   16 u  -  1024   0    0.000    0.000   0.000
 202.112.7.150   .STEP.   16 u  -  1024   0    0.000    0.000   0.000

 remote: ntp服務器的上層服務器;如果前面有*代表是正在使用的ntp服務器,+代表ntp服務端已連接,可做為備用ntp服務器

 refid:上層ntp服務器的校準服務器

 st:NTP上層服務器的級別

 when: 多少秒之前與上層服務器同步過時間

 poll:多長時間之后與上層服務器再次進程同步時間   

 reach:已經向上層ntp服務器同步的次數

 delay:時延;單位 10^(-3)秒

 offset:時間補償的結果;單位與 10^(-3)秒                               

 jitter:linux系統時間與BIOS硬件的差異時間;單位與10^(-3)秒

詳情請參考:http://linux.vbird.org/linux_server/0440ntp.php

原創文章,作者:馬行空,如若轉載,請注明出處:http://www.www58058.com/5569

(1)
馬行空馬行空
上一篇 2015-06-24
下一篇 2015-06-24

相關推薦

  • 馬哥教育網絡班22期+第12周作業

    week11 1、請描述一次完整的http請求處理過程; 2、httpd所支持的處理模型有哪些,他們的分別使用于哪些環境。 3、源碼編譯安裝LAMP環境(基于wordpress程序),并寫出詳細的安裝、配置、測試過程。 4、建立httpd服務器(基于編譯的方式進行),要求:      提供兩個基于名稱的虛擬主…

    Linux干貨 2016-10-31
  • 上古神器vim

    概述:     在之前的篇章中,我們介紹了一些文本的處理工具,如grep、sed、cut、sort等,但是那些工具的側重點都在于有了現成的文本之后,對現有的文本進行一定條件的加工處理后,滿足我們進一步對數據的要求。但是目前為止,還沒有接觸一款專業用來編輯文本的工具,本篇就來介紹一下Linux系統上自帶的專業用來文本編輯…

    Linux干貨 2016-08-10
  • wed服務基礎·httpd基礎配置詳解

    一、 Web Service基礎: service:計算機后臺提供的功能或計算機可以提供的某一種功能 Web Service本質:通過網絡調用其它網站的資源 根據來源的不同,分為兩種服務: 本地服務:使用同一臺機器提供的服務,不需要網絡 網絡服務:使用另一臺機器提供的服務,需要網絡   IANA互聯網地址授權機構(Internet Assigned…

    2017-06-09
  • 馬哥教育網絡班20期+第五周博客作業

    1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行; ]# grep  "^[[:space:]]\+" /boot/grub/grub.conf 2、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行; ]#…

    Linux干貨 2016-07-12
  • CentOS系統啟動流程

       開機不是只要單擊電源鈕,而關機只要關掉電源鈕就可以了嗎?話是這樣沒錯啦,但是由于 Linux 是一套多人多任務的操作系統,你難保你在關機時沒有人在在線,如果你關機的時候碰巧一大群人在在線工作, 那會讓當時在在線工作的人馬上斷線的!那不是害死人了!一些數據可是無價之寶。    另外 Linux 在執行的時候,雖然你…

    Linux干貨 2016-09-19

評論列表(1條)

  • jemmy
    jemmy 2015-11-19 15:00

    學習了,謝謝分享!

欧美性久久久久