1.时区的设置
之前我用命令同步时间服务器上的时间,要保证时区的一致
[root@c7-22 ~]# timedatectl set-timezone Asia/Shanghai #设置为上海
2.时间服务器的实验
三台服务器都是采用的CentOS7_X64系列
10.0.0.22 要同步阿里云服务器的时间服务器
#修改配置文件
[root@c7-22 ~]# grep -Ev '^#|^$' /etc/chrony.conf
pool ntp.aliyun.com iburst #同步的阿里云时间服务器的地址
pool ntp1.aliyun.com iburst #同步的阿里云时间服务器的地址
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 10.0.0.0/24 #准许10.0.0.0/24的网段同步
logdir /var/log/chrony
#设置时区
[root@c7-22 ~]# timedatectl set-timezone Asia/Shanghai
10.0.0.24 客服端同步10.0.0.22 的时间
#默认:[root@c7-24 ~]# systemctl status chronyd是开启的
[root@c7-24 ~]# date
Wed May 26 00:18:13 EDT 2021
[root@c7-24 ~]# ntpdate 10.0.0.22 #一次性的时间服务
26 May 00:18:27 ntpdate[1418]: step time server 10.0.0.22 offset 31536000.001526 sec
[root@c7-24 ~]# date
Thu May 26 00:18:30 EDT 2022
#将服务器的地址写入配置文件
[root@c7-24 ~]# grep '^server' /etc/chrony.conf
server 10.0.0.22 iburst
重启时间服务
[root@c7-24 ~]# systemctl restart chronyd
[root@c7-24 ~]# 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.22 3 6 37 22 -54ns[ -151us] +/- 15ms
此时已经同步了时间服务器10.0.0.22
[root@c7-24 ~]# date -s '-1 years'
Wed May 26 00:30:22 EDT 2021
[root@c7-24 ~]# date
Wed May 26 00:30:24 EDT 2021
[root@c7-24 ~]# systemctl restart chronyd
[root@c7-24 ~]# date
Thu May 26 00:30:42 EDT 2022
10.0.0.25作为10.0.0.24的客服端
[root@c7-25 ~]# systemctl status chronyd 默认情况下时间服务器是开启的
[root@c7-25 ~]# yum -y install ntpdate -y
[root@c7-25 ~]# date -s '-1 years'
Wed May 26 00:36:29 EDT 2021
[root@c7-25 ~]# date
Wed May 26 00:36:31 EDT 2021
无法同步10.0.0.24的时间是因为10.0.0.24之开放了127.0.0.1的网络,没有123端口
[root@c7-25 ~]# ntpdate 10.0.0.24
26 May 00:37:27 ntpdate[1416]: no server suitable for synchronization found
[root@c7-24 ~]# ss -tnul #发现*.123的端口未打开,导致10.0.0.25无法同步10.0.0.24的
时间
[root@c7-24 ~]# grep '^allow' /etc/chrony.conf
allow 0.0.0.0/0 #开放所有端口