在使用Linux系統部署項目,有時會出現時間跟當前時間不一致的情況,這個時候需要做些調整:
1.首先刪除之前設置的時區
rm -rf /etc/localtime
2.創建上海時區
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
3.查看當前時間
date
4.利用 ntpdate 同步北京時間 (如未安裝ntpdate 需要先安裝 yum install -y ntp)
ntpdate 120.24.81.91
5.再次查看,可以發現時間已經同步
date
6.查看硬件時間,還是沒有同步
hwclock
7.將當前時間同步到硬件時間
hwclock -w
8.此時查看硬件時間,發現已同步
hwclock
9.查看當前時間,也沒問題,此時系統時間已同步完成
date
當然,這樣同步之后,隔段時間還是出現未同步的情況,需要做定時任務去定時同步!未完待續。。。。