在大多数基于 Unix 的服务器上(例如 Linux 服务器),可以使用 `ntp` 或 `chrony` 服务来实现时间同步。以下是在不同 Linux 发行版上开启和配置时间同步的通用方法。
使用 `chrony`(推荐)
1. 安装 `chrony`
如果没有安装 `chrony`,首先需要安装它。
对于 Debian/Ubuntu:
bash
sudo apt update
sudo apt install chrony
对于 RHEL/CentOS/Fedora:
bash
sudo yum install chrony
对于 openSUSE:
bash
sudo zypper install chrony
2. 启动并启用 `chrony` 服务
bash
sudo systemctl start chronyd
sudo systemctl enable chronyd
3. 验证时间同步状态
bash
chronyc tracking
使用 `ntp`
1. 安装 `ntp`
如果希望使用 `ntp`,可以按照以下步骤安装:
对于 Debian/Ubuntu:
bash
sudo apt update
sudo apt install ntp
对于 RHEL/CentOS:
bash
sudo yum install ntp
对于 Fedora:
bash
sudo dnf install ntp
2. 启动并启用 `ntpd` 服务
bash
sudo systemctl start ntpd
sudo systemctl enable ntpd
3. 验证时间同步状态
bash
ntpq -p
使用 `systemd-timesyncd`
在现代 Linux 发行版上,`systemd` 通常会自带一个轻量级的时间同步服务 `systemd-timesyncd`,它是更简单的替代方案。
1. 启动并启用 `systemd-timesyncd`
bash
sudo systemctl start systemd-timesyncd
sudo systemctl enable systemd-timesyncd
2. 验证时间同步状态
bash
timedatectl status
确认 `NTP synchronized` 状态为 `yes`。
根据你的具体需求和系统环境,选择一种合适的时间同步解决方案,并参考上述步骤来配置和启用时间同步。
查看详情
查看详情