linux設置時區

版權聲明:轉載時請以超鏈接形式標明文章原始出處和作者信息及本聲明
原文地址:http://helenfj.blogbus.com/logs/60894038.html

 

時間以及時區設置
首先確認使用utc還是local time.
UTC(Universal Time Coordinated)=GMT(Greenwich Mean Time)
Local time 是你手錶上的時間

傳統的POSIX計算機(Solaris,bsd,unix)使用UTC格式
linux可以處理UTC時間和蹩腳的Windows所使用的local time

到底是使用UTC還是local time可以這樣來確定:
如果機器上同時安裝有Linux和Windows,建議使用local time
如果機器上只安裝有Linux,建議使用utc
確定後編輯/etc/sysconfig/clock, UTC=0 是local time; UTC=1 是UTC(GMT)

1) 使用cat /etc/sysconfig/clock查看當前時區
linux5:~ # cat /etc/sysconfig/clock
## Path: System/Environment/Clock
## Description: Information about your timezone and time
## Type: string
## ServiceRestart: boot.clock
#
# Set to "-u" if your system clock is set to UTC, and to "--localtime"
# if your clock runs that way.
#
HWCLOCK="-u"

## Type: string(Europe/Berlin,Europe/London,Europe/Paris)
## ServiceRestart: boot.clock
#
# Timezone (e.g. CET)
# (this will set /usr/lib/zoneinfo/localtime)
#
TIMEZONE="US/Pacific"
DEFAULT_TIMEZONE="US/Pacific"
linux5:~ #

2) 使用tzselect設置時區,最後結果如下

You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
linux5:~ #

3) 複製相應的時區文件,替換系統默認時區
linux5:~ # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
linux5:~ #

4) 將當前時間寫入BIOS永久生效(避免重啓後失效)
linux5:~ # hwclock
Tue Jan 29 18:22:59 2008 -0.565688 seconds
linux5:~ #

10. 配置ntp客戶端
編輯/etc/ntp.conf,增加一行server 10.30.1.10,其中10.30.1.105就是時鐘服務器,如下
linux:/var/log # grep -v \# /etc/ntp.conf

server 10.30.1.105

查看ntp服務的狀態
linux:/var/log # /etc/init.d/xntpd status
Checking for network time protocol daemon (NTPD): unused

設置時區以及時間
/usr/sbin/zic -l PRC
/bin/date "+%H:%M:%S - %d-%m-%Y"

寫回硬件時鐘
/sbin/hwclock --hctosys --localtime
或者寫回硬件時鐘: hwclock --systohc

在/etc/rc.d/rc5.d創建xntp服務的啓動腳本
linux:/etc/rc.d/rc5.d # ln -s ../xntpd S14xntpd
查看ntp時間調整紀錄
linux:/var/log # grep ntp messages
Aug 14 07:19:51 linux ntpdate[2837]: step time server 10.30.1.105 offset 2.010174 sec
Aug 14 07:19:51 linux ntpd[2884]: ntpd [email protected] Wed Jun 30 18:37:03 UTC 2004 (1)
Aug 14 07:19:51 linux ntpd[2884]: precision = 1.000 usec
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, 0.0.0.0#123
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, ::#123
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface lo, 127.0.0.1#123
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface eth0, 10.40.157.66#123
Aug 14 07:19:51 linux ntpd[2884]: kernel time sync status 0040

mmscbill:~ # date
Wed May 7 15:53:10 CST 2008
這裏時區設置沒有錯. PRC是時區的名稱,它對應/usr/share/lib/zoneinfo下的PRC時區文件.
CST是Chinese Standard Time的縮寫,用在date命令的輸出中.它是定義在PRC時區文件中.看
一下/usr/share/lib/zoneinfo/src下的asia文件就知道是怎麼回事了.

修改系統時間(bjchenxu,laixi781211,hutuworm)
date -s “2003-04-14 cst”,cst指時區,時間設定用date -s 18:10
修改後執行clock -w 寫到CMOS
hwclock --systohc
set the hardware clock to the current system time

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章