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 09:48
下一篇 2015-06-24 10:03

相關推薦

  • 馬哥教育的第一天

    春天的北京,比想象中的更加溫暖,跨越一千三百公里的距離,我來到馬哥教育位于北京昌平區的校區,傳說中的春寒料峭似乎遺忘了北京,自湖北出門的時候,車外還是淅淅瀝瀝的小雨,到達北京,迎接我的卻是春風拂面熏人醉。 安頓了兩天之后,我們三十期的開班典禮在三月二十六號早上的九點鐘準時開始,由云珍老師主持,傳說中的馬哥、王老師、張sir、宗華老師紛紛登臺致辭,分別從運維工…

    2018-03-26
  • 互聯網安全之iptables/netfilter入門到進階

    隨著互聯網技術的方興未艾,各種網絡應用層出不窮,網絡攻擊、黑客入侵也成了網民暢游互聯網的心頭大患,互聯網安全也愈加受到了人們的重視。網絡防火墻,作為一種簡單高效的互聯網防御手段,逐漸成為了網民暢游網絡世界的保護傘。下面筆者介紹下Linux系統的守衛者——iptables/netfilter。 ?一 兄弟齊心,其利斷金 ?iptables/netfilter就…

    Linux干貨 2017-05-06
  • Bash的I/O重定向及管道

    每周更新的博客定時派送啦,本周與大家一起分享的是重定向和管道 首先了解一下 讀入數據:Input 輸出數據:Output 我們來看一下重定向:  >  覆蓋重定向 上面圖中 > 文件名     創建空文件 touch 文件名 創建空文件 這兩種方法都可以創建一個新的文…

    2017-07-21
  • 磁盤管理

    回顧 {a..f} a b c d e f ]# arr=({a..z}) ]# echo ${#arr[*]} 26 ]# N1=N2 ]# N2=zhuchaoming ]# echo ${!N1} eval N1=\$$N2 echo $N1 創建臨時文件 mktemp NAME.XXX 交互式登錄 /etc/profile –> /…

    Linux干貨 2016-09-07
  • Linux簡單命令說明(date、clock、echo 、Tab鍵、screen)

    Linux簡單命令說明 1、如何查詢命令的幫助文檔 外部命令:是系統用應用程序的一部分,在系統啟動時不會被加載到內存,而在服務或進程啟用時 才執行它。 查看 COMMAND –help man COMMAND 內部命令:是簡小的命令,開機就已加載到shell中。 查看 help COMMAND 2、date和clock命令 date #顯示當前系統時間 […

    Linux干貨 2017-07-12
  • vim編輯器使用介紹

    vim基礎

    2017-11-09

評論列表(1條)

  • jemmy
    jemmy 2015-11-19 15:00

    學習了,謝謝分享!

欧美性久久久久