centos 设置时间同步
CentOS 可以通过 NTP(网络时间协议)来同步时间。可以按照以下步骤进行设置:
- 安装 ntpdate
在终端中输入以下命令:
sudo yum install ntpdate
- 配置 NTP 服务器
可以使用以下命令来查找可用的 NTP 服务器:
ntpdate -q 0.centos.pool.ntp.org
其中,0.centos.pool.ntp.org 是 NTP 服务器的地址,可以根据自己的位置和需求进行更改。
- 设置同步时间
可以使用以下命令来同步时间:
sudo ntpdate 0.centos.pool.ntp.org
其中,0.centos.pool.ntp.org 是 NTP 服务器的地址,可以根据自己的位置和需求进行更改。
- 设置定时同步
可以使用以下命令来设置 NTP 定时同步:
sudo crontab -e
在编辑器中添加以下内容:
*/5 * * * * /usr/sbin/ntpdate 0.centos.pool.ntp.org >/dev/null 2>&1
其中,0.centos.pool.ntp.org 是 NTP 服务器的地址,可以根据自己的位置和需求进行更改。这里设置的是每 5 分钟同步一次时间。
保存并退出编辑器。
- 重启 NTP 服务
可以使用以下命令来重启 NTP 服务:
sudo systemctl restart ntpd
至此,CentOS 的时间同步设置完成。
原文地址: https://www.cveoy.top/t/topic/IPt 著作权归作者所有。请勿转载和采集!