天天看點

linux 設定時區

時間以及時區設定

首先确認使用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)

# 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

3) 複制相應的時區檔案,替換系統預設時區 

linux5:~ # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

4) 将目前時間寫入BIOS永久生效(避免重新開機後失效) 

linux5:~ # hwclock

Tue Jan 29 18:22:59 2008  -0.565688 seconds

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

上一篇: linux IP 設定

繼續閱讀