[root@test2 ~]# date #检查系统时间是否和当前时间一致
2024年 04月 01日 星期一 10:34:49 CST
[root@test2 ~]# yum -y install ntpdate ntpdate命令是用来设置本地日期和时间
[root@test2 ~]# tzselect #设置时区,选择Asia→China→Beijing Time→Yes(即5、9、1、1序号)
...
You can make this change permanent for yourself by appending the line TZ='Asia/Shanghai'; export TZ to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai #看到这个说明设置时区成功
[root@test2 ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: "/usr/share/zoneinfo/Asia/Shanghai" 与"/etc/localtime" 为同一文件
[root@test2 ~]# ntpdate cn.pool.ntp.org #http://cn.pool.ntp.org是位于中国的公共NTP服务器
5 Apr 17:19:18 ntpdate[39500]: step time server 84.16.67.12 offset 368881.951125 sec
[root@test2 ~]# hwclock -w #或hwclock-systohc,将系统时钟同步到硬件时钟
[root@test2 ~]# date #再次验证
2024年 04月 05日 星期五 17:13:27 CST