当前位置: > Linux发行版 > Debian >

debian7 调整时间

时间:2015-10-10 12:26来源:linux.it.net.cn 作者:IT

参考这个

设置时区

root@debian-armhf:/home/rtmpSRV/nolibrtmp# 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
#? 1

The following information has been given:

China
Beijing Time

Therefore TZ=’Asia/Shanghai’ will be used.
Local time is now: Thu Jan 1 08:26:29 CST 1970.
Universal Time is now: Thu Jan 1 00:26:29 UTC 1970.
Is the above information OK?
1) Yes
2) No
#? yes
Please enter 1 for Yes, or 2 for No.
#? 1

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

root@debian-armhf:/home/rtmpSRV/nolibrtmp# cat /etc/localtime
TZif2UTCTZif2UTC
UTC0
/etc/localtimemhf:/home/rtmpSRV/nolibrtmp# cat /etc/localtime
TZifip ~hp”^Jp$Gg%_

执行这个

cp /usr/share/zoneinfo/Asia/Shanghai /usr/localtime
将北京时间设置为本地时间,即系统将使用北京时间来显示系统时间

无法访问硬件时间

root@debian-armhf:/home/rtmpSRV/nolibrtmp# hwclock
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the –debug option to see the details of our search for an access method.

当前时间
root@debian-armhf:/home/rtmpSRV/nolibrtmp# date
1970年 01月 01日 星期四 08:30:03 CST

这个服务器不行
root@debian-armhf:/home/rtmpSRV/nolibrtmp# ntpdate time.nist.org
1 Jan 08:31:12 ntpdate[2902]: no server suitable for synchronization found
root@debian-armhf:/home/rtmpSRV/nolibrtmp# ntpdate 61.139.8.101
1 Jan 08:31:30 ntpdate[2903]: no server suitable for synchronization found

这个可以
root@debian-armhf:/home/rtmpSRV/nolibrtmp# ntpdate time.nist.gov
11 Sep 14:35:58 ntpdate[2904]: step time server 66.219.116.140 offset 1441951458.387245 sec
root@debian-armhf:/home/rtmpSRV/nolibrtmp#

当前时间

root@debian-armhf:/home/rtmpSRV/nolibrtmp# date
2015年 09月 11日 星期五 14:37:24 CST

这俩不行

root@debian-armhf:/home/rtmpSRV/nolibrtmp# hwclock -w –localtime
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the –debug option to see the details of our search for an access method.
root@debian-armhf:/home/rtmpSRV/nolibrtmp# rdate -s time.nist.gov
-bash: rdate: 未找到命令
root@debian-armhf:/home/rtmpSRV/nolibrtmp#

btime的时间自动被修改了:

root@debian-armhf:/home/rtmpSRV/nolibrtmp# cat /proc/stat
cpu 3289 0 2410 430968 8481 0 54 0 0 0
cpu0 469 0 1250 217771 2627 0 49 0 0 0
cpu1 2820 0 1160 213197 5854 0 5 0 0 0
intr 439609 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 246685 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 0 0 0 0 0 0 0 0 0 3539 1 0 0 0 0 0 25 6 0 0 0 19618 0 0 0 1 22075 2 0 0 0 0 133673 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 101522
btime 1441951458
processes 2909
procs_running 1
procs_blocked 0
softirq 114467 0 41005 417 3004 0 0 24264 33728 6 12043
root@debian-armhf:/home/rtmpSRV/nolibrtmp#

一些基础理论知识,参考

据说/dev/rtc是以前的规定,现在是兼容性更好的/dev/rtc0,115内核默认就是这个,内核驱动的配置也不是在字符设备里头了,是在设备驱动里头单独有个rtc模块。

 
1 (1)hwclock
2 为了查看硬件时钟是否为本地时间,运行命令hwclock –r。结果系统提示:“Could not open RTC: No such file or directory”,即找不到RTC文件。
3 (2)/dev/rtc
4 由于内核在编译过程中没有提供RTC支持,需要重新编译内核(或为内核增加一个module)。方法为,在make menuconfig阶段,选中“Character device”的“Enhanced Real Time Clock Support”一项的支持。
5 为内核增加了该模块后,目录/proc/drive/下已出现了rtc文件,cat也能查看到正常的内容。但/dev/目录下仍没有rtc文件。
6 于是通过mknod命令在/dev目录下增加rtc文件。通过man rtc可以得知,RTC为只读字符设备,主10,从135。因此命令为“mknod /dev/rtc c 10 135”。命令执行完毕后,/dev下成功生成了rtc文件。
7 运行hwclock –r,能够看到硬件时间为本地时间。通过date命令查看系统时间,却为UTC时间。这说明系统没有进行本地时间的设置。

 

 

mkmod后,甚至ln -s /dev/rtc0 /dev/rtc ,  最后hwclock还是不成功:

 
01 (3)/etc/localtime
02 Linux的系统时区是通过符号连接/etc/localtime来得到的。可以通过tzset命令来设置时区。如果没有该命令,可以通过命令“ln –s /etc/localtime /usr/share/zoneinfo/Asia/Shanghai”来将时区设置为亚洲的上海。
03 由于最初构建系统的时候没有包含zoneinfo信息,因此/usr/share目录下不存在zoneinfo目录及其文件。所以将包含zoneinfo信息的机器的/usr/share目录下的整个zoneinfo目录复制到本机的/usr/share目录下。
04 通过date命令检查时间,发现已变成了正常的本地时间:
05 Mon Aug 29 13:14:29 CST 2005
06 (4)/etc/sysconfig/clock
07 该配置文件可用来设置用户选择何种方式显示时间。如果硬件时钟为本地时间,则UTC设为0,并且不用设置环境变量TZ。如果硬件时钟为UTC时间,则要设置UTC为1,并设置环境变量TZ(或配置文件/etc/TZ)为时区信息,如“Asia/Shanghai”。
08 我机器的硬件时间为本地时间,因此该配置文件内容为:
09 ZONE="Asia/Shanghai"
10 UTC=0
11 ARC=0



(责任编辑:IT)
------分隔线----------------------------