在解決問題以前,咱們首先來了解下面幾個知識點:linux
1. date命令:服務器
#date網絡
顯示系統時間spa
2.hwclock命令 (即hardwareclock系統硬件時間).net
#hwclockserver
顯示硬件時間crontab
#hwclock -w同步
將系統時間寫入到系統硬件當中百度
3.ntpdate軟件
ntpdate 是一個linux時間同步服務軟件,具體的詳細資料請參考下百度,有不少詳細的資料
第2、查看本機是否安裝ntpdate服務,若是沒有安裝,請 yum install -y ntpdate
開始解決問題:
1. 輸入ntpdate time.nuri.net同步網絡時間
結果:3 Jun 15:42:39 ntpdate[4721]: adjust time server 211.115.194.21 offset -0.005885 sec
出現上述結果表明時間同步成功,上面的大體意思爲調整時間爲服務器211.115.194.21的時間,相差-0.005885秒的時間
若是上面time.nist.gov服務器同步不了,能夠換下面幾個時間服務器試試:
time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org
2.同步時間成功後調整硬件時間
#hwclock -w
執行成功後, 查看系統硬件時間(不出意外的話,如今date和hwclock現實的時間均爲internet時間)
#date
#hwclock
執行上述命令,顯示的時間應該同樣的
4、定時執行時間同步任務,因此咱們利用crontab -e 來添加定時任務
#* */1 * * * root ntpdatetime.nuri.net;hwclock -w
即:每隔一個小時同步一下internet時間。