http://blog.itpub.net/27099995/viewspace-1370723/

今天又被开发的说服务器时间异常,时差很大。我就纳闷了,上个星期都调整过的。
去查看了一下。

[root@BIAPP default]# date -R 
Fu, 11 Dec 2014 02:26:08 ---- 今天是双十二
----修改完后,记得输入,这是修改到系统时间

但是我上次也是这样修改的。那么过段时间肯定又会出现时差,所以得找出真正的原因,问了一个老系统工程师才知道其中的原因。
看见上面红色的-0500
吗?它应该是美国地区的,西-5时区。
而我们中国一般设置的都是以东时区,Linux里面一般出现的有:北京,上海,香港
。举例上海的就是+0800
[root@BIAPP ~]# date -R
Fri, 12 Dec 2014 11:31:20

  • [root@BIAPP ~]#) 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.
  • #?--- 亚洲的英文是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
  • ) 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
  • #? =\'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
:将硬件时间写入系统时间
这样服务器的硬件和系统时间全部都修改一致,同时修改了时区。我想应该不会出现之前的时差吧!

最新文章

  1. 30个要点帮你完成java代码优化
  2. 2015暑假多校联合---Expression(区间DP)
  3. WordPress 常用数据库SQL查询语句大全
  4. makefile中的自动化变量$@,$%,$
  5. ccc2016
  6. tunnel.p4
  7. 如何使VS2008 调试网站的根目录和IIS调试的一致?
  8. BestCoder Round #66 (div.2) hdu5592
  9. 60分钟Python快速学习(转)
  10. .NET Excel导出方法及其常见问题详解
  11. memcache 中的add set 和replace的区别
  12. ThreadLocal原理
  13. 编年史:OI测试
  14. Python—生成器
  15. CI框架在控制器中切换读写库和读写库
  16. httplib urllib urllib2 pycurl 比较
  17. 【Java】Java8的Lambda入门记录
  18. 20190422 DW/BI系统
  19. 海量数据找相同数,高配词,不重复的数,判断一个数是否存在,查询串,不同电话号码的个数,中位数,按照query频度排序,topk
  20. terminate called after throwing an instance of 'std::bad_alloc'

热门文章

  1. flex builder 4
  2. 团队作业4——第一次项目冲刺(Alpha版本)-第一篇
  3. win7 C/C++,QT安装环境总结
  4. docker/qemu中是如何对设备管理的
  5. Python 装饰器和抽象类
  6. [CF1066C]Books Queries
  7. [Leetcode] Symmetric tree 对称二叉树
  8. SCU3037 Painting the Balls
  9. json获取属性值的方式
  10. Ubuntu 12.04更新源(转)