zoukankan      html  css  js  c++  java
  • 时间同步 ntp

    1 使用ntp同步时间

    1.1 如果开启了ntp服务,使用ntpsta查看同步状态

    1.2 如果不使用用ntp服务,使用ntpdate -u ntp.aliyun.com 直接同步时间

    echo "*/20 * * * * /usr/sbin/ntpdate -u ntp1.aliyun.com >/dev/null &" >> /var/spool/cron/root


    2 时间同步ntp包相关信息

    2.1 包名

    # dnf -y install ntp ntpdate
     -- ntp-4.2.6p5-29.el7.centos.2.x86_64   # ntp服务包
     -- ntpdate-4.2.6p5-29.el7.centos.2.x86_64   # 手动同步使用包,可不安装
     
    

    2.2 相关配置查看

    # rpm -ql ntp-4.2.6p5-29.el7.centos.2.x86_64
    /etc/dhcp/dhclient.d
    /etc/dhcp/dhclient.d/ntp.sh
    /etc/ntp.conf
    /etc/ntp/crypto
    /etc/ntp/crypto/pw
    /etc/sysconfig/ntpd
    /usr/bin/ntpstat
    /usr/lib/systemd/ntp-units.d/60-ntpd.list
    /usr/lib/systemd/system/ntpd.service
    /usr/sbin/ntp-keygen
    /usr/sbin/ntpd
    /usr/sbin/ntpdc
    /usr/sbin/ntpq
    /usr/sbin/ntptime
    /usr/sbin/tickadj
    /usr/share/doc/ntp-4.2.6p5
    ...
    
    
    -- # cat /etc/ntp.conf
    # For more information about this file, see the man pages
    # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
    
    driftfile /var/lib/ntp/drift
    
    # Permit time synchronization with our time source, but do not
    # permit the source to query or modify the service on this system.
    restrict default nomodify notrap nopeer noquery
    
    # Permit all access over the loopback interface.  This could
    # be tightened as well, but to do so would effect some of
    # the administrative functions.
    restrict 127.0.0.1
    restrict ::1
    
    # Hosts on local network are less restricted.
    #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    
    # Use public servers from the pool.ntp.org project.
    # Please consider joining the pool (http://www.pool.ntp.org/join.html).
    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
    
    #broadcast 192.168.1.255 autokey        # broadcast server
    #broadcastclient                        # broadcast client
    #broadcast 224.0.1.1 autokey            # multicast server
    #multicastclient 224.0.1.1              # multicast client
    #manycastserver 239.255.254.254         # manycast server
    #manycastclient 239.255.254.254 autokey # manycast client
    
    # Enable public key cryptography.
    #crypto
    
    includefile /etc/ntp/crypto/pw
    
    # Key file containing the keys and key identifiers used when operating
    # with symmetric key cryptography.
    keys /etc/ntp/keys
    
    # Specify the key identifiers which are trusted.
    #trustedkey 4 8 42
    
    # Specify the key identifier to use with the ntpdc utility.
    #requestkey 8
    
    # Specify the key identifier to use with the ntpq utility.
    #controlkey 8
    
    # Enable writing of statistics records.
    #statistics clockstats cryptostats loopstats peerstats
    
    # Disable the monitoring facility to prevent amplification attacks using ntpdc
    # monlist command when default restrict does not include the noquery flag. See
    # CVE-2013-5211 for more details.
    # Note: Monitoring will not be disabled with the limited restriction flag.
    disable monitor
    

    2.3 使用ntp查看时间同步状态

    [0 root@centos7 /root]# timedatectl set-ntp true
    [0 root@centos7 /root]# timedatectl
          Local time: Fri 2020-05-20 09:13:18 CST
      Universal time: Fri 2020-05-20 01:13:18 UTC
            RTC time: Fri 2020-05-20 01:13:16
           Time zone: Asia/Shanghai (CST, +0800)
         NTP enabled: yes
    NTP synchronized: yes
     RTC in local TZ: no
          DST active: n/a
    [0 root@centos7 /root]# ntpstat
    synchronised to NTP server (162.159.200.123) at stratum 4
       time correct to within 1114 ms
       polling server every 64 s
    [0 root@centos7 /root]# ntpq -p
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    *time.cloudflare 10.40.9.201      3 u   12   64    1  293.152   14.088   1.622
     time.cloudflare 10.40.9.201      3 u   11   64    1  291.438   13.657   0.763
     electrode.felix 56.1.129.236     3 u   11   64    1  219.896  -10.669   1.720
     ntp7.flashdance 192.36.143.153   2 u   12   64    1  253.784   -8.469  33.159
    

    - PS

    阿里云NTP服务器

    image

  • 相关阅读:
    python爬虫练习5——新闻联播
    python爬虫练习4——腾讯视频评论提取
    python爬虫练习3——豆瓣电影
    python爬虫练习2——豆瓣读书
    python爬虫练习1——百度阅读榜
    微信小程序音频视频下载(fiddler抓包)
    4. Median of Two Sorted Arrays
    42.trapping-rain-water
    3.lengthOfLongestSubstring
    1.two sum
  • 原文地址:https://www.cnblogs.com/firewalld/p/14792389.html
Copyright © 2011-2022 走看看