配置服务端:
服务端配置:
[root@cent7_yzil ~]# hostname -I
10.0.0.121
[root@cent7_yzil ~]# yum -y install chrony
[root@cent7_yzil ~]# vim /etc/chrony.conf
server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 10.0.0.0/24 #加此行,指定允许同步的网段
# Serve time even if not synchronized to a time source.
local stratum 10 #删除此行注释,当互联网无法连接,仍然可以为客户端提供时间同步服务
[root@cent7_yzil ~]# systemctl restart chronyd
[root@cent7_yzil ~]# chronyc sources -v
210 Number of sources = 2
.-- 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
===============================================================================
^* 203.107.6.88 2 6 17 18 +444us[+2371us] +/- 25ms
^- 120.25.115.20 2 6 17 19 -1082us[-1082us] +/- 27ms
[root@cent7_yzil ~]#
#服务启动后会打开端口123/udp
[root@cent7_yzil ~]# ss -ntlu
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 127.0.0.1:323 *:*
udp UNCONN 0 0 *:5353 *:* *:*
udp UNCONN 0 0 *:123 *:*
[root@cent7_yzil ~]#
客户端配置:
[root@cent8_yzil ~]# vim /etc/chrony.conf
server 10.0.0.121 iburst
[root@cent8_yzil ~]# systemctl restart chronyd
#确认同步成功
[root@cent8_yzil ~]# 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
===============================================================================
^* 10.0.0.121 2 7 377 1 +4765us[+5003us] +/- 26ms
[root@cent8_yzil ~]#