linux 时间处理(差8小时)

Linux文章/教程评论448阅读模式

一、同步时间

运行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、查看时间信息文章源自爱尚资源教程网-https://www.23jcw.net/1755.html

[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、改硬件时间文章源自爱尚资源教程网-https://www.23jcw.net/1755.html

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

3、改系统时间
再改系统时间,上一步搞定的话,这里也可以不设置文章源自爱尚资源教程网-https://www.23jcw.net/1755.html

date -s '10:10:00'

4、重设系统时区
(1)方法一文章源自爱尚资源教程网-https://www.23jcw.net/1755.html

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

(2)方法二文章源自爱尚资源教程网-https://www.23jcw.net/1755.html

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

5、再次查看时间文章源自爱尚资源教程网-https://www.23jcw.net/1755.html

[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虚拟机中,并且上面的设置不生效,则继续按下方的步骤进行设置。
linux 时间处理(差8小时)文章源自爱尚资源教程网-https://www.23jcw.net/1755.html 文章源自爱尚资源教程网-https://www.23jcw.net/1755.html

相关文章
版权声明:文章图片资源来源于网络,如有侵权,请留言删除!!!
  • 温馨提示:如遇到资源下载不了,或者文章没有解决你的问题的,可以联系我们帮你处理!!!
  • 转载请务必保留本文链接:https://www.23jcw.net/1755.html

发表评论