1. 程式人生 > >RHEL 7 NTP配置實驗

RHEL 7 NTP配置實驗

實驗 時間源 地址 進程 ntp服務 rhel emc conf zone

RHEL 7 NTP配置實驗

系統環境:
RHEL 7.3 (Maipo) 3.10.0-514.el7.x86_64
NTP Server IP:192.168.74.130
NTP Client IP: 192.168.74.131

一,使用傳統NTP服務進行配置
NTP Server和NTP Client上安裝
1、安裝NTP包:

# yum install -y ntp
# systemctl enable ntpd            ##開機啟用NTP服務
# systemctl start ntpd             ##啟動NTP服務

2、配置NTP時間同步文件:

NTP Server

#vi /etc/ntp.conf              ##添加時間源,如:
server  133.100.11.8
fudge   133.100.11.8 stratum 10
#ntpq -p                    ##查看時間同步進程
#ntpdate 133.100.11.8          ##手動同步
#date                         ##查看當前時間    

NTP Client

#vi /etc/ntp.conf                    ##添加時間源,如:
server  192.168.74.130
fudge   192.168
.74.130 stratum 10 #ntpq -p ##查看時間同步進程 #ntpdate 192.168.74.130 ##手動同步 #date

二,使用chrony服務進行配置
NTP Server和NTP Client上安裝
1、安裝chrony包:

#yum -y install chrony.x86_64
#systemctl enable chronyd.service    ##開機啟用chrony服務
#systemctl start chronyd.service    ##啟動chrony服務

2、配置NTP時間同步文件:
NTP Server

#vi /etc/chrony.conf			##添加時間源,如:
server  133.100.11.8              iburst
......
allow 192.168.74.131			##允許本地IP地址或網絡訪問本時鐘源
#systemctl restart chronyd.service	##重啟時間同步服務
#systemctl status chronyd.service	##查看時間同步狀態
#chronyc sources -v			##查看時間同步源
210 Number of sources = 1

  .-- Source mode  ‘^‘ = server, ‘=‘ = peer, ‘#‘ = local clock.
 / .- Source state ‘*‘ = current synced, ‘+‘ = combined , ‘-‘ = not combined,
| /   ‘?‘ = unreachable, ‘x‘ = time may be in error, ‘~‘ = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 133.100.11.8                  2   6    37    11   -110us[-3921us] +/-   92ms
註:帶*號表示時間已經同步完成

# chronyc sourcestats -v		##檢測上一級時鐘源狀態
210 Number of sources = 1
                             .- Number of sample points in measurement set.
                            /    .- Number of residual runs with same sign.
                           |    /    .- Length of measurement set (time).
                           |   |    /      .- Est. clock freq error (ppm).
                           |   |   |      /           .- Est. error in freq.
                           |   |   |     |           /         .- Est. offset.
                           |   |   |     |          |          |   On the -.
                           |   |   |     |          |          |   samples.                            |   |   |     |          |          |             |
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
133.100.11.8               11   7   525     -0.107     18.717  -3914ns  2252us

# timedatectl				##查看日期時間及NTP狀態
      Local time: Thu 2017-10-05 13:12:18 CST
  Universal time: Thu 2017-10-05 05:12:18 UTC
        RTC time: Thu 2017-10-05 05:12:18
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

NTP Client

#vi /etc/chrony.conf			##添加時間源,如:
server 192.168.74.130  iburst
#systemctl restart chronyd.service	##重啟時間同步服務
#systemctl status chronyd.service	##查看時間同步狀態
#chronyc sources -v			##查看時間同步源
210 Number of sources = 1

  .-- Source mode  ‘^‘ = server, ‘=‘ = peer, ‘#‘ = local clock.
 / .- Source state ‘*‘ = current synced, ‘+‘ = combined , ‘-‘ = not combined,
| /   ‘?‘ = unreachable, ‘x‘ = time may be in error, ‘~‘ = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.74.130                3   6    17     5    -42us[-1869us] +/-  102ms
註:帶*號表示時間已經同步完成

# chronyc sourcestats -v
210 Number of sources = 1
                             .- Number of sample points in measurement set.
                            /    .- Number of residual runs with same sign.
                           |    /    .- Length of measurement set (time).
                           |   |    /      .- Est. clock freq error (ppm).
                           |   |   |      /           .- Est. error in freq.
                           |   |   |     |           /         .- Est. offset.
                           |   |   |     |          |          |   On the -.
                           |   |   |     |          |          |   samples.                            |   |   |     |          |          |             |
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
192.168.74.130              6   4   135     -4.794    110.462   -206us  1596us

# timedatectl
      Local time: Thu 2017-10-05 14:06:35 CST
  Universal time: Thu 2017-10-05 06:06:35 UTC
        RTC time: Thu 2017-10-05 06:06:35
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

附:公網NTP服務器IP地址
ntpdate 133.100.11.8
ntpdate 132.163.4.101

RHEL 7 NTP配置實驗