linux時鐘基本概念、CST與UTC、以及NTP簡單設定

season0891發表於2014-02-11

1,安裝linux的時候在設定時間的時候有一個選項:
system clock uses UTC,那麼這個UTC是什麼意思呢?


世界協調時間(Universal Time Coordinated,UTC)
GPS 系統中有兩種時間區分,一為UTC,另一為LT(地方時)兩者的區別為時區不同,UTC就是0時區的時間,地方時為本地時間,如北京為早上八點(東八區),UTC時間就為零點,時間比北京時晚八小時,以此計算即可


2,在linux中,用date檢視時間的時候顯示:
2008年 12月 17日 星期三 09:04:14 CST
這個CST是什麼意思呢?

CST China Standard Time UTC+8:00 中國沿海時間(北京時間)

############################################

以下內容是關於幫助你在linux下設定日期和時間的一些步驟,也包含了一點ntpd時間同步的內容。特別提醒的是在發行版本的限制是red hat系列,包括fedora,centos,redflag,unbreakable linux等。

There are two clocks to configure in Linux, the hardware clock and the system clock. The hardware clock determines the system clock on system boot. While the system is running, changes to one of these doesn't affect the other.

在linux下有兩個時鐘需要配置,硬體時鐘和系統時鐘。硬體時鐘在系統啟動時決定系統時鐘,當系統處於執行狀態下時,修改其中任何一個並不能對另一個預設生效。

Note: it's best to set the hardware clock and have the system clock be set upon a reboot. Changing the system clock by using the date program on a running system could cause date discontinuities and consequently problems. If you will be using ntpd, you probably don't need to set either of these clocks (unless the current time is more than 1000s off the real time). Just setup ntpd and let ntpd adjust the time (it will do it in small steps to keep system timestamps reliable).

  1. 現在大部分的發行版本在圖形介面下都提供了時鐘設定工具,例如kde,gnome都有友好的 圖形化工具,這裡就不多說了。
  2. You can use timeconfig to configure the timezone and UTC settings. Timeconfig will update /etc/sysconfig/clock and /etc/localtime.

  3. Set the time zone manually if not already set.

    Linux uses the file /etc/localtime to determine the time zone. This file should be either a copy of the appropriate timezone file from the directory /usr/share/zoneinfo or a symbolic link. If your time zone is incorrect, create a symbolic link to the appropriate timezone file.
    # ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  4. Set whether hwclock uses local time or UTC

    Edit the file /etc/sysconfig/clock and change "UTC=" to true or false. If you have a dual-boot system with Windows, using UTC may cause problems for Windows.

  5. Set the system clock
    # date MMDDhhmmCCYY.ss
    where MM is month, DD is day, hh is hour, mm is minutes, CCYY is year and ss is seconds. Time should be in 24-hour notation.

    To only set the time:
    # date -s hh:mm:ss
  6. Set the hardware clock

    To set the hardware clock to the current system clock:
    # setclock
    this method looks at /etc/sysconfig/clock to determine whether the hardware clock is set to UTC

    Another method:
    # hwclock --systohc
    # hwclock --systohc --utc
    use the second option if you use UTC.

    Set hwclock manually:
    # hwclock --set --date="9/22/96 16:45:05"
    Everytime you use the hwclock --set command, it will create or edit the file /etc/adjtime to determine the systematic drift. Once you have some history, you can use the --adjust option to adjust the hardware clock appropriately. Run as a cron job if you want the clock to adjust automatically on a regular schedule. Don't use the --adjust function when using ntpd since ntpd will turn the "11 minute mode" on, which is best left alone. See the hwclock manpage for more info.

  7. Setup ntpd for automatic synchronization with a remote server.

    Run Red Hat's setup utility to make ntpd start on boot up and edit /etc/ntp.conf

    Set server and fudge options:
    server time.nist.gov
    fudge time.nist.gov stratum 10
    Enable multicastclient:
    multicastclient     # listen on default 224.0.1.1
    Edit /etc/sysconfig/ntpd if necessary. The default should be fine.

    Start the ntpd daemon:
    # service ntpd start

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-1079648/,如需轉載,請註明出處,否則將追究法律責任。

相關文章