RHCE服务器和防火墙的应用

定义两个虚拟主机 node1, node2
1、在 node1 主机上配置 chrony 时间服务器,将该主机作为时间服务器。

[root@node1 ~]# 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 ntp.aliyun.com iburst

重启并查看

[root@node1 ~]# systemctl restart chronyd.service 
[root@node1 ~]# chronyc sources

 2、在 node1 主机上创建防火墙区域 testzone, 将 node1 主机网络接口接入该区域,创建新防火墙服务为 timeservice

[root@node1 ~]# firewall-cmd --new-zone=testzone --permanent
success

[root@node1 ~]# firewall-cmd --reload
success

[root@node1 ~]# firewall-cmd --get-zones
block dmz drop external home internal nm-shared public testzone trusted work


[root@node1 ~]# firewall-cmd --get-active-zones
public
  interfaces: ens160
[root@node1 ~]# firewall-cmd --zone=testzone --change-interface=ens160 --permanent
The interface is under control of NetworkManager, setting zone to 'testzone'.
success
[root@node1 ~]# firewall-cmd --get-active-zones
testzone
  interfaces: ens160

[root@node1 ~]# firewall-cmd --new-service=timeservice --permanent
success
root@node1 ~]# ll /etc/firewalld/services/
3、在 node1 将该防火墙服务 timeservice 定义为允许 chrony 服务通过。

[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 主机作为时间源服务器

 
# 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  

[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查看时间服务器日志是否有记录

猜你喜欢

转载自blog.csdn.net/m0_70940822/article/details/129622021