centos 修改date系統(tǒng)時間
查看和修改linux的時間和時區(qū)
1、查看當前時間、時區(qū)、日歷
# date
Tue Dec 25 15:36:09 CST 2013
# date -R
Tue, 25 Dec 2013 15:36:13 +0800
# cal
December 2013
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
2、修改服務(wù)器的時間
1)修改日期的格式,時分時秒默認為 00:00:00
# date -s 2013/12/25 // ok
Wed Dec 25 00:00:00 CST 2013
# date -s 2013-12-25 // ok
Wed Dec 25 00:00:00 CST 2013
# date -s 12/25/2013 // ok
Wed Dec 25 00:00:00 CST 2013
# date -s 25/12/2013 // error
date: invalid date ‘25/12/2013’
2)修改時間的格式
# date -s 15:50:30
Tue Dec 25 15:50:30 CST 2013
# date
Tue Dec 25 15:50:31 CST 2013
3)寫入到主板CMOS
# clock -w
# hwclock -w
3、修改服務(wù)器的時區(qū)
1)tzselect
# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please select a country.
1) Afghanistan 18) Israel 35) Palestine
2) Armenia 19) Japan 36) Philippines
3) Azerbaijan 20) Jordan 37) Qatar
4) Bahrain 21) Kazakhstan 38) Russia
5) Bangladesh 22) Korea (North) 39) Saudi Arabia
6) Bhutan 23) Korea (South) 40) Singapore
7) Brunei 24) Kuwait 41) Sri Lanka
8) Cambodia 25) Kyrgyzstan 42) Syria
9) China 26) Laos 43) Taiwan
10) Cyprus 27) Lebanon 44) Tajikistan
11) East Timor 28) macau 45) Thailand
12) Georgia 29) Malaysia 46) Turkmenistan
13) Hong Kong 30) Mongolia 47) United Arab Emirates
14) India 31) Myanmar (Burma) 48) Uzbekistan
15) Indonesia 32) Nepal 49) Vietnam
16) Iran 33) Oman 50) Yemen
17) Iraq 34) Pakistan
#? 9
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
Therefore TZ='Asia/Shanghai' will be used.
Local time is now: Tue Dec 25 16:09:30 CST 2013.
Universal Time is now: Tue Dec 25 08:09:30 UTC 2013.
Is the above information OK?
1) Yes
2) No
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 /bin/tzselect command in shell scripts:
Asia/Shanghai
2)復(fù)制時區(qū)文件軟鏈接到 /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Chongqing /etc/localtime // 軟鏈到東八區(qū) - 重慶
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime // 軟鏈到東八區(qū) - 上海
Linux 修改時間的命令
date –s '2013-12-25 10:10:10'
clock –w // 將日期寫入CMOS,避免重啟后失效
hwclock –w // 將日期寫入CMOS,避免重啟后失效
Linux時間修改3個命令
date:修改系統(tǒng)當前的時間
clock:修改CMOS時間(查看CMOS時間:clock -r)
hwclock:修改系統(tǒng)硬件時間
# date
Tue Dec 25 15:32:22 CST 2013
# clock -r
Tue 25 Dec 2013 03:32:27 PM CST -1.061780 seconds
# clock
Tue 25 Dec 2013 03:32:31 PM CST -1.071987 seconds
# hwclock
Tue 25 Dec 2013 03:32:35 PM CST -1.055773 seconds
hwclock 硬件時鐘的用法
hwclock --show // 查看硬件時鐘
hwclock --set --date="1/23/01 22:16:59" // 設(shè)置硬件時鐘
# hwclock
Tue 25 Dec 2013 03:53:28 PM CST -1.059641 seconds
# hwclock --set --date='2013-12-25 03:53:38'
硬件時間從根本上講是CMOS時鐘;而系統(tǒng)時間是由內(nèi)核維護的,它是從1969年末(即傳說中的標志Unix時代開端的那個拂曉)開始算起的累積秒數(shù)。
在DOS或Mac系統(tǒng)中,起作用的是硬件時鐘。
遺憾的是,你可能已經(jīng)發(fā)現(xiàn)了,絕大多數(shù)電腦時鐘都是很不準確的。它們從根本上講是由小型電池供電的警報器時鐘,這種鋰電池一般可持續(xù)供電三年左右,那時候你系統(tǒng)各大塊差不多都已經(jīng)過時了。而在Linux系統(tǒng)中,起作用的是系統(tǒng)時鐘。在啟動時,它靠讀取硬件時鐘獲得計時起點,而不是靠記憶計時。
你可以通過BIOS修改系統(tǒng)硬件時鐘,或者如果你不想重啟機器,那就用hwclock命令。
硬件時鐘通常被設(shè)置成全球標準時間(UTC),而將時區(qū)信息保存在 /usr/share/zoneinfo/ 或 /usr/share/lib/timezone 或在某些系統(tǒng)中可能是/usr/local/timezone 的目錄下某個適當?shù)奈募校缓笥靡粋€符號鏈接文件/etc/localtime指向它。
例如:]# ll /etc/localtime
lrwxrwxrwx. 1 root root 34 May 2 2013 /etc/localtime -> /usr/share/zoneinfo/Asia/Chongqing
CentOS下的操作
ln -sf /usr/share/zoneinfo/Asia/Chongqing /etc/localtime // 修正時區(qū)
date –s '2011-11-23 22:34:10' // 設(shè)置時間
clock –w // 將時間寫入CMOS
AWS EC2上修改RedHat系統(tǒng)時區(qū)及ntp對時
有人說EC2上不需要進行對時,基于Xen的虛擬機的系統(tǒng)時間會跟宿主的時間保持一致,并且不需要運行ntpd服務(wù),不過從運維的角度我們還是決定根據(jù)需要自己配置時區(qū)及對時。假設(shè)您AWS上的EC2實例是創(chuàng)建在新加坡,并且是面向東南亞用戶,可以使用新加坡當?shù)貢r間。
具體步驟如下:
1. 修改時區(qū)
sudo cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime // 默認為UTC時間
2. 配置ntp服務(wù)
vim /etc/ntp.conf
Amazon EC2添加ntp服務(wù)器
server 0.amazon.pool.ntp.org iburst
server 1.amazon.pool.ntp.org iburst
server 2.amazon.pool.ntp.org iburst
server 3.amazon.pool.ntp.org iburst
3. 重啟ntpd服務(wù)及設(shè)置自動啟動
/etc/init.d/ntpd start
chkconfig ntpd on
4. 查看ntp狀態(tài)
ntpstat
ntpq -p