在 CentOS 中,时区的设置对于服务器的运行非常重要。本文将介绍如何查看当前 CentOS 系统的时区设置,并展示如何修改时区设置。
使用以下命令查看当前时区设置:
timedatectl
timedatectl | grep 'Time zone'
输出中的 Time zone
行将显示当前时区。
使用以下命令列出所有可用的时区:
timedatectl list-timezones
选择一个新的时区,并使用以下命令将其应用到系统中。例如,将时区设置为 "Asia/Shanghai":
sudo timedatectl set-timezone Asia/Shanghai
验证新时区设置是否生效:
timedatectl
重启系统以确保时区更改生效:
sudo reboot
启用 NTP(Network Time Protocol)以自动同步系统时间:
sudo yum install -y chrony
sudo systemctl start chronyd
sudo systemctl enable chronyd
验证 NTP 是否正常运行:
chronyc sources -v
如果你使用的是防火墙,确保允许 NTP 流量通过:
sudo firewall-cmd --add-service=ntp --permanent
sudo firewall-cmd --reload
这样,你就可以在 CentOS 中查看和修改时区设置,并确保系统时间与所选时区保持同步。