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