标签: 时间同步

  • Linux系统配置时区和时间同步服务的两种方法

    在 Linux 系统中,配置时区和启用时间同步服务可以通过不同的方式完成。下面我们将介绍两种常见的方法:一种使用传统命令,另一种使用 timedatectl 命令来进行配置。

    方法一:使用传统命令配置时区

    1. 配置时区为 Asia/Singapore

    你可以通过以下命令来设置时区:

    echo "Asia/Singapore" | tee /etc/timezone

    然后,将本地时间设置为 Asia/Singapore 时区:

    ln -sf /usr/share/zoneinfo/Asia/Singapore /etc/localtime
    1. 查看当前系统时间

    使用 date 命令查看系统时间,确保时区设置生效:

    date

    方法二:使用 timedatectl 配置时区

    1. 配置时区为 Asia/Singapore

    使用 timedatectl 直接设置时区:

    timedatectl set-timezone Asia/Singapore
    1. 查看当前系统时间

    使用 timedatectl 查看当前系统时区设置:

    timedatectl
    1. 安装并启动时间同步服务

    如果系统没有启用时间同步服务,可以通过以下命令来安装和启动 systemd-timesyncd 服务:

    apt install systemd-timesyncd
    systemctl start systemd-timesyncd
    systemctl status systemd-timesyncd
    1. 确认时间同步

    使用 timedatectl 再次查看同步状态:

    timedatectl