设为首页 加入收藏

TOP

MySQL服务器时间同步问题处理(二)
2015-11-10 12:16:42 来源: 作者: 【 】 浏览:7
Tags:MySQL 服务器 时间 同步 问题 处理
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的各种用途:


[root@wgq_idc_mon_1_12 ~]# hwclock --show
2015年09月26日 星期六 13时58分34秒? -0.219418 seconds
[root@wgq_idc_mon_1_12 ~]#
hwclock –hctosys 把硬件时间设置成系统时间


hwclock –systohc 把系统时间设置成硬件时间


hwclock –set –date=”mm/dd/yy hh:mm:ss” 设置硬件时间我们可以开机的时候在BIOS里设定.也可以用hwclock命令


date -s “dd/mm/yyyy hh:mm:ss” 修改系统时间用date命令就最简单了


现在我们知道了如何设置系统和硬件的时间. 但问题是如果这两个时间都不准确了怎么办? 那么我们就需要在互联网上找到一个可以提供我们准确时间的服务器然后通过一种协议来同步我们的系统时间,那么这个协议就是NTP了. 接下去我们所要说的同步就都是指系统时间和网络服务器之间的同步了


2.4 设置NTP Server前的准备
其实这个标题应该改为设置”NTP Relay Server”前的准备更加合适. 因为不论我们的计算机配置多好运行时间久了都会产生误差,所以不足以给互联网上的其他服务器做

首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇从Java的类型转换看MySQL和Oracle.. 下一篇MySQL日期字符串转换成NULL值的异..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: