centos下时区的查看及设置,以及配置自动更新时间

person 蓝猫    watch_later 2024-04-19 18:03:23
visibility 23    class centos,timezone,ntp    bookmark 分享

在 CentOS 中,时区的设置对于服务器的运行非常重要。本文将介绍如何查看当前 CentOS 系统的时区设置,并展示如何修改时区设置。

查看当前时区设置

  1. 使用以下命令查看当前时区设置:

    timedatectl
    timedatectl | grep 'Time zone'
    
  2. 输出中的 Time zone 行将显示当前时区。

修改时区设置

  1. 使用以下命令列出所有可用的时区:

    timedatectl list-timezones
    
  2. 选择一个新的时区,并使用以下命令将其应用到系统中。例如,将时区设置为 "Asia/Shanghai":

    sudo timedatectl set-timezone Asia/Shanghai
    
  3. 验证新时区设置是否生效:

    timedatectl
    
  4. 重启系统以确保时区更改生效:

    sudo reboot
    

自动同步时间

  1. 启用 NTP(Network Time Protocol)以自动同步系统时间:

    sudo yum install -y chrony
    sudo systemctl start chronyd
    sudo systemctl enable chronyd
    
  2. 验证 NTP 是否正常运行:

    chronyc sources -v
    
  3. 如果你使用的是防火墙,确保允许 NTP 流量通过:

    sudo firewall-cmd --add-service=ntp --permanent
    sudo firewall-cmd --reload
    

这样,你就可以在 CentOS 中查看和修改时区设置,并确保系统时间与所选时区保持同步。

评论区
评论列表
作者信息

蓝猫

还记得当初年少的我吗


热门分享