查看当前系统时间和NTP是否启用:
[root@localhost ~]# timedatectl
Local time: Tue 2019-05-28 19:59:48 PDT
Universal time: Wed 2019-05-29 02:59:48 UTC
RTC time: Wed 2019-05-29 02:59:48
Time zone: America/Los_Angeles (PDT, -0700)
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 PST
Sun 2019-03-10 03:00:00 PDT
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2019-11-03 01:59:59 PDT
Sun 2019-11-03 01:00:00 PST
查看时区列表:
[root@localhost ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
......
设置时区:
[root@localhost ~]# timedatectl set-timezone Asia/Hong_Kong
取消NTP:
[root@localhost ~]# timedatectl set-ntp no
[root@localhost ~]# timedatectl status
Local time: Wed 2019-05-29 11:10:14 HKT
Universal time: Wed 2019-05-29 03:10:14 UTC
RTC time: Wed 2019-05-29 03:10:14
Time zone: Asia/Hong_Kong (HKT, +0800)
NTP enabled: no
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
启用NTP:
[root@localhost ~]# timedatectl set -ntp yes
NTP服务:
[root@localhost /]# systemctl status chronyd
NTP配置文件:
[root@localhost /]# less /etc/chrony.conf
NTP启用状态下无法设置系统时间:
[root@localhost /]# timedatectl set-time "2019-05-29 11:40:00"
Failed to set time: Automatic time synchronization is enabled
[root@localhost /]#
禁用NTP后可以修改系统时间:
[root@localhost /]# timedatectl set-ntp no
[root@localhost /]# timedatectl set-time "2019-05-29 11:40:00"
[root@localhost /]# timedatectl status
Local time: Wed 2019-05-29 11:40:07 HKT
Universal time: Wed 2019-05-29 03:40:07 UTC
RTC time: Wed 2019-05-29 03:40:07
Time zone: Asia/Hong_Kong (HKT, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@localhost /]#