Quantcast
Channel: 羽飞博客 » 8小时
Viewing all articles
Browse latest Browse all 2

再谈关于RHEL6系统时间相差8小时的问题

0
0

今天我测试网页的发邮件功能,RHEL6.1系统已经安装的Postfix,而且也随系统启动了,但就是发不出来邮件,于是就开始查找原因,虽然目前还没有找到邮件不能发送的原因。(现在已经写出POSTFIX的问题解决方法了关于postfix发邮件No route to host和Connection refused错误的解决方法)但却发现了系统的时间不正确。按网上的资料也没有解决我的问题,不知道大家是如何解决的,那今天就把我解决的方法给大家共享出来,供大家参考学习。

先来看看问题是什么样的:

1、系统的BISO时间是完全正确的

2、用hwclock -r查看的系统时间

[root@yufei ~]# hwclock -r
Wed 13 Jul 2011 05:50:55 AM CST  -0.868339 seconds

而现在的北京时间是7月12号21:50。正好相差8小时。

3、用hwclock -D来调试的结果是

[root@yufei ~]# hwclock -D
hwclock from util-linux-ng 2.17.2
Using /dev interface to clock.
Last drift adjustment done at 1310506688 seconds after 1969
Last calibration done at 1310506688 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2011/07/12 21:44:52
Hw clock time : 2011/07/12 21:44:52 = 1310507092 seconds since 1969
Wed 13 Jul 2011 05:44:52 AM CST  -0.315375 seconds

发现能正确读取到BIOS的时间,但用date命令还是不正确,依然相差8小时,还是Wed 13 Jul 2011 05:44:52

4、折腾了半天也没有设置正确,希望大家别和我一样啊!!哈哈……

下面是我的解决方法

1、我已经忘记了我的系统在安装的时候有没有开启UTC,这一点,我们先忽略。(因为按网上的关掉UTC设置方法,不能解决问题)

2、因为网上资料都基本上雷同,所以我就看hwclock的帮助,想从中找到解决的办法,结果真让我给找到了。

3、使用 hwclock –help查看帮助内容,这个命令大家一定要注意他的使用方法。这样才能找到原因。下面我就把几个重要的内容摘录出来,给大家做个解释。

[root@yufei ~]# hwclock --help
hwclock - query and set the hardware clock (RTC)

Usage: hwclock [function] [options...]
这里需要大家特别注意:先是函数后是参数,只用其中一个是没有用的,这是解决问题的关键

Functions:
  -r | --show         read hardware clock and print result #读取硬件(BIOS)时间,并显示出来
  -s | --hctosys      set the system time from the hardware clock #把目前系统时间调整为硬件时间
  -w | --systohc      set the hardware clock to the current system time #把硬件时间调整为目前系统的时间
       --systz        set the system time based on the current timezone #把系统时间设置为当时时区的时间

Options:
  -u | --utc          the hardware clock is kept in UTC #设置硬件为的UTC时间
       --localtime    the hardware clock is kept in local time #设置硬件为本地时间

hwclock的使用方法很关键,有了上面的解释后,综合一下,就得到了解决问题的方法了。

[root@yufei ~]# hwclock -s --localtime

这一句命令解决所有问题。

注意:

1、确保你的时区要设置正确/etc/sysconfig/clock

2、确保你的系统中的BIOS时间正确

关于如何关闭UTC啊,如何设置时区啊,大家可以参考http://www.opsers.org/linux-home/base/8-hour-time-difference-on-the-linux-incorrect-solution.html


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images