[Linux] 設定系統時區

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   使用   ar   strong   

1. 檢查當前時區

  以 root 身份登入。

# dateFri Sep  5 01:53:21 UTC 2014

 

  其中 UTC 是指當前使用的時間系統為世界標準時間,也稱世界協調時間。英文名稱為 Coordinated Universal Time,法文名稱為 Temps Universel Coordonné。作為英文縮寫 CUT 和法文縮寫 TUC 的妥協方案,簡稱 UTC。中國所處時區為 UTC+8。

 

2. 查看可用時區

  查看目錄 /usr/share/zoneinfo,可以看到所有時區。(根據 Linux 發行不同而可以時區列表不同。)

# ls /usr/share/zoneinfoAfrica      Australia  Cuba     Etc      GMT+0      Iceland  Kwajalein  NZ       Poland     Turkey     WET          rightAmerica     Brazil     EET      Europe   GMT-0      Indian   Libya      NZ-CHAT  Portugal   UCT        Zulu         zone.tabAntarctica  CET        EST      Factory  GMT0       Iran     MET        Navajo   ROC        US         iso3166.tabArctic      CST6CDT    EST5EDT  GB       Greenwich  Israel   MST        PRC      ROK        UTC        localtimeAsia        Canada     Egypt    GB-Eire  HST        Jamaica  MST7MDT    PST8PDT  Singapore  Universal  posixAtlantic    Chile      Eire     GMT      Hongkong   Japan    Mexico     Pacific  SystemV    W-SU       posixrules

 

3. 設定時區3.1. 手動設定時區

  首先備份一下當前的時區配置。

# mv /etc/localtime /etc/localtime-old

 

  使用新的時區。你可以在地區列表中找到你所處的城市,如果沒有你所處的城市,那麼選擇另一個同時區的城市。

# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

 

  配置完成後你可以使用 date 命令查看是否已經生效。

 

3.2. 自動化佈建時區

  在 Ubuntu 中內建了設定時區工具,tzconfig 不推薦使用,使用 dpkg-reconfigure tzdata 命令調出設定 UI,跟隨介面指示設定即可完成時區設定。

$ sudo dpkg-reconfigure tzdata

 

  彈出對話方塊:

 

  選擇大洲後,然後選擇時區城市,北京時間選擇 Shanghai 即可:

Current default time zone: ‘Asia/Shanghai‘Local time is now:      Sat Sep 20 21:03:38 CST 2014.Universal Time is now:  Sat Sep 20 13:03:38 UTC 2014.

 

4. 設定伺服器與互連網時間伺服器同步

  大多數現代 Linux 發行版本都已經預裝 NTP 程式包。如果你的伺服器沒有安裝它,你可以手動安裝。

  1. Ubuntu/Debian: 

$ sudo aptitude install ntp

 

  2. CentOS: 

$ sudo yum install ntp$ sudo /sbin/chkconfig ntpd on

 

  3. Fedora/RedHat:

$ sudo yum install ntp$ sudo chkconfig ntpd on

 

  安裝完畢後執行:

$ ntpdate && hwclock -w

 

  或者與 cn.pool.ntp.org 同步一下時間,該網站是位於中國的 NTP 公用伺服器:

 

$ sudo ntpdate cn.pool.ntp.org20 Sep 21:08:33 ntpdate[2057]: adjust time server 202.112.29.82 offset 0.017623 sec

 

 

 

 

 

附:

1. 3 Ways to Change the Timezone in Linux

2. How To Set Up Synchronization on Ubuntu 12.04 

3. tzconfig (deprecated)

4. dpkg-reconfigure tzdata

[Linux] 設定系統時區

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.