1、timedatectl查看时间各种状态:
Local time: 三 2021-04-21 00:01:05 CST
Universal time: 二 2021-04-20 16:01:05 UTC
RTC time: 三 2021-04-21 00:01:05
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a
2、timedatectl list-timezones: 列出所有时区
3、timedatectl set-local-rtc 1 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间
4、timedatectl set-timezone Asia/Shanghai 设置系统时区为上海
5、设置时间
方式一、timedatectl set-time "2022-07-19 20:20:15"
方式二、 date -s “2022-07-19 20:20:15”
6.校准时间
6.1.在集群中所有节点上安装ntp
yum install ntp
6.2.所有节点设置时区,这里设置为中国所用时间timedatectl set-timezone Asia/Shanghai
6.3.在server节点上启动ntp服务
systemctl start ntpd
systemctl enable ntpd
6.4.#通过阿里云时间服务器校准时间
ntpdate ntp1.aliyun.com
6.5.所有节点启动时间同步
timedatectl set-ntp yes
设置完后,具体如下
Local time: 二 2021-04-20 16:29:43 CST
Universal time: 二 2021-04-20 08:29:43 UTC
RTC time: 二 2021-04-20 08:29:42
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
同步阿里云时间
ntpdate ntp.aliyun.com
7、设置24小时制
使用tzselect命令选择时区(永久生效)
使用tzselect命令选择时区,根据提示选择5 -> 9 -> 1 -> 1 -> ok
查看软连接是否正常,如下是正确的
如果不是,根据下面步骤重建即可
rm /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime