1. 系统环境
Oracle Linux Server 7.5
2. 将系统时区改为上海时区(即CST时区)
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
~]# date
Fri Sep 13 12:48:43 EDT 2019
~]# time
time timedatectl timeout times
[root@lzudb ~]# timedatectl
Local time: Fri 2019-09-13 12:49:04 EDT
Universal time: Fri 2019-09-13 16:49:04 UTC
RTC time: Fri 2019-09-13 16:49:04
Time zone: America/New_York (EDT, -0400)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sun 2019-03-10 01:59:59 EST
Sun 2019-03-10 03:00:00 EDT
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2019-11-03 01:59:59 EDT
Sun 2019-11-03 01:00:00 EST
~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
~]# date
Sat Sep 14 00:51:02 CST 2019
~]# date
Sat Sep 14 00:51:06 CST 2019
~]# timedatectl
Local time: Sat 2019-09-14 00:51:47 CST
Universal time: Fri 2019-09-13 16:51:47 UTC
RTC time: Fri 2019-09-13 16:51:47
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
此时虽然系统时间更新了,但是日志中记录的时间还是旧时区时间,最好重新启动一下服务器。
另外在RHEL7中有命令:timedatectl
# timedatectl list-timezones |grep Shanghai #查找中国时区的完整名称
Asia/Shanghai
# timedatectl set-timezone Asia/Shanghai #其他时区以此类推
3. 相关的命令
# 查看日期时间、时区及 NTP 状态
timedatectl
# 查看时区列表
timedatectl list-timezones
timedatectl list-timezones | grep -E "Asia/S.*"
# 修改时区
timedatectl set-timezone Asia/Shanghai
# 修改日期时间(可以只修改其中一个)
timedatectl set-time "2019-09-19 15:50:20"
# 开启 NTP
timedatectl set-ntp true/flase