阿里云ECS的坑 – 系统硬件时间

用了这么久 的阿里云ecs,也是今天无意间才发现的,更准确的说应该是centos 7的坑,在centos 6上那样直接修改时区的办法不行了

1)拿到了阿里云的ecs,第一件事就是应该修改系统的hwclock,这是因为阿里云的ecs默认使用的是hwclock 是cst,也就是中国时区。这个可以是可以,但是国际上通用的办法是使用UTC时间,这更能避免很多问题:

timedatectl set-local-rtc 0

2) 第二个坑就是因为有了第一个问题以后,在centos 6上我经常使用下面的办法修改时区(个人习惯,所有的服务器都是UTC或者EST时区):

cp /usr/share/zoneinfo/America/New_York /etc/localtime

在centos 7上我也继续这么使用,在国外的服务器上没有一点问题,但是在阿里云ecs上就会出现下面的情况:

[root@sz ~]# timedatectl
Local time: Wed 2020-01-29 07:57:08 EST
Universal time: Wed 2020-01-29 12:57:08 UTC
RTC time: Wed 2020-01-29 20:57:07
Time zone: Asia/Shanghai (EST, -0500)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: yes
DST active: no
Last DST change: DST ended at
Sun 2019-11-03 01:59:59 EDT
Sun 2019-11-03 01:00:00 EST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2020-03-08 01:59:59 EST
Sun 2020-03-08 03:00:00 EDT

Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.

重点是timezone 那一行, Asia/Shanghai 变成了EST了,明显不对, 我们需要用下面的命令修改一下:

timedatectl set-timezone "America/New_York"

重启以后,系统的各种时间才会恢复正常.

为什么要这么做?因为如果你不这么做,系统的时间和mysql 的时间会发生冲突,当你需要重启mysql服务的时候,就会出现:

InnoDB: Waiting for page_cleaner to finish flushing of buffer pool

让你需要最起码5分钟以上才能完全重启mysql服务或者重启服务器。。。

下午遇到了问题,一台新装的ecs服务器需要最少5分钟才能重启。。。刚开始以为是smokeping 重启过慢,仔细debug了开机启动,发现是关机速度太慢。。。然后看log 发现是mysql shutdown 时间太长,InnoDB需要清空buffer。。。再继续debug才发现这是系统时间的问题。。。

浪费了整整一下午。。。

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.