在 CentOS 中通过 PTP 协议配置时间同步

要在 CentOS 中通过 PTP 配置时间同步:

  1. 打开操作系统控制台。
  2. 检查 linuxptp 包是否已安装。为此,请输入以下命令:

    dnf list installed

  3. 如果未安装 linuxptp 包,请输入以下命令添加该包并启用 ptp4l 时间同步服务:

    sudo dnf install linuxptp
    sudo systemctl enable ptp4l
    sudo systemctl start ptp4l

  4. 打开服务配置文件。为此,请输入以下命令:

    sudo mcedit /etc/ptp4l.conf

  5. 对于 slaveOnly 参数,输入 1
  6. 保存并关闭配置文件。
  7. 打开包含服务常规设置的文件。为此,请输入以下命令:

    sudo mcedit /etc/sysconfig/ptp4l

  8. OPTIONS 字符串中,指定参数如下:

    OPTIONS="-f <配置文件> -i <接口名称> -S -s"

    其中:

    • -f <配置文件> – 配置文件的默认名称和完整路径。
    • -i <接口名称> – 用于时间同步的网络接口的名称。
    • -S – 允许使用基于软件的时间戳。如果您想使用基于硬件的时间戳,可以跳过此参数。但是,首先要确保部件支持此功能。
    • -s – 启用下属时间同步。

    示例 OPTIONS 字符串:

    OPTIONS="-f /etc/ptp4l.conf -i eth0 -S -s"

  9. 保存并关闭常规设置文件。
  10. 允许防火墙使用端口 319 和 320 来运行 UDP 协议。为此,请输入以下命令:

    sudo firewall-cmd --permanent --add-port=319/udp
    sudo firewall-cmd --permanent --add-port=320/udp

  11. 重新启动防火墙服务。为此,请输入以下命令:

    sudo systemctl restart firewalld

  12. 重新启动时间同步服务。为此,请输入以下命令:

    sudo systemctl restart ptp4l

页首