Linux服務器時間設置及同步

1 手動設置

date命令:
date :查看當前時間,結果如下:Wed Feb  4 16:29:51 CST 2015
date -s 16:30:00 :設置當前時間,結果如下:Wed Feb  4 16:30:00 CST 2015
date -s "YYYY-MM-DD hh:mm[:ss]" 如date -s "2015-02-04 16:30:00"
hwclock -w(將時間寫入bios避免重啓失效)

2 同步網絡

ntpdate命令:
ntpdate -u 210.72.145.44 :網絡時間同步命令

注意:若不加上-u參數, 會出現以下提示:no server suitable for synchronization found
-u:從man ntpdate中可以看出-u參數可以越過防火牆與主機同步;
210.72.145.44:中國國家授時中心的官方服務器。

ntp常用服務器:
中國國家授時中心:210.72.145.44
NTP服務器(上海) :ntp.api.bz
美國:time.nist.gov 
復旦:ntp.fudan.edu.cn 
微軟公司授時主機(美國) :time.windows.com 
臺警大授時中心(臺灣):asia.pool.ntp.org

經測試中國國家授時中心與NTP上海服務器可以正常同步時間,注意需要加上-u參數!

3 時區修改

####3.1 即時生效

[root@localhost /]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime  
[root@localhost /]# hwclock  

3.2 重啓生效

修改/etc/sysconfig/clock文件,把ZONE的值改爲Asia/Shanghai,UTC值改爲false,改完後的文件如下:

# The time zone of the system is defined by the contents of /etc/localtime.  
# This file is only for evaluation by system-config-date, do not rely on its  
# contents elsewhere.  
ZONE="Asia/Shanghai"  
UTC=false  
ARC=false  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章