一、配置chronyd, 使其从其他NTP服务器去同步时间
(配置一个aliyun可用,再配置一个不可用的)
使用timedatectl查看:当前系统时钟是否已同步,ntp服务器是否可用
需要查看:时间源的状态: ^? .^*
跟踪当前的同步状态: tracking sourcestat, activity
强制同步:chronyc -a makestep重启服务
1、对配置文件进行编辑/etc/chrony.conf
[root@localhost ~]# vim /etc/chrony.conf
2、向文件中配置两条时间源(其中server ntp.aliyun.com iburst可用,server s1a.time.edu.cn iburst不可用)
3、查看当前时钟是否已经同步,ntp服务是否可用
[root@localhost ~]# timedatectl
Local time: Mon 2022-09-26 09:15:35 CST
Universal time: Mon 2022-09-26 01:15:35 UTC
RTC time: Mon 2022-09-26 01:15:36
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
时钟已经同步且ntp服务可用
4、查看时间源的状态
[root@localhost ~]# chronyc sources -v
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current best, '+' = combined, '-' = not combined,
| / 'x' = may be in error, '~' = too variable, '?' = unusable.
|| .- 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 377 30 +3424us[+4748us] +/- 35ms
查看可知,203.107.6.88时间源可用,另外一个配置的时间源不可用(没有显示出来)
5、跟踪当前的同步状态
(1)tracking
[root@localhost ~]# chronyc tracking -v
Reference ID : CB6B0658 (203.107.6.88)
Stratum : 3
Ref time (UTC) : Mon Sep 26 01:20:29 2022
System time : 0.000538207 seconds slow of NTP time
Last offset : +0.000052816 seconds
RMS offset : 0.133085340 seconds
Frequency : 10.698 ppm slow
Residual freq : +0.022 ppm
Skew : 10.006 ppm
Root delay : 0.058949839 seconds
Root dispersion : 0.002617337 seconds
Update interval : 65.0 seconds
Leap status : Normal
(2)sourcestats
[root@localhost ~]# chronyc sourcestats -v
.- 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
==============================================================================
203.107.6.88 17 9 848 +0.579 12.416 +18us 3545us
(3)activity
[root@localhost ~]# chronyc activity -v
200 OK
1 sources online
0 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address
6、强制同步
[root@localhost ~]# chronyc -a makestep
200 OK
二、配置chrony:需要有两台机器,一台作为时间服务器,一台作为客户端时间
服务器要求:不从网络同步时间,使用本地时间
客户端要求:从我们时间服务器同步时间,要求能同步成功也要分别查看状态
localhost作为时间服务器,rhce作为客服端
(1)a端配置
1、配置chrony.conf文件
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# pool 2.rhel.pool.ntp.org iburst
server 192.168.106.130 iburst #表示将自己设置为时间服务器
allow 192.168.0.0/16 #表示允许这个网段的其他主机链接
local stratum 10 #即使未与时间源同步,也提供服务时间
2、启动服务
systemctl start chronyd
systemctl enable chronyd
(2)b端配置
1、配置chrony.conf文件
server 192.168.192.133 iburst #说明需要同步的服务器是虚拟机a
2、启动
systemctl start chronyd
systemctl enable chronyd