centos配置linuxptp

                                centos配置linuxptp

【参考文献】

redhad配置ptp https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/ch-configuring_ptp_using_ptp4l#s2-Advantages_of_PTP
ptp资料  https://events.static.linuxfound.org/sites/events/files/slides/lcjp14_ichikawa_0.pdf
linuxptp项目地址  http://linuxptp.sourceforge.net/
IEEE1588  http://blog.sina.com.cn/s/blog_4b0cdab70100k4fv.html
systemd服务使用  http://blog.csdn.net/wzyzzu/article/details/44171319
使用 linuxptp    https://doc.opensuse.org/documentation/leap/tuning/html/book.sle.tuning/cha.tuning.ptp.html
centos7之关于时间和日期以及时间同步的应用 https://www.cnblogs.com/lei0213/p/8723106.html

一、linuxptp安装

    1、yum直接安装:
        yum -y install linuxptp

    2、git下载源码安装:
        1) 安装git工具
            yum -y install git
        
        2) 下载linuxptp-code项目
            git clone https://git.code.sf.net/p/linuxptp/code linuxptp-code
        
        3) 进入下载的linuxptp-code目录
            cd linuxptp-code
        
        4)编译源代码,并安装到系统
            make
            make install

二、linuxptp使用

   
    ptp4l时钟同步主程序,phc2sys同步PHC时钟和系统时钟;


    ptp4l默认工作为master模式和硬件时间戳,使用-s可设置为slave模式。
    
    phc2sys使用 -a -rr为自动配置模式,-c设置slave时钟(CLOCK_REALTIME), -s 设置master时钟 , -w设置为等待ptp4l
    
    (以下命令需要使用root权限,使用yum直接安装的linuxptp为例)

    1、检查网卡的驱动支持情况

    ethtool -T eth0

    Time stamping parameters for eth0:
    Capabilities:
            hardware-transmit     (SOF_TIMESTAMPING_TX_HARDWARE)
            software-transmit     (SOF_TIMESTAMPING_TX_SOFTWARE)
            hardware-receive      (SOF_TIMESTAMPING_RX_HARDWARE)
            software-receive      (SOF_TIMESTAMPING_RX_SOFTWARE)
            software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
            hardware-raw-clock    (SOF_TIMESTAMPING_RAW_HARDWARE)
    PTP Hardware Clock: 0
    Hardware Transmit Timestamp Modes:
            off                   (HWTSTAMP_TX_OFF)
            on                    (HWTSTAMP_TX_ON)
    Hardware Receive Filter Modes:
            none                  (HWTSTAMP_FILTER_NONE)
            all                   (HWTSTAMP_FILTER_ALL)
            
    1) 硬件时间戳需要包括参数
        SOF_TIMESTAMPING_SOFTWARE
        SOF_TIMESTAMPING_TX_SOFTWARE
        SOF_TIMESTAMPING_RX_SOFTWARE
        
    2) 软件时间戳需要包括参数    
        SOF_TIMESTAMPING_RAW_HARDWARE
        SOF_TIMESTAMPING_TX_HARDWARE
        SOF_TIMESTAMPING_RX_HARDWARE
        
    2、ptp4l使用说明
        1) 参数说明
           参数:
               -i [dev] 网卡设备
               -m 输出消息
               -s 从时钟
               -S 软件时间戳
    
           硬件时间戳模式+主时钟
            ptp4l -i eth0 -m    
            
           硬件时间戳模式+从时钟
            ptp4l -i eth0 -m -s
    
           软件时间戳模式 + 主时钟
            ptp4l -i eth0 -m -S
    
           软件时间戳模式 +从时钟
            ptp4l -i eth0 -m -S -s


    2) 配置文件使用

        -f /etc/ptp4l.conf       
        -s 为slave 模式,默认为master模式

    3) 开机启动ptp4l

        a、修改/etc/sysconfig/ptp4l
        PTIONS="-f /etc/ptp4l.conf -i eth0 -s"
        
        b、启动ptp4l       
        systemctl start ptp4l
        
        c、设置开机启动        
        systemctl enable ptp4l


    3、pmc

        获取ptp4l运行信息 -b 0为本地ptp4l的运行信息
        pmc -u -b 0 'GET CURRENT_DATA_SET'
        pmc -u -b 0 'GET TIME_STATUS_NP'


    4、phc2sys
        1) phc2sys使用说明 
            -m 可输出消息
            -rr 作为时间源
            主时钟(硬件时间戳模式+软件时间戳模式)          
                自动配置系统时钟和PHC时钟的同步
                phc2sys -a -rr                
                系统时钟(ptp4l主时钟)同步到特定的PHC(网卡)时钟
                phc2sys -s CLOCK_REALTIME -c eth0 -w
           
            从时钟(硬件时间戳模式+软件时间戳模式)
                phc2sys -a -rr
                phc2sys -s eth0 -w
        2) 开机启动phc2sys
    
            a、修改/etc/sysconfig/phc2sys    
                PTIONS="-a -rr"
            
            b、启动ptp4l
                systemctl start phc2sys
    
            c、设置开机启动
                systemctl enable phc2sys
    5、 测试
        主时钟运行命令:
            phc2sys -s CLOCK_REALTIME -c eth0 -w (或-a -rr)
            ptp4l -i eth0 -m
             
        从时钟运行命令:
            phc2sys -c eth0 -w           (或-a -r)
            ptp4l -i eth0 -m -s
     
    6、配置例子
            (ethX 表示的是网卡名字 eth0 或者 enp0s31f6)
            EXAMPLE 1: SLAVE CLOCK USING SOFTWARE TIME STAMPING REPORT BUG 
            #/etc/sysconfig/ptp4l:           
            OPTIONS=”-f /etc/ptp4l.conf -i ethX”
            
            No changes made to the distribution /etc/ptp4l.conf.
            
            EXAMPLE 2: SLAVE CLOCK USING HARDWARE TIME STAMPING REPORT BUG 
            #/etc/sysconfig/ptp4l:          
            OPTIONS=”-f /etc/ptp4l.conf -i ethX”
            
            #/etc/sysconfig/phc2sys:            
            OPTIONS=”-s ethX -w”
            
            No changes made to the distribution /etc/ptp4l.conf.
            
            EXAMPLE 3: MASTER CLOCK USING HARDWARE TIME STAMPING REPORT BUG 
            #/etc/sysconfig/ptp4l:           
            OPTIONS=”-f /etc/ptp4l.conf -i ethX”
            
            #/etc/sysconfig/phc2sys:          
            OPTIONS=”-s CLOCK_REALTIME -c ethX -w”
            
            #/etc/ptp4l.conf:          
            priority1 127
            
            EXAMPLE 4: MASTER CLOCK USING SOFTWARE TIME STAMPING (NOT GENERALLY RECOMMENDED) REPORT BUG 
            #/etc/sysconfig/ptp4l:            
            OPTIONS=”-f /etc/ptp4l.conf -i ethX”
            
            #/etc/ptp4l.conf:            
            priority1 127
        
三、禁用NTP时间

    1、配置 /etc/ntp.conf
        server 127.127.1.0 
        fudge  127.127.1.0 stratum 0

    2、文件中/etc/sysconfig/network增加如下所示:
        PEERNTP=no

    3、ntpd服务关闭
        临时关闭
        service ntpd stop

        永久性关闭
        chkconfig ntpd off
        systemctl disable ntpd
        systemctl disable chronyd
        systemctl disable ntpdate


四、linux时间同步命令
    ntpdate us.pool.ntp.org 
    同时还有其他的服务器:
    1.cn.pool.ntp.org
    2.cn.pool.ntp.org
    3.cn.pool.ntp.org

你可能感兴趣的:(linux)