NTP server 时间同步服务器搭建

落爺英雄遲暮 提交于 2019-12-02 11:46:52

#允许ntp通过防火墙
sudo ufw allow ntp

交叉编译ntp:
    --target=arm --build=arm

    ./configure --prefix=$PWD/install --exec-prefix=$PWD/install --host=arm-xilinx-linux-gnueabi CC=arm-xilinx-linux-gnueabi-gcc --with-yielding-select=yes --with-openssl-libdir=/home/linux/openssl-1.0.1f/install/lib --with-openssl-incdir=/home/linux/openssl-1.0.1f/install/include

    make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi-

 


交叉编译openssl:
    ./Configure linux-elf-arm -DB_ENDIAN arm:'arm-xilinx-linux-gnueabi-gcc' no-shared --prefix=/home/linux/openssl-1.0.1f/install
    make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi-

    
ubuntu获取软件包源码:
    #获取源码包
    sudo apt-get source pakege_name
    #解压所有的包,生成源码目录
    dpkg-source -x ***.dsc
    #获取依赖
    sudo apt-get build-dep xxx


定时任务:

    crontab -e * /1 * * * /usr/sbin/ntpdate 192.168.11.165 > /dev/null 2>&1
    service cron restart


    crontab -e * * * * * ntpdate 192.168.11.165 > /dev/null 2>&1
    service crond restart

    * * * * * ls / -l >log

    mkdir -p /var/spool/cron/crontabs

设置时间:
    date -s 2019.10.23-10:10:10


Task:

    board:                    ubuntu:
        server(ntpd)            client(ntpdate)        (完成)
        server(ntpd)            client(ntpd)        (完成)

        client(ntpdate)            server(ntpd)        (完成)
        client(ntpd)            server(ntpd)        (无法进行)
        client(ntpdate + crond)    server(ntpd)        (完成)

获取rtc时间:
    hwclock -w

FAQ:
    
    ntp客户端的时间大于ntp服务器的时间,客户端无法同步时间
    
    使用下面的配置时,ntp服务不能从别的服务器同步时间
    server  127.127.1.0  
    fudge   127.127.1.0 stratum 8

NOTE:

    交叉编译命令(依赖openssl,需要先交叉编译openssl)
            ./configure --prefix=$PWD/install --exec-prefix=$PWD/install --host=arm-xilinx-linux-gnueabi CC=arm-xilinx-linux-gnueabi-gcc --with-yielding-select=yes --with-openssl-libdir=/home/linux/openssl-1.0.1f/install/lib --with-openssl-incdir=/home/linux/openssl-1.0.1f/install/include

            make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi-

    板子上运行:
                运行ntp server时,当客户端与服务器时间相差太大时,可能会导致失败,应先使用ntpdate 同步本机时间后开启ntp server
                另外需要ntp.conf文件,在/etc目录下,同时在/etc目录下的services文件下新增一下两行内容,若没有services文件,则新建该文件
                            ntp    123/tcp
                            ntp    123/udp


                客户端运行ntpdate -u ip 或者ntpdate ip

    板子的文件系统:
                在/etc目录下,需要services和ntp.conf文件
                在/bin目录下放入编译好的ntpd和ntpdate


    板子上定时同步ntp服务器的时间:
                文件系统需要有/var/spool/cron/crontabs目录
                在该目录下新建root文件,文件内容如下:
                #每分钟执行一次
                * * * * * ntpdate 192.168.11.165 >&1
                

linux@ubuntu:~$ ntpq -p
     remote           refid      st                 t             when                             poll                     reach   delay   offset      jitter
============================================================================================================================================================
 192.168.11.165  LOCAL(0)        11                 u           11                               64                        3        0.583      -691911       0.616

服务器的ip地址    服务器的上层    服务器的上层层数    u:单播        上一次校正时间与现在时间的差    查询服务器的时间间隔            延时    时间偏移    
                                                    b:广播
                                                    i:本地


 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!