NTP原理及配置使用

1、NTP簡介linux

1.NTP簡介   web

       NTP(Network Time Protocol,網絡時間協議)是用來使網絡中的各個計算機時間同步的一種協議。它的用途是把計算機的時鐘同步到世界協調時UTC,其精度在局域網內可達0.1ms,在互聯網上絕大多數的地方其精度能夠達到1-50ms。(1s=1000ms) NTP服務器就是利用NTP協議提供時間同步服務的。windows

2.NTP原理
    NTP客戶端能夠定時自動向NTP服務器發送請求來獲取時間,NTP服務器將時間發送給客戶端,。
    NTP服務器的時間來源有兩個
    1.網絡時間
    2.NTP服務器本身的時間
2.NTP架構
    C/S
2、部署NTP服務端
1.NTP安裝
  1. [root@web02 ~]# yum install ntp -y
2.NTP配置文件說明
1)restict 表示進行受權,受權哪些主機可使用這個服務器
    格式: restrict  IP地址  mask  子網掩碼  參數
參數有如下幾個
    ignore  :關閉全部的 NTP 聯機服務
    nomodify:客戶端不能更改服務端的時間參數,可是客戶端能夠經過服務端進行網絡校時。
    notrust :客戶端除非經過認證,不然該客戶端來源將被視爲不信任子網
    noquery :不提供客戶端的時間查詢:用戶端不能使用ntpq,ntpc等命令來查詢ntp服務器
    notrap :不提供trap遠端登錄:拒絕爲匹配的主機提供模式 6 控制消息陷阱服務。陷阱服務是 ntpdq 控制消息協議的子系統,用於遠程事件日誌記錄程序。
    nopeer :用於阻止主機嘗試與服務器對等,並容許欺詐性服務器控制時鐘
    kod : 訪問違規時發送 KoD 包。
 
例子:
    restrict 127.0.0.1 表示當前主機可使用這個時間服務
    restrict 172.16.1.0 mask 255.255.255.0 表示受權172.16.1網絡中的所有主機可使用時間服務
    restrict 0.0.0.0 mask 0.0.0.0  nomodify notrao 表示全部主機均可以訪問這個時間服務
    restrict efault ignore 設置默認策略,容許任意主機進行時間同步
 
2)server 表示當前NTP服務從哪一個主機來獲取時間
默認的ntp地址
    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
經常使用的ntp地址
    server ntp1.aliyun.com     #→阿里雲時間服務器(ntp1...21等)
    server time.nist.gov          #→微軟時間服務器
3)fudge 設置你的ntp優先級
4)statsdir logfile  指定日誌文件的位置
 
3.修改NTP配置文件
【此例使用ntp本機時間做爲時間源】
  1. [root@web02 ~]# cd /etc/
  2. [root@web02 etc]# mv ntp.conf ntp.conf.bak
  3. [root@web02 etc]#cat > ntp.conf<<eof
  4. server 127.127.1.0
  5. restrict 127.0.0.1
  6. restrict 10.0.0.0 mask 255.255.255.0
  7. fudge 127.127.1.1 startnum 10
  8. statsdir /var/log/ntp/
  9. logfile /var/log/ntp/ntp.log
  10. eof
檢查ntp運行狀態
  1. [root@web02 etc]# ntpq -p
  2. remote refid st t when poll reach delay offset jitter
  3. ==============================================================================
  4. *LOCAL(0) .LOCL. 5 l 1 64 1 0.000 0.000 0.000
  5.  
  6. [root@web02 etc]# ntpstat
  7. synchronised to local net at stratum 6
  8. time correct to within 7948 ms
  9. polling server every 64 s
3、部署NTP客戶端
 
1.windows客戶端
      
2.linux客戶端
    客戶端只須要安裝ntp,可是不能啓動ntp。
    啓動ntp會報錯:
  1. [root@test ~]# yum install ntpdate
  2. [root@test ~]# crontab -e
  3. */5 * * * * /usr/sbin/ntpdate 10.0.0.7 &gt;/dev/null 2&gt;&1
相關文章
相關標籤/搜索