CentOS7.0 安裝NTP服務器及思科交換機NTP同步

一、安裝環境:

    CentOS 7  Linux version 3.10.0-229.el7.x86_64

    ntp-4.2.6p5-19.el7.centos.x86_64

二、安裝及配置

    2.1 安裝

        NTP可以直接通過yum來安裝,使用 rpm -qa ntp可以查看是否已安裝ntp服務,如有安裝可使用yum install ntp 來升級,當然也可以不用升級。

        命令:

        yum install ntp  #安裝NTP服務器

    2.2 配置

        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

        restrict 192.168.30.0 mask 255.255.255.0 nomodify notrap #增加這一行,允許哪些IP 地址可以同步NTP服務器,也可以不用配置,默認所有網段


        # 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

        #默認配置,可以不用改動,在中國大陸會默認使用大陸的主NTP服務器,在香港就會使用香港的NTP服務器。當然也可以註釋上面四行,自己添加,如 server 0.210.72.145.44

        #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服務

        命令:

        systemctl start ntpd.service  開啓服務

        systemctl stop ntpd.service   停止服務

三、測試

    命令:

    ntpstat  #查看ntp服務器是否連通,啓動服務後需要三五分鐘後纔會連通

    ntpq -p #查看ntp服務器連接狀態

    netstat -tunlp | grep ntpd  #查看服務端口

    在另一臺linux上測試ntp同步是否可用

    命令:

    yum install ntpdate

    ntpdate 172.31.251.196

 

四、交換機同步

    配置命令:

    conf t

    ntp server 172.31.251.196

 



謝謝你打開這篇博文,並一直堅持看到了這裏,如果覺得對你有幫助,請不要吝嗇點一下右下角的贊。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章