服务器与CST时间误差8小时的修复方法

linux系统修改CST时区:
=================================================

初始时间:2012年 09月 14日 星期五 18:15:33 EDT

[root@test ~]# mv /etc/localtime /etc/localtime.bak

[root@test ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

[root@test ~]# date

修改后的时间:

2012年 09月 15日 星期六 18:25:00 CST

 

 

1 确认时区是否为shanghai

[root@xxx ~]# ll /etc/localtime
lrwxrwxrwx 1 root root 35 Jul 27  2018 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai

如果不正确,手动修改时区:
[root@xxx ~]# timedatectl set-timezone Asia/Shanghai
或者:
[root@xxx ~]# ln -sf /usr/share/zoneinfo/Universal /etc/localtime

2 检查本地时间与硬件时间

[root@xxx ~]# timedatectl
      Local time: Fri 2018-07-27 00:54:04 CST    本地时间为CST
  Universal time: Thu 2018-07-26 16:54:04 UTC    UTC时间
        RTC time: Thu 2018-07-26 16:54:04        硬件时间默认使用UTC时间
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

3 修改本地时间

[root@xxx ~]# date -s '-8hour'
Thu Jul 26 16:54:30 CST 2018

4 将本地时间写入硬件时间并重新检查

[root@xxx ~]# hwclock -w
[root@xxx ~]# timedatectl
      Local time: Thu 2018-07-26 16:55:11 CST
  Universal time: Thu 2018-07-26 08:55:11 UTC
        RTC time: Thu 2018-07-26 08:55:11
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a




CentOS 7解决系统时间相关问题

2018年04月09日 15:30:38 roguestudys 阅读数 820

 

 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/RogueStudys/article/details/79867299

方法一:
Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。
查看系统时间的命令: #date
设置系统时间的命令: #date –set “18/01/10 15:15”
查看硬件时间的命令: # hwclock
设置硬件时间的命令: # hwclock –set –date = (月/日/年 时:分:秒)


或者用同步网络时间
1.安装ntpdate工具


# yum -y install ntp ntpdate
2.设置系统时间与网络时间同步


# ntpdate cn.pool.ntp.org
3.将系统时间写入硬件时间


# hwclock --systohc


4.强制系统时间写入CMOS中防止重启失效
  hwclock -w
  或clock -w


方法二:
1.查看当前时间
输入命令:timedatectl
显示如下:
[root@HIK-ACloud logs]# timedatectl
      Local time: Mon 2018-04-09 15:12:14 CST
  Universal time: Mon 2018-04-09 07:12:14 UTC
        RTC time: Mon 2018-04-09 07:12:14
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a


Local 本地时间
RTC   硬件时间
Timezone 时区


2.设置时区
timedatectl set-timezone Asia/Shanghai
或者
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp命令覆盖/etc/localtime时间无法解决


3.是否NTP服务器同步
timedatectl set-ntp yes //yes或者no


4.将硬件时钟调整为与本地时钟一致
timedatectl set-local-rtc 1


硬件时钟默认使用UTC时间,因为硬件时钟不能保存时区和夏令时调整,修改后就无法从硬件时钟中读取出准确标准时间,因此不建议修改。修改后系统会出现下面的警告。


Warning: The RTC is configured to maintain time in the local timezone. This
         mode is not fully supported and will create various problems with time
         zone changes and daylight saving adjustments. If at all possible use
         RTC in UTC, by calling 'timedatectl set-local-rtc 0'。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值