定义两个虚拟主机 node1, node2
在 node1 主机上配置 chrony时间服务器,将该主机作为时间服务器。
1.1 vim打开配置文件
[root@node1 ~]# vim /etc/chrony.conf
1.2 修改配置文件
我这里选择的是阿里云时间服务器:ntp.aliyun.com
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
#pool 2.rhel.pool.ntp.org iburst
server ntp.aliyun.com iburst
1.3 重启服务器并查看
[root@node1 ~]# systemctl restart chronyd.service
[root@node1 ~]# chronyc sources
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 203.107.6.88 2 6 7 0 -19us[-3729us] +/- 31ms
2. 在 node1 主机上创建防火墙区域testzone, 将 node1 主机网络接口接入该区域,创建新防火墙服务为 timeservice 。
2.1 创建一个区域 testzone
[root@node1 ~]# firewall-cmd --new-zone=testzone --permanent
success
2.2 重新加载
[root@node1 ~]# firewall-cmd --reload
success
2.3 显示所有可用区域
[root@node1 ~]# firewall-cmd --get-zones
block dmz drop external home internal nm-shared public testzone trusted work
2.4 将node1主机网络接口接入该区域
[root@node1 ~]# #先查看活跃网络接口
[root@node1 ~]# firewall-cmd --get-active-zones
public
interfaces: ens160
[root@node1 ~]# #将ens16o主机网络接口接入testzone区域
[root@node1 ~]# firewall-cmd --zone=testzone --change-interface=ens160 --permanent
The interface is under control of NetworkManager, setting zone to 'testzone'.
success
[root@node1 ~]# #查看更改是否成功
[root@node1 ~]# firewall-cmd --get-active-zones
testzone
interfaces: ens160
2.5创建新防火墙服务为 timeservice
[root@node1 ~]# firewall-cmd --new-service=timeservice --permanent
success
[root@node1 ~]# #查看创建是否成功
root@node1 ~]# ll /etc/firewalld/services/
total 4
-rw-r--r--. 1 root root 60 Mar 15 21:54 timeservice.xml
3、在 node1 将该防火墙服务 timeservice 定义为允许 chrony 服务通过。
找到chrony服务 然后复制一份到timeservice
[root@node1 ~]# cd /usr/lib/systemd/system/
[root@node1 system]# cp chronyd.service /etc/firewalld/services/timeservice.xml
cp: overwrite '/etc/firewalld/services/timeservice.xml'? y
[root@node1 system]# cd /etc/firewalld/services/
[root@node1 services]# vim timeservice.xml
4、在 node2 主机上配置 chrony 时间客户端,该主机将 node1 主机作为时间源服务器。
首先我们要修改node1主机的/etc/chrony.conf文件中 允许node2主机访问 再重新启动服务(关闭防火墙)
# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 192.168.78.132/24
[root@node1 ~]# systemctl restart chronyd.service
[root@node1 ~]# systemctl stop firewalld #关闭防火墙
2. 再在node2主机上 添加node1主机作为时间服务器 再重新启动服务(关闭防火墙)
[root@node2 ~]# vim /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.rhel.pool.ntp.org iburst
server 192.168.78.133 iburst
[root@node2 ~]# systemctl restart chronyd.service
[root@node1 ~]# systemctl stop firewalld #关闭防火墙
5、配置完防火墙服务之后,node1 和 node2 主机的时间服务器可以正常工作。
直接查看时间服务器日志是否有记录
使用命令:cat /var/log/chrony/measurements.log
node1
node2