NTP 簡介
NTP(Network Time Protocol,互聯網時間協議)是用來使互聯網中的各個計算機時間同步的一種協議。它的用途是把計算機的時鐘同步到世界協調時 UTC,其精度在區域網內可達 0.1ms,在網際互聯網上絕大多數的地方其精度可以達到 1-50ms 。
NTP 站羣服務器就是利用 NTP 協議提供時間同步服務的。
 
NTP 站羣服務器安裝
系統自帶 ntp
# yum -y install ntp
 
配置 NTP 服務
# vim /etc/ntp.conf
#restrict default kod nomodify notrap nopeer noquery
restrict
default nomodify
# nomodify 客户端可以同步
# 將預設時間同步源註釋改用可用源
#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 ntp1.aliyun.com
server time.nist.gov
 
啓動 NTP 站羣服務器
# 如果計劃任務有時間同步,先註釋,兩種用法會衝突。
# crontab -e
# time
sync by oldboy at 2010-2-1
#*/5 *
* * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
 
# /etc/init.d/ntpd start
Starting
ntpd:[  OK  ]
# ntpq -p
remote           refid      st t when poll reach   delayoffset  jitter
==============================================================================
*ntp1.aliyun.com
10.137.38.86     2 u   2264    1  525.885-42.367   0.000
 
# ntpstat
synchronised
to NTP server (110.75.186.247) at stratum 3
time correct to within 4257 ms
polling server every 64 s
 
# ntpdate 10.0.0.9
7 Dec 18:43:07 ntpdate[26950]: the NTP socket
is in use, exiting
 
客户機時間同步
客户機要等幾分鐘再與新啓動的 ntp 站羣服務器進行時間同步,否則會提示 no server suitable for synchronization found 錯誤。
# ntpdate 10.0.0.9
7 Dec 18:40:16 ntpdate[1453]: step time server
10.0.0.9 offset 40.880807 sec
# 將命令放入計劃任務即可。