linux 設定時區

來源:互聯網
上載者:User

 

時間以及時區設定
首先確認使用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 4.2.0a@1.1213-r 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

 

zdump -v Europe/Moscow 查看時區一些設定參數

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.