为什么我不应该使用 timedatectl 来设置时区

Why shouldn't I use timedatectl to set the timezone

当我使用 timedatectl 设置时区时,它发生了

[root@localhost ~]# timedatectl set-timezone "America/New_York"
Failed to set time zone: Access denied

这是我的主机信息

Static hostname: rolin
Icon name: computer-vm
Chassis: vm
Machine ID: 699591c5339c2ae6d7e7b25151eaa987
Boot ID: 40dc52c07c85444c9514f7d92a24448e
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.18.2.el7.x86_64
Architecture: x86-64

我现在可以做什么?

我发现我的 /etc/localtime 不是指向 /usr/share/zoneinfo/... 的符号链接。

所以我像这样更改了那个文件,它有效:

lrwxrwxrwx. /etc/localtime ->../usr/share/zoneinfo/Asia/Shanghai

我使用此命令更改我的 vicidial 服务器的时区 os 7 :

rm /etc/localtime

rm: 删除常规文件 `/etc/localtime'

ln -s /usr/share/zoneinfo/Europe/Rome localtime

日期 你会看到它已经改变了。

此问题的根本原因可能是 SELinux 标签问题。修复方法是重新标记 /etc 目录:

restorecon -Rv /etc

然后重新运行 timedatectl 命令。

来源:https://access.redhat.com/solutions/3366211(link 需要 RedHat 登录)。

或者,如果由于某种原因您不能这样做,作为一种解决方法,您可以暂时将 SELinux 设置为宽容模式,更新时区,然后重新启用 SELinux。

但是,第二种方法无法解决根本问题。 /etc 中的错误标签很可能会导致其他问题。