Centos系統時間和時區配置

一、時間配置(臨時配置和永久配置)
a.臨時配置:reboot後失效

[root@tmpt01 ~]# date -s "2018-12-20 16:34:11"
Thu Dec 20 16:34:11 CST 2018
[root@tmpt01 ~]# 
[root@tmpt01 ~]# 
[root@tmpt01 ~]# date
Thu Dec 20 16:34:13 CST 2018

b.永久配置
eg:實例

[root@tmpt01 ~]# hwclock --set --date "2018-12-20 16:37:30"
[root@tmpt01 ~]# hwclock --hctosys                  #系統時間和硬件中的時間計數器同步時間。
[root@tmpt01 ~]# clock -w                                #保存配置
[root@tmpt01 ~]# 
[root@tmpt01 ~]# 
[root@tmpt01 ~]# date               
Thu Dec 20 16:38:01 CST 2018
[root@tmpt01 ~]# hwclock --show
Thu 20 Dec 2018 04:38:11 PM CST  -0.282644 seconds

爲什麼要使用clock --set 配置

[root@tmpt01 ~]# date -s "2018-12-20 16:41:00"
Thu Dec 20 16:41:00 CST 2018
[root@tmpt01 ~]# 
[root@tmpt01 ~]# hwclock --show                 #實際硬件時間沒有保存,如果reboot機器那麼重啓後系統時間爲硬件的中的時間(所以修改系統最好用hwclock --set的方法)
Thu 20 Dec 2018 04:39:39 PM CST  -0.892401 seconds
[root@tmpt01 ~]# 

二、Centos時區配置:
查看系統的時區

[root@tmpt01 ~]$ timedatectl 
      Local time: Thu 2018-12-20 16:27:56 CST
  Universal time: Thu 2018-12-20 08:27:56 UTC
        RTC time: Thu 2018-12-20 16:27:56
       *Time zone: Asia/Shanghai (CST, +0800)*
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: yes
      DST active: n/a

修改時區(修改後永久生效,reboot後也生效)

[root@tmpt01 ~]# timedatectl set-timezone Asia/Dubai   #設置爲Dubai時區
[root@tmpt01 ~]# timedatectl 
      Local time: Thu 2018-12-20 12:50:03 GST
  Universal time: Thu 2018-12-20 08:50:03 UTC
        RTC time: Thu 2018-12-20 12:50:04
       Time zone: Asia/Dubai (GST, +0400)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: yes
      DST active: n/a
[root@tmpt01 ~]# 
[root@tmpt01 ~]# timedatectl set-timezone Asia/Shanghai      # #設置爲Shanghai時區
[root@tmpt01 ~]# 
[root@tmpt01 ~]# timedatectl 
      Local time: Thu 2018-12-20 16:50:17 CST
  Universal time: Thu 2018-12-20 08:50:17 UTC
        RTC time: Thu 2018-12-20 16:50:17
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: yes
      DST active: n/a

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章