• Linuxptp安装部署


    ptp介绍

            PTP(Precision Time Protocol)精确时间协议,由IEEE1588规定,用于同步网络中多台设备。

    ptp工作原理

            PTP时钟可以实现主时钟和从时钟功能,但是一个PTP通信子网内只能有一个主时钟。在系统的同步过程中,PTP主时钟提供时间同步及时间信息,从时钟接收主时钟发来的时间戳信息,系统根据此信息计算出主从线路时间延迟及主从时间差,并利用该时间差调整本地时间,从而使设备时间保持与主设备时间一致的频率和相位,实现频率同步和时间同步。

    ptp中的设备类型

            PTP作用的对象是时钟,主要分为全局主时钟(GrandMaster),主时钟(MasterClock),透明时钟(TransparentClock),边界时钟(BoundaryClock)和普通时钟(OrdinaryClock)。

    全局主时钟GM全局唯一,为PTP域中的所有设备提供时间基准。
    主时钟MCOC和BC的基准时钟称为主时钟。
    边界时钟 (BC)有多个端口连接到网络的时钟,一个slave端口连接到上游设备的PTP端口,其他的端口作为master连接到下游设备的slave端口。下游slave端口同构PTP协议直接同步于边界时钟,而不是直接和grandmaster通信。
    普通时钟OC只有一个端口(port)连接到网络的时钟,可以作为master或slave之一; 作为master时候,可以是 grandmaster,作为slave时候,一般作为时钟分发网络的端点设备(end,最后一级)。 
    透明时钟TC可以担负同步系统中信号分配器的角色。它拥有多个PTP端口,不需要像普通时钟和边界时钟一样与其他节点进行时间同步,仅负责在端口之间转发PTP报文时,对其进行转发延时校正(在PTP报文中增加时间校正信息)。

    linuxptp介绍

    在服务器上安装部署linuxptp就不做过多说明了,联网安装可执行下面的指令

    yum install -y linuxptp

    Linuxptp主要包含两个软件,一个是ptp4l,一个是phc2sys。作用分别如下

    • ptp4l:遵循IEEE 1588-2008标准文档规范,实现了BC(Boundary Clock)、OC(Ordinary Clock)和TC(Transparent Clock);
    • phc2sys:phc2sys是一个同步系统中两个或多个时钟的程序。通常,它用于将系统时钟与PTP硬件时钟(PHC)同步,该硬件时钟本身由ptp4l(8)程序同步;
    • pcm:在ptp4l运行期间对其进行配置。

    ptp4l指令详解

    1. [root@localhost ~]# ptp4l -h
    2. usage: ptp4l [options]
    3. Delay Mechanism
    4. -A Auto, starting with E2E
    5. -E E2E, delay request-response (default)
    6. -P P2P, peer delay mechanism
    7. Network Transport
    8. -2 IEEE 802.3
    9. -4 UDP IPV4 (default)
    10. -6 UDP IPV6
    11. Time Stamping
    12. -H HARDWARE (default)
    13. -S SOFTWARE
    14. -L LEGACY HW
    15. Other Options
    16. -f [file] read configuration from 'file'
    17. -i [dev] interface device to use, for example 'eth0'
    18. (may be specified multiple times)
    19. -p [dev] PTP hardware clock device to use, default auto
    20. (ignored for SOFTWARE/LEGACY HW time stamping)
    21. -s slave only mode (overrides configuration file)
    22. -t transparent clock
    23. -l [num] set the logging level to 'num'
    24. -m print messages to stdout
    25. -q do not print messages to the syslog
    26. -v prints the software version and exits
    27. -h prints this message and exits

    phc2sys指令详解

    1. [root@localhost ~]# phc2sys
    2. autoconfiguration or valid source clock must be selected.
    3. usage: phc2sys [options]
    4. automatic configuration:
    5. -a turn on autoconfiguration
    6. -r synchronize system (realtime) clock
    7. repeat -r to consider it also as a time source
    8. manual configuration:
    9. -c [dev|name] slave clock (CLOCK_REALTIME)
    10. -d [dev] master PPS device
    11. -s [dev|name] master clock
    12. -O [offset] slave-master time offset (0)
    13. -w wait for ptp4l
    14. common options:
    15. -f [file] configuration file
    16. -E [pi|linreg] clock servo (pi)
    17. -P [kp] proportional constant (0.7)
    18. -I [ki] integration constant (0.3)
    19. -S [step] step threshold (disabled)
    20. -F [step] step threshold only on start (0.00002)
    21. -R [rate] slave clock update rate in HZ (1.0)
    22. -N [num] number of master clock readings per update (5)
    23. -L [limit] sanity frequency limit in ppb (200000000)
    24. -M [num] NTP SHM segment number (0)
    25. -u [num] number of clock updates in summary stats (0)
    26. -n [num] domain number (0)
    27. -x apply leap seconds by servo instead of kernel
    28. -z [path] server address for UDS (/var/run/ptp4l)
    29. -l [num] set the logging level to 'num' (6)
    30. -t [tag] add tag to log messages
    31. -m print messages to stdout
    32. -q do not print messages to the syslog
    33. -v prints the software version and exits
    34. -h prints this message and exits

    检查网卡是否支持ptp硬件时钟,并确定时钟的设备名称

    命令

    ethtool -T p2p1

     可以看到p2p1占用的端口为/dev/ptp5

    C2模式下的server配置

    这时候server充当的角色是OC(slave角色),只接收ptp信号,Switch充当的角色是TC

     

    启动ptp4l进程

    /usr/sbin/ptp4l -2 -A -q -i p2p1 -f /etc/ptp4l.conf -s -m

    -2: IEEE 802.3协议

    -A: 自动选择延迟测量机制,运行时使用E2E,但接收到peer delay request报文后自动切换到P2P。

    -q: 不将信息发送到系统logger

    -i: 指定网口(PTP port),可以多次使用指定多个网口,但该选项或配置文件中至少要指定一个。

    -f: 指定配置文件,若没有指定,则使用默认配置。

    -s: slaveOnly模式

    -m: 将信息打印到标准输出

    启动phc2sys进程,同步系统时钟跟PHC时钟

    /usr/sbin/phc2sys -s /dev/ptp5 -c CLOCK_REALTIME -w -r -n 24 -m

    -s: 按设备(如/dev/ptp0)或接口(如eth0)或名称(如系统时钟的clock_REALTIME)指定主时钟(即ptp4l绑定的接口)

    -c: 按设备(如/dev/ptp1)或接口(如eth1)或名称指定从时钟。默认值CLOCK_REALTIME(系统时钟)

    -w: 等待直到ptp4l处于同步状态

    -r: 指示phc2sys也同步系统时钟(clock_REALTIME)

    -n: 指定ptp4l使用的域号。默认值为0

    -m: 将信息打印到标准输出

    C1模式下的server配置

    这时候server充当的角色是BC(既是slave又是master),网络中没有Switch。

    说明:

            p2p1从GM获取PTP,然后将PHC同步到系统时钟,充当的是slave角色;

            p3p2将p2p1中的信号从p3p2下发给RU,充当的是master的角色。

    slave配置

    /usr/sbin/ptp4l -2 -A -q -i p2p1 -f /etc/ptp4l.conf -s -m
    /usr/sbin/phc2sys -s /dev/ptp5 -c CLOCK_REALTIME -w -r -n 24 -m

    master配置

    获取p2p1跟p3p2设备

     启动进程

    /usr/sbin/ptp4l -2 -A -q -i p3p2 -f /etc/ptp4l_m.conf -m
    /usr/sbin/phc2sys -q -m -s /dev/ptp5 -c /dev/ptp3 -w -r -n 24

    配置BC是如果进程报错,按照错误时进行修改参数即可

    例如如下报错:

    在配置文件中修改tx_timestamp_timeout参数即可,将timeout值设置的大一点,单位是ms

    tx_timestamp_timeout: 等待发送时间戳的超时时间,单位ms

    配置文件参数含义

    参考:转载:linuxptp/ptp4l PTP时钟同步配置选项_小学生Yi的博客-CSDN博客_ptp4l

    配置选项描述默认值
    twoStepFlag两步时间戳模式,单步时间戳模式选择1
    slaveOnly绕过BMCA,使clock工作在slave模式0
    socket_priority报文优先级,0~15,只在L2协议下生效0
    gmCapable是否具有master能力,只对gPTP模式生效1
    priority1时钟priority1属性,0~255128
    priority2时钟priority2属性,0~255128
    clockClass时钟clockClass属性248
    clockAccuracy时钟clockAccuracy属性0xFE
    clockIdentity时钟clockIdentity属性,使用默认值则会在运行时自动生成000000.0000.000000
    offsetScaledLogVariance时钟offsetScaledLogVariance属性0xFFFF
    G.8275.defaultDS.localPriorityITU-T G.8275.1 and G.8275.2使用128
    maxStepsRemovedAnnounce报文的stepsRemoved值大于等于该值时,则不参与BMCA255
    domainNumberPTP域0
    utc_offsetTAI和UTC时间差37
    free_running不调整物理时钟0
    freq_est_interval评估本地时钟和对端时钟频率比值的时间间隔,时间间隔值为该值的2的次方。1(2秒)
    assume_two_step按两步报文的方式,处理单步报文0
    tc_spanning_tree透明时钟生成树模式,在PTP网络中,实现所有透明时钟内增加Announce报文的stepsRemoved值,和相应BMCA,可以避免环形PTP报文循环。0
    tx_timestamp_timeout等待发送时间戳的超时时间,单位ms1
    check_fup_sync检查sync,follow_up报文顺序0
    clock_servo时钟伺服器,可选择pi,ntpshm,nullfpi
    clock_type时钟类型,OC,BC,E2E_TC,P2P_TCOC
    pi_proportional_constpi算法选项0.0
    pi_integral_constpi算法选项0.0
    pi_proportional_scalepi算法选项0.0
    pi_proportional_exponentpi算法选项-0.3
    pi_proportional_norm_maxpi算法选项0.7
    pi_integral_scalepi算法选项0.0
    pi_integral_exponentpi算法选项0.4
    pi_integral_norm_maxpi算法选项0.3
    step_threshold步进时钟的阈值,超过阈值,直接调整时钟时间,单位秒0.0
    first_step_threshold第一次步进时钟的阈值,超过阈值,直接调整时钟时间,单位秒0.00002
    max_frequency最大频率调整值,单位ppb900000000 (90%)
    sanity_freq_limitPTP时钟和系统monotonic时钟频率偏差限制,单位ppb200000000 (20%)
    initial_delay链路延迟初始值,单位ns。设置为0的话,程序会先测量0
    ntpshm_segmentntpshm私服使用的SHM段的数目0
    udp6_scopeIPv6多播报文的范围,默认为全局范围0x0E
    uds_addressUNIX domain socket地址/var/run/ptp4l
    dscp_eventPTP事件报文使用的Differentiated Services Codepoint (DSCP),0~630
    dscp_generalPTP通用报文使用的Differentiated Services Codepoint (DSCP),0~630
    dataset_comparisonBMCA比较dataset的方法,可选择"ieee1588"或 “G.8275.x”ieee1588
    logging_levellog级别6 (LOG_INFO)
    message_tag可以添加到所有打印信息中空字符
    verbose打印消息到标准输出0
    use_syslog打印消息到系统日志1
    summary_interval打印统计信息时间间隔,时间间隔值为该值的2的次方。0(1秒)
    time_stamping时间戳类型,可选择hardware, software, legacy, onestep, 或p2p1stephardware
    productDescription时钟描述;;
    revisionData时钟描述;;
    userDescription时钟描述空字符
    manufacturerIdentity时钟描述00:00:00
    kernel_leaplinux内核闰秒1
    timeSource时钟类型0xA0
    hwts_filter硬件时间戳过滤器设置模式,可选择normal, check, fullnormal
    asCapable如果设置为true,就认为是gPTP设备,不再检查。auto
    BMCA最优时钟算法,可选择masterOnly,slaveOnly或ptpptp
    inhibit_announce禁止发送Annouce报文,需要使能ignore_source_id0
    ignore_source_id忽略sync和follow_up报文的source port id检查0
    msg_interval_request是否使能请求调整sync和peer delay request报文的发送间隔0
    servo_num_offset_values时间偏差值连续小于servo_offset_threshold的数目,达到这个数目伺服器进入stable状态10
    servo_offset_threshold时间偏差阈值0
    slave_event_monitorslave事件监测的UNIX domain socket地址空字符
    write_phase_mode使用PTP硬件写相位功能,代替调整频率偏差0

    5.3 单播发现选项

    配置选项描述
    table_idtable id,正数值
    logQueryInterval单播协商时间间隔,时间间隔值为该值的2的次方。
    peer_addressP2P单播地址
    L2|UDPv4|UDPv6传输协议

  • 相关阅读:
    20-SpringCloudAlibaba-3
    Linux Ubunto Nginx安装
    (计算机组成原理)第四章指令系统-第三节1:X86汇编语言基础
    Python3:@property属性装饰器
    酷开科技 | 酷开系统沉浸式大屏游戏更解压!
    如何用 Prometheus Operator 监控 K8s 集群外服务?
    2023最新最全【Python3.11.3】下载安装零基础教程【附安装包】
    Python 爬虫零基础:探索网络数据的神秘世界
    线代 | 目标120以上的综合提高题
    神经网络应用场景——自然语言处理
  • 原文地址:https://blog.csdn.net/weixin_43054437/article/details/126802722