Chinaunix首页 | 论坛 | 博客
  • 博客访问: 212837
  • 博文数量: 53
  • 博客积分: 2059
  • 博客等级: 大尉
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-30 03:03
文章分类
文章存档

2012年(4)

2011年(19)

2010年(30)

分类: LINUX

2010-08-20 18:34:51

Linux时间和时区总结
1,设置时区的方法
众所周知的,全世界有24个时区,每个时区对应不同的地理时间,所有我们的系统也是按照时区来更新的本地的时间,ntp服务也是通过本地时区设置来更新时间的,
设置本地时区有一下几种方法:
1,
 #cat /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=true
ARC=false
在以上的参数中 UTC=true 打开才能通过ntp来更新时间
2,
#cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
在目录/usr/share/zoneinfo/下面时区的文件把它cp为/etc/locatime就可以了
3,使用命令
[root@test6 ~]# 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) east China - Beijing, Guangdong, Shanghai, etc.
2) Heilongjiang (except Mohe), Jilin
3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.
4) most of Tibet & Xinjiang
5) west Tibet & Xinjiang
#? 1
The following information has been given:
        China
        east China - Beijing, Guangdong, Shanghai, etc.
Therefore TZ='Asia/Shanghai' will be used.
Local time is now:      Fri Aug 20 18:04:53 CST 2010.
Universal Time is now:  Fri Aug 20 10:04:53 UTC 2010.
Is the above information OK?
1) Yes
2) 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
tzselect 根据命令提示来设置时区 如果想永久修改timezone的话,把TZ变量写入/etc/profile
2,Real Time Clock(RTC) and System Clock
硬件时间和系统时间说明
硬件时间简单的说指的是硬件中CMOS电池中的时间。
系统时间指的是操作系统的时间,这两个时间是各自独立运行的当然也可以进行他们之间的同步。
~]# hwclock --show
Fri 20 Aug 2010 06:15:58 PM CST  -0.978211 seconds
[root@test-1 ~]# date
Fri Aug 20 18:15:31 CST 2010
设置硬件时间使用hwclock
这里说三个比较重要的参数
hwclock --set设置硬件的时间
hwclock --hctosys 设置系统时间同步硬件时间
hwclock --systohc  把系统时间设置为硬件时间
修改系统时间
使用命令date
date -s "dd/mm/yy hh:mm:ss"
3,xen domain0 和domainU的时间同步问题
在Xen的默认设置下,domainU的时间总是要自动和domain0 保持同步的,但是有时候会同步失败,如果想简单的在domainU内部用各种时间,日期等命令改变domainU的时间是并不
起作用。有一下几种方法来设置,让domainU的时间不受domain0的影响,
1,直接改变Xen内核的运行时的参数
echo 1 >/proc/sys/xen/independent_wallclock
但是上面的方法重启虚拟机的时候,会丢失参数。
2,改变内核启动参数
vi /etc/sysctl.conf
xen.independent_walclock=1
sysctl -p
3,在domainU的启动配置文件中加上一下参数
vi /etc/xen/test
name = "test2"
uuid = "21d00018-9f1e-1a5f-5377-dcc85b544e19"
maxmem = 1024
memory = 1024
vcpus = 1
bootloader = "/usr/bin/pygrub"
extra='independent_wallclock=1'
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
vfb = [  ]
disk = [ "tap:aio:/opt/test2.img,xvda,w" ]
vif = [ "mac=00:16:3e:3a:3b:d4,bridge=xenbr0" ]
阅读(790) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~