歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux之使用NTP服務管理/同步服務器時間

Linux之使用NTP服務管理/同步服務器時間

日期:2017/3/2 9:44:32   编辑:關於Linux

當有多台Web Server時,而且每台服務器的時間需要保持一致,這時就可以考慮使用NTP 服務了。

1.先用用ntpstat查看一下NTP service當前的狀態。
#ntpstat
如果輸出下面內容,說明還沒有啟動,需要設置服務器重啟時NTP服務自啟動:
Unable to talk to NTP daemon. Is it running?
如果輸出下面內容說明已經在工作了:
synchronised to NTP server (198.55.111.5) at stratum 3
time correct to within 238 ms
polling server every 64 s
如果輸出:unsynchronised, 需要重新啟動(ntpd restart)一下進行同步。

2.使用ntpq -p查看NTP server列表

#ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*dns1.synet.edu. 202.118.1.46 2 u 46 64 377 19.924 11.896 5.692
+dns2.synet.edu. 202.118.1.46 2 u 45 64 317 20.518 11.833 6.992
dns.sjtu.edu.cn .STEP. 16 u - 64 0 0.000 0.000 0.000

3.手動同步時間
#ntpdate
如果輸出下面內容,說明ntp服務已經啟動導致手動同步時間失敗,需要先停止ntp服務:
the NTP socket is in use. exiting
#service ntpd stop
#ntpdate cn.pool.ntp.org
如果輸出下面內容,說明手動同步時間成功:
adjust time server xxx
最後記得將ntp服務啟動,讓他自動更新。

4.啟動NTP服務
#service ntpd start
Starting ntpd: [ OK ] Enable NTP to start at boot time with the chkconfig command.

5.開啟NTP自啟動
#chkconfig ntpd on
Verify that NTP is enabled with the following command.

6.檢查NTP自啟動情況
#chkconfig --list ntpd
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Here ntpd is on in runlevels 2, 3, 4, and 5, which is correct.

Copyright © Linux教程網 All Rights Reserved