NTP客户端
检查是否安装ntp软件
[root@localhost ~]# rpm -q ntp
ntp-4.2.6p5-19.el7.CentOS.3.x86_64
如果没有安装执行下面语句安装
[root@localhost ~]# yum -y install ntp
[root@localhost ~]# systemctl enable ntpd
[root@localhost ~]# systemctl start ntpd
设置时区(Timezone)
先看下当前时区
[root@localhost ~]# timedatectl
Local time: Mon 2024-04-29 01:00:41 EDT
Universal time: Mon 2024-04-29 05:00:41 UTC
RTC time: Mon 2024-04-29 05:00:41
Time zone: America/New_York (EDT, -0400)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sun 2024-03-10 01:59:59 EST
Sun 2024-03-10 03:00:00 EDT
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2024-11-03 01:59:59 EDT
Sun 2024-11-03 01:00:00 EST
查看系统支持的时区
[root@localhost ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
我们帮时区配置成Asia/Shanghai
[root@localhost ~]# sudo timedatectl set-timezone Asia/Shanghai
[root@localhost ~]# timedatectl
Local time: Mon 2024-04-29 13:01:52 CST
Universal time: Mon 2024-04-29 05:01:52 UTC
RTC time: Mon 2024-04-29 05:01:52
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
参考资料:
https://cloud.tencent.com/developer/article/1401342
https://linuxize.com/post/how-to-set-or-change-timezone-on-centos-7