一、NTP簡介
1.NTP簡介 ?
NTP(Network Time Protocol,網絡時間協議)是用來使網絡中的各個計算機時間同步的一種協議。它的用途是把計算機的時鐘同步到世界協調時UTC,其精度在局域網內可達0.1ms,在互聯網上絕大多數的地方其精度可以達到1-50ms。(1s=1000ms)NTP服務器就是利用NTP協議提供時間同步服務的。
2.NTP原理
? ? NTP客戶端可以定時自動向NTP服務器發送請求來獲取時間,NTP服務器將時間發送給客戶端,。
? ? NTP服務器的時間來源有兩個
? ? 1.網絡時間
? ? 2.NTP服務器自己的時間
2.NTP架構
? ? C/S
二、部署NTP服務端
1.NTP安裝
[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本機時間作為時間源】
[root@web02?~]#?cd?/etc/
[root@web02 etc]#?mv ntp.conf ntp.conf.bak
[root@web02 etc]#cat?>?ntp.conf<
server?127.127.1.0
restrict?127.0.0.1
restrict?10.0.0.0?mask?255.255.255.0
fudge?127.127.1.1?startnum?10
statsdir?/var/log/ntp/
logfile?/var/log/ntp/ntp.log
eof
檢查ntp運行狀態
[root@web02 etc]#?ntpq?-p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0)?.LOCL.?5?l?1?64?1?0.000?0.000?0.000
[root@web02 etc]#?ntpstat
synchronised to?local?net at stratum?6
time correct to within?7948?ms
polling server every?64?s
三、部署NTP客戶端
1.windows客戶端
need-to-insert-img
2.linux客戶端
? ? 客戶端只需要安裝ntp,但是不能啟動ntp。
? ? 啟動ntp會報錯:
[root@test?~]#?yum install ntpdate
[root@test?~]#?crontab?-e
*/5?*?*?*?*?/usr/sbin/ntpdate?10.0.0.7?>/dev/null?2>&1
?