确保在 CentOS 7 系统上启用 NTP (Network Time Protocol) 服务。可以通过执行以下命令来实现:
systemctl start ntpd
systemctl enable ntpd
编辑 NTP 配置文件 /etc/ntp.conf
,根据需要设置时间服务器的 IP 地址或域名,并调整其他选项。例如:
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
确保 NTP 服务具有适当的权限,可以通过以下命令进行设置:
firewall-cmd --permanent --add-service=ntp
firewall-cmd --reload
这将在防火墙中开放 NTP 端口,允许其他主机访问时间服务器。
定期检查 NTP 服务的运行状态和同步情况,可以使用以下命令:
systemctl status ntpd
ntpq -p
确保时间服务器能够正确同步时间,并与其他时间源保持一致。