# 使用 chrony 自动同步时间的示例代码
# 1. 安装 chrony
sudo apt-get update
sudo apt-get install chrony
# 2. 配置 chrony
# 编辑 /etc/chrony/chrony.conf 文件,添加或修改如下内容:
# server ntp.example.com iburst # 替换为你的 NTP 服务器地址
# allow all # 允许所有主机同步时间(可选)
# 3. 重启 chrony 服务
sudo systemctl restart chronyd
# 4. 检查同步状态
chronyc sources -v
apt-get 安装 chrony,它是 Linux 系统中用于时间同步的工具。/etc/chrony/chrony.conf 文件,添加或修改 NTP 服务器地址。你可以根据需要选择不同的 NTP 服务器。chronyd 服务。chronyc sources -v 命令查看当前的时间同步状态。如果你不需要详细配置,也可以直接使用 ntpdate 或 timedatectl 进行简单的时间同步:
# 使用 ntpdate 同步时间
sudo ntpdate pool.ntp.org
# 使用 timedatectl 设置自动同步
sudo timedatectl set-ntp true
这两种方法更为简单,但功能相对较少。
上一篇:移动文件的linux命令
下一篇:linux暂停命令
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站