linux 时间处理(差8小时)

一、同步时间

运行ntpdate ntp1.aliyun.com命令同步时间

# 将 `ntpdate ntp1.aliyun.com` 加入以下文件的底部,实现开机自动同步。
vi /etc/rc.d/rc.local

# 赋予执行权限
chmod +x /etc/rc.d/rc.local

二、解决相差8小时

CST应该是指(China Shanghai Time,东八区时间)
UTC应该是指(Coordinated Universal Time,标准时间)
所以,这2个时间实际上应该相差8个小时。

1、查看时间信息

[root@hub ~]# timedatectl
Warning: Ignoring the TZ variable. Reading the system's time zone setting only.

      Local time: Thu 2022-02-17 18:38:37 CST
  Universal time: Thu 2022-02-17 10:38:37 UTC
        RTC time: Thu 2022-02-17 10:38:37
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@hub ~]# date
Thu Feb 17 10:40:38 CST 2022
[root@hub ~]# date
Thu Feb 17 10:40:40 CST 2022

2、改硬件时间

hwclock --show 查看硬件的时间
hwclock --set --date '2020-05-20 10:10:00' 设置硬件时间
hwclock --hctosys 设置系统时间和硬件时间同步
hwclock -s  让系统时间和硬件时间保持一致

3、改系统时间

再改系统时间,上一步搞定的话,这里也可以不设置

date -s '10:10:00'

4、重设系统时区

(1)方法一

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' >/etc/timezone
#jenkins时需要使用root用户权限
docker exec -u root -it jenkins /bin/bash

(2)方法二

# 在/etc/profile文件中增加一行
export TZ='CST-8'
# 使文件立即生效
source /etc/profile 或者 . /etc/profile

5、再次查看时间

[root@hub ~]# timedatectl
Warning: Ignoring the TZ variable. Reading the system's time zone setting only.

      Local time: Thu 2022-02-17 10:51:18 CST
  Universal time: Thu 2022-02-17 02:51:18 UTC
        RTC time: Thu 2022-02-17 02:51:18
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

三、vmware 相差8小时

如果linux系统是在vmware虚拟机中,并且上面的设置不生效,则继续按下方的步骤进行设置。
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值