1.1ntp的簡介
1.1.1NTP簡介
NTP(Network Time Protocol,網絡時間協議)是用來使網絡中的各個計算機時間同步的一種協議。它的用途是把計算機的時鐘同步到世界協調時UTC,其精度在局域網內可達0.1ms,在互聯網上絕大多數的地方其精度可以達到1-50ms。
NTP服務器就是利用NTP協議提供時間同步服務的。
1.2ntp服務的安裝
1.2.1# 系統自帶ntp
[root@m01~]# rpm -qa ntp
ntp-4.2.6p5-5.el6.centos.x86_64
# 如果沒有就安裝
yum -yinstall ntp
1.3配置ntp服務
[root@m01~]# vim /etc/ntp.conf
8 # restrict default kod nomodify notrap nopeernoquery
9 restrict default nomodify 註釋第八行內容並在下面添加此行內容
# nomodify客戶端可以同步
# 將默認時間同步源註釋改用可用源
[root@m01~]# vim /etc/ntp.conf
22 # server 0.centos.pool.ntp.org iburst
23 # server 1.centos.pool.ntp.org iburst
24 # server 2.centos.pool.ntp.org iburst
25 # server 3.centos.pool.ntp.org iburst
26 server ntp1.aliyun.com
27 server time.nist.gov 註釋22-25行內容並在下面添加此部分內容
1.4啓動ntp服務器
# 如果計劃任務有時間同步,先註釋,兩種用法會衝突。
[root@m01~]# crontab -e
# time sync by oldboy at 2010-2-1
#*/5 * * * * /usr/sbin/ntpdate time.nist.gov>/dev/null 2>&1
[root@m01~]# /etc/init.d/ntpd start (如果之前啓動過 需要restart重啓)
Starting ntpd:
[ OK ]
[root@m01~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp1.aliyun.com 10.137.38.86 2 u 22 64 1 525.885 -42.367 0.000
[root@m01~]# ntpstat
synchronised to NTP server (110.75.186.247) atstratum 3
timecorrect to within 4257 ms
pollingserver every 64 s
[root@m01~]# ntpdate 10.0.0.61
7 Dec18:43:07 ntpdate[26950]: the NTP socket is in use, exiting
1.5客戶機時間的同步
1.5.1客戶機要等幾分鐘再與新啓動的ntp服務器進行時間同步,否則會提示no server suitable for synchronizationfound
錯誤
[root@web~]# ntpdate10.0.0.61
7 Dec18:40:16 ntpdate[1453]: step time server 10.0.0.61 offset 40.880807 sec
1. #將命令放入計劃任務即可。
3.在用date 查詢一下你的時間是否同步了