利用chrony,配置linux1为其他linux主机提供NTP服务。
//使用for循环给所
[root@linux1 ~]# for i in {1..9};do ssh root@10.4.220.10$i yum install -y chrony ;done
[root@linux1 ~]# vi /etc/chrony.conf //修改服务端配置文件
1 # Use public servers from the pool.ntp.org project.
2 # Please consider joining the pool (https://www.pool.ntp.org/join.html).
3 #pool 2.rocky.pool.ntp.org iburst //取消注释
4 server 10.4.220.101 ibutst //添加这段
5
6 # Use NTP servers from DHCP.
7 sourcedir /run/chrony-dhcp
8
9 # Record the rate at which the system clock gains/losses time.
10 driftfile /var/lib/chrony/drift
11
12 # Allow the system clock to be stepped in the first three updates
13 # if its offset is larger than 1 second.
14 makestep 1.0 3
15
16 # Enable kernel synchronization of the real-time clock (RTC).
17 rtcsync
18
19 # Enable hardware timestamping on all interfaces that support it.
20 #hwtimestamp *
21
22 # Increase the minimum number of selectable sources required to adjust
23 # the system clock.
24 #minsources 2
25
26 # Allow NTP client access from local network.
27 #allow 192.168.0.0/16
28 allow 10.4.220.0/24 //添加
29
30 # Serve time even if not synchronized to a time source.
31 local stratum 10 //取消注释
[root@linux2 ~]# vi /etc/chrony.conf //配置客户端
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
#pool 2.rocky.pool.ntp.org iburst //取消注释
server 10.4.220.101 iburst //添加;注:客户端只用修改这里
# Use NTP servers from DHCP.
sourcedir /run/chrony-dhcp
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
//利用for循环把配置文件发送到别的主机
[root@linux2 ~]# for i in {3..9};do scp /etc/chrony.conf root@10.4.220.10$i:/etc/chrony.conf ;done
[root@linux1 ~]# firewall-cmd --zone=public --add-port=123/udp --permanent //放行端口
[root@linux1 ~]# firewall-cmd --reload //刷新规则
//利用for循环重启所有主机的服务
[root@linux1 ~]# for i in {1..9};do ssh root@10.4.220.10$i systemctl restart chronyd.service ;done
//验证
[root@linux1 ~]# chronyc clients //查询同步主机