文章來源:www.liberiangeek.net/2013/02/setti...
Setting The Correct Timezone In CentOS And Ubuntu Servers With NTP
First, let view all the timezones your sytem has by running the commands below. Remember to run these commands as root. In Ubuntu always precede the commands with wudo.
# ls /usr/share/zoneinfo
Take notes of the available timezones on your system. Next, you’ll want to replace the current timezone file in /etc/ directory with the correct one. To do that, remove the current timezone file by running the commands below.
# mv /etc/localtime /etc/localtime.bak
Next, run the commans below to link the local timezone file with the correct one in the /usr/share/zoneinfo directory.
# ln -s /usr/share/zoneinfo/PRC /etc/localtime
Next, install these packages if you haven’t already done so in Ubuntu or CentOS.
$ sudo apt-get install ntp ntpdate
Here’s the same commands in CentOS.
# yum install ntp ntpdate
Once ntp is installed, run the commands below to synchronize your server’s internal clock. There are multiple ntp servers to choose from so if the one below isn’t what you want, then choose a different server.
# ntpdate 0.us.pool.ntp.org
Finally, run the commands below to apply the changes to the hardware so it sticks after reboot.
# hwclock --systohc
Enjoy!
以下為自己償試的譯文(可能會有些不準確的地方,勿噴^_^)
用
NTP
設定CentOS
和Ubuntu
伺服器的正確時區
首先,讓我們執行以下命令,來檢視系統所有時區,記住需要使用 root
。在 Ubuntu
裡,我們常常需要在該命令前使用 sudo
。
# ls /usr/share/zoneinfo
記錄下來在您系統裡找到的時區。然後,你應該想要用正確的時區檔案來替換在 /etc 目錄下的當前時區檔案,這樣,您需要執行以下命令來刪除當前時區檔案:
# mv /etc/localtime /etc/localtime.bak
然後,執行以下命令,用 /usr/share/zoneinfo 目錄里正常的時區檔案連結到當前時區檔案
(譯者注:中國用PRC即可,PRC指向的其實是 Asia/Shanghai )
# ln -s /usr/share/zoneinfo/PRC /etc/localtime
然後,如果 Ubuntu
裡沒有這些包,則需要安裝
$ sudo apt-get install ntp ntpdate
在 CentOS
裡可以用這個命令
# yum install ntp ntpdate
一旦 ntp
安裝了,命令以下命令來同步您伺服器上的內部時鐘。有很多 ntp
伺服器去選擇,如果以下不是您想要的,可以選擇不同的伺服器。
# ntpdate 0.us.pool.ntp.org
Finally, run the commands below to apply the changes to the hardware so it sticks after reboot.
最後,執行以下命令,更改硬體時鐘,這樣下次重啟以後也會生效了。
# hwclock --systohc
玩得開心!
本作品採用《CC 協議》,轉載必須註明作者和本文連結