MySQL服务器时间同步问题处理(2)

[root@wgq_idc_mon_1_12 ~]# zdump /usr/share/zoneinfo/Asia/Shanghai
/usr/share/zoneinfo/Asia/Shanghai  Sat Sep 26 13:11:23 2015 CST
[root@wgq_idc_mon_1_12 ~]#
那么我们又怎么来告诉系统我们所在TIME ZONE是哪个呢? 方法有很多,这里举出两种:

第一个就是修改/etc/localtime这个文件,这个文件定义了我么所在的local time zone.

[root@wgq_idc_mon_1_12 ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp:是否覆盖"/etc/localtime"? y
[root@wgq_idc_mon_1_12 ~]# date
2015年 09月 26日 星期六 13:19:00 CST
[root@wgq_idc_mon_1_12 ~]#
第二种方法也就设置TZ环境变量的值. 许多程序和命令都会用到这个变量的值. TZ的值可以有多种格式,最简单的设置方法就是使用tzselect命令,如下所示:

[root@wgq_idc_mon_1_12 ~]# 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:  Sat Sep 26 13:21:14 CST 2015.
Universal Time is now:  Sat Sep 26 05:21:14 UTC 2015.
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@wgq_idc_mon_1_12 ~]#
[root@wgq_idc_mon_1_12 ~]# more /etc/localtime
TZif2
CST-8
[root@wgq_idc_mon_1_12 ~]#
TZ变量的值会override /etc/localtime. 也就是说当TZ变量没有定义的时候系统才使用/etc/localtime来确定time zone.

所以你想永久修改time zone的话那么可以把TZ变量的设置写入/etc/profile里

2.3 Read Time Clock(RTC) and System Clock
说道设置时间这里还要明确另外一个概念就是在一台计算机上我们有两个时钟:一个称之为硬件时间时钟(RTC),还有一个称之为系统时钟(System Clock);

硬件时钟是指嵌在主板上的特殊的电路, 它的存在就是平时我们关机之后还可以计算时间的原因;
系统时钟就是操作系统的kernel所用来计算时间的时钟. 它从1970年1月1日00:00:00 UTC时间到目前为止秒数总和的值; 在Linux下系统时间在开机的时候会和硬件时间同步(synchronization),之后也就各自独立运行了 ;

那么既然两个时钟独自运行,那么时间久了必然就会产生误差了,下面我们来看一个例子;

通过hwclock –help命令查看hwclock的各种用途:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/430507ebdf7cefc8dc61b97bef307c9a.html