centos7搭建ntp同步服務,配置服務端和客戶端

ntp服務器的搭建和客戶端的配置

1) 查看是否已經安裝ntp
[命令]  rpm -qa | grep ntp
若只有ntpdate而未見ntp,則需刪除原有ntpdate。如:
ntpdate-4.2.6p5-22.el7_0.x86_64
fontpackages-filesystem-1.44-8.el7.noarch
python-ntplib-0.3.2-1.el7.noarch

2) 刪除已安裝的ntp

[命令] yum erase ntp ntpdate

3) 重新安裝ntp

[命令] yum -y install ntp

服務端的配置:

[命令] vi /etc/ntp.conf

除了如下需要按自己需求改動外,其他的不需要修改
# 1. 先處理權限方面的問題,包括放行上層服務器以及開放局域網用戶來源:
restrict default kod nomodify notrap nopeer noquery     <==拒絕 IPv4 的用戶
restrict -6 default kod nomodify notrap nopeer noquery  <==拒絕 IPv6 的用戶
restrict 220.130.158.71   <==放行 tock.stdtime.gov.tw 進入本 NTP 的服務器
restrict 59.124.196.83    <==放行 tick.stdtime.gov.tw 進入本 NTP 的服務器
restrict 59.124.196.84    <==放行 time.stdtime.gov.tw 進入本 NTP 的服務器
restrict 127.0.0.1        <==底下兩個是默認值,放行本機來源
restrict -6 ::1
restrict 192.168.100.0 mask 255.255.255.0 nomodify <==放行局域網用戶來源,或者列出單獨IP

# 2. 設定主機來源,請先將原本的 [0|1|2].centos.pool.ntp.org 的設定批註掉:
server 0.centos.pool.ntp.org iburst     <==以這部主機爲最優先的server
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

# 3.預設時間差異分析檔案與暫不用到的 keys 等,不需要更動它:
driftfile /var/lib/ntp/drift
keys      /etc/ntp/keys

啓動ntp服務、查看狀態

1)啓動ntp服務

【命令】service ntpd start

 

2)查看ntp服務器有無和上層ntp連通

【命令】ntpstat

查看ntp狀態時,可能會出現如下所示情況

① unsynchronised time server re-starting polling server every 8 s

② unsynchronised polling server every 8 s

這種情況屬於正常,ntp服務器配置完畢後,需要等待5-10分鐘才能與/etc/ntp.conf中配置的標準時間進行同步。

等一段時間之後,再次使用ntpstat命令查看狀態,就會變成如下正常結果:

 

3)查看ntp服務器與上層ntp的狀態

【命令】ntpq -p

客戶端的配置:

[命令] vi /etc/ntp.conf
    註釋掉
    #server 0.rhel.pool.ntp.org
    #server 1.rhel.pool.ntp.org
    #server 2.rhel.pool.ntp.org

    修改
    server  127.127.1.0 # local clock
    fudge   127.127.1.0 stratum 10
    server  210.72.145.44   # 這個ip寫自己的ntp服務器ip
    fudge   210.72.145.44 stratum 10

    添加
    ntpd_enable="YES"

    啓動服務
    service ntpd restart
      chkconfig ntpd on

    可以使用的命令
    ntpq -p
    ntpstat

    四)設置開機啓動
    [命令]chkconfig ntpd on

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