[root@V3B01-zsy yum.repos.d]# date -s "2019-09-24 17:02:30"
2019年 09月 24日 星期二 17:02:30 CST
[root@V3B01-zsy yum.repos.d]# hwclock --show
2019年09月25日 星期三 01時01分42秒 -0.689057 秒
[root@V3B01-zsy yum.repos.d]# hwclock --set --date "2019-09-24 17:03:30"
[root@V3B01-zsy yum.repos.d]#
[root@V3B01-zsy yum.repos.d]# hwclock --show
2019年09月24日 星期二 17時03分35秒 -0.750970 秒
[root@V3B01-zsy yum.repos.d]# hwclock --hctosys
[root@V3B01-zsy yum.repos.d]# clock -w
[root@V3B01-zsy yum.repos.d]#
[root@V3B01-zsy yum.repos.d]# hwclock --show
2019年09月24日 星期二 17時04分02秒 -0.813435 秒
[root@V3B01-zsy yum.repos.d]#
[root@V3B01-zsy yum.repos.d]#
[root@V3B01-zsy yum.repos.d]# timedatectl
Local time: 二 2019-09-24 17:05:16 CST
Universal time: 二 2019-09-24 09:05:16 UTC
RTC time: 二 2019-09-24 17:03:51
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@V3B01-zsy yum.repos.d]# timedatectl set-local-rtc 1
[root@V3B01-zsy yum.repos.d]#
[root@V3B01-zsy yum.repos.d]#
[root@V3B01-zsy yum.repos.d]# timedatectl
Local time: 二 2019-09-24 17:06:03 CST
Universal time: 二 2019-09-24 09:06:03 UTC
RTC time: 二 2019-09-24 17:06:03
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a
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'.
[root@V3B01-zsy yum.repos.d]#
[root@V3B01-zsy yum.repos.d]# timedatectl set-timezone Asia/Shanghai
[root@V3B01-zsy yum.repos.d]#
[root@V3B01-zsy yum.repos.d]# hwclock --show
2019年09月24日 星期二 17時07分11秒 -0.407534 秒
[root@V3B01-zsy yum.repos.d]#
[root@V3B01-zsy yum.repos.d]# init 6
Last login: Wed Sep 25 00:57:21 2019 from 172.16.52.201
[root@V3B01-zsy ~]#
[root@V3B01-zsy ~]#
[root@V3B01-zsy ~]# date
2019年 09月 24日 星期二 17:13:09 CST
[root@V3B01-zsy ~]#
參考以下
安裝在虛擬機上的CentOS7的時間分為系統時間和硬件時間。二者都修改,重啟系統(init 6 )才會永久生效。
修改步驟如下
1.查看當前系統時間 date
2.修改當前系統時間 date -s "2018-2-22 19:10:30
3.查看硬件時間 hwclock --show
4.修改硬件時間 hwclock --set --date "2018-2-22 19:10:30"
5.同步系統時間和硬件時間 hwclock --hctosys
6.保存時鍾 clock -w
7.重啟系統(init 6)后便發現系統時間被修改了
時區的修改
yum -y install ntp [root@localhost kevin]# systemctl enable ntpd
systemctl start ntpd
ntpdate us.pool.ntp.org
Linux 系統(我特指發行版, 沒說內核) 下大部分軟件的風格就是不會仔細去考慮向后 的兼容性, 比如你上個版本能用這種程序配置, 沒准到了下一個版本, 該程序已經不見了. 比如 sysvinit 這種東西.
設置時區同樣, 在 CentOS 7 中, 引入了一個叫 timedatectl 的設置設置程序.
用法很簡單:
# timedatectl # 查看系統時間方面的各種狀態
Local time: 四 2014-12-25 10:52:10 CST
Universal time: 四 2014-12-25 02:52:10 UTC
RTC time: 四 2014-12-25 02:52:10
Timezone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
# timedatectl list-timezones # 列出所有時區
# timedatectl set-local-rtc 1 # 將硬件時鍾調整為與本地時鍾一致, 0 為設置為 UTC 時間
# timedatectl set-timezone Asia/Shanghai # 設置系統時區為上海
其實不考慮各個發行版的差異化, 從更底層出發的話, 修改時間時區比想象中要簡單:
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
reboot和init 6的區別
Linux中重啟的兩個命令:reboot和init 6之間的區別
init命令用於改變操作系統的運行級別。
Init 6是重新啟動機器。
reboot也是重新啟動機器。
那么這兩個命令到底有什么區別呢?
對這兩個操作使用man命令看到的內容如下:
"init 6" 基於一系列/etc/inittab文件,並且每個應用都會有一個相應shutdown腳本。
'init 6' 調用一系列shutdown腳本(/etc/rc0.d/K*)來使系統優雅關機;
'reboot'並不執行這些過程,reboot更是一個kernel級別的命令,不對應用使用shutdown腳本。 .
我們應該在通常情況下使用 init 6.
reboot - reboot performs a sync(1M) operation on the disks, and then a
multi- user reboot is initiated. See init(1M) for details.
init 6 Stop the operating system and reboot to the
state defined by the initdefault entry in
/etc/inittab.
在出問題的狀況下或強制重啟時使用reboot.