1.新裝的服務器可能設置了錯誤的時區,需要調整時區並調整時間.
使用NTP來從一個時間服務器同步把當前時區調整爲上海就是+8區(想改其他時區也可以去看看/usr/share/zoneinfo)目錄;
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
2.檢查是否安裝ntp服務
rpm -qa ntp
[root@LAN8-KVM ~]# rpm -qa ntp
ntp-4.2.4p8-3.el6.centos.x86_64
若未安裝ntp服務 yum安裝一下(yum install ntp)
3.安裝完了之後,測試一下(利用ntpdate同步標準時間)
[root@LAN8-KVM ~]#ntpdate 0.pool.ntp.org
29 Nov 03:44:15 ntpdate[28324]: the NTP socket is in use, exiting
這說明ntp服務正在使用,先停止ntp服務(service ntpd stop)在測試下
[root@LAN8-KVM ~]# ntpdate 0.pool.ntp.org
5 May 11:23:13 ntpdate[2056]: adjust time server 202.112.29.82 offset 0.000380 sec
如果出現上面的內容說明,同步成功了,然後開啓ntp服務(servicentpd start)
4.修改時區(我這裏以上海時區爲主)
vi /etc/sysconfig/clock
ZONE="Asia/Shanghai"
5.加入定時計劃任務
crontab –e
0 1 * * * /usr/sbin/ntpdate 0.pool.ntp.org
6.加入開機自啓動
vi /etc/rc.local
ntpdate cn.pool.ntp.org
chkconfig ntpd on
推薦幾個網絡時間服務器地址
time.nist.gov(美國)
time.nuri.net
asia.pool.ntp.org
ntp.fudan.edu.cn (復旦)→國內用戶推薦使用此服務器)
timekeeper.isi.edu
subitaneous.cpsc.ucalgary.ca
usno.pa-x.dec.com
time.twc.weather.com
swisstime.ethz.ch
ntp0.fau.de
ntp3.fau.de
time-a.nist.gov
time-b.nist.gov
time-nw.nist.gov
nist1-sj.glassey.com
210.72.145.44