`
tomcat_oracle
  • 浏览: 311517 次
社区版块
存档分类
最新评论

RedHat 6* 修改系统时区解决

阅读更多
  今天又被开发的说服务器时间异常,时差很大。我就纳闷了,上个星期都调整过的。
  去查看了一下。
  [root@BIAPP default]# date -R
  Fu, 11 Dec 2014 02:26:08 -0500
  跟当前的时间大概相差13个小时。于是我就手动的修改了时间:
  # date -s "2014-12-12 11:30:00"   ---- 今天是双十二
  # clock -w      ----修改完后,记得输入,这是修改到系统时间
  但是我上次也是这样修改的。那么过段时间肯定又会出现时差,所以得找出真正的原因,问了一个老系统工程师才知道其中的原因。
  看见上面红色的-0500 吗?它应该是美国地区的,西-5时区。
  而我们中国一般设置的都是以东时区,Linux里面一般出现的有:北京,上海,香港 。举例上海的就是+0800
  [root@BIAPP ~]# date -R
  Fri, 12 Dec 2014 11:31:20 +0800
  现在只是修改了时间,但是问题还没有根本解决,我们要解决时区问题。
[root@BIAPP ~]# 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  --- 亚洲的英文是Asia 别搞错了啊。
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: Sat Dec 13 00:59:53 CST 2014.
Universal Time is now: Fri Dec 12 16:59:53 UTC 2014.
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
[root@bidevelop4 ~]#
[root@BIAPP ~]# export TZ=\'Asia/Shanghai\'
 --这里其实可以写到.bash_profile里面
  上面的提示已经很清楚了,不需要我多解释了。
  不过我发现,修改了之后,还有不能生效,因为只是改了时区,服务器分为硬件时间和系统时间。所以设定了时区,还要确定Linux的时间方案。
  学习一下:
  Linux支持UTC时间,Coordinated Universal Time,也就是世界协调时,也就是本初子午线上的时间,它和以前的格林威治标准时(GMT)的区别似乎是它是由多个原子钟平均出来的。在 /etc/default/rcS这个文件中,设定了系统是否使用UTC,UTC=yes就是用。
  计算机自己还有自己的时间,也就是硬件时间,hard clock,也就是存在BIOS里那个时间,关机也不会丢失。
  计算机启动时,就要读取这个时间。这个时间如果设定为UTC(GMT),也就是伦敦那地方的时间,就要在rcS文件中设定UTC=yes,反之则要设为no。
  一般来讲,BIOS里面都设定为当地时间,这是因为如果装双系统的话,Windows似乎不懂UTC,就会出问题。这时UTC=no。
  (a).网上说法:时区的配置,主要是两个文件:
  /etc/localtime
  /etc/timezone
  timezone这个文件是个文本,里面只需要写一行自己的时区就行,我们这里就是上海(Asia/Shanghai)
  localtime这个文件的类型不清楚,里面就写了些timezone data,它可以从系统自带时区文件那里拷贝,位置在:/usr/share/zoneinfo
  从这个目录下找到Shanghai拷贝到/etc下的localtime即可,同样也可以做个联接,也是同样效果
  (b).网上说法:修改时间的配置文件时/etc/default/rcS
  但是我在我的系统里面没有找到这个文件。
  2、修改时间
  修改好了时区后,我们可以手动的修改时间,或者可以做一个时间同步:
  [root@BIAPP ~]#  /usr/sbin/ntpdate pool.ntp.org   ---- 这是和中国国家授时中心同步
  最好是做一个自动任务,每天凌晨自动做一次同步。
  我这里在同步了时间之后,先查看硬件时间是否正确,如果不正确就修改硬件时间。
  Linux读取这个硬件时间要用到hwclock这个命令:
  hwclock --show :显示硬件时间
  hwclock --systohc :将系统时间写入硬件
  hwclock --hctosys :将硬件时间写入系统时间
  这样服务器的硬件和系统时间全部都修改一致,同时修改了时区。我想应该不会出现之前的时差吧!
2
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics