背景:在阿里上買了台服務器,然后安裝zookeeper,然后沒有回調
好像沒有設置防火牆
需要注意的是:CentOS7默認的防火牆不是iptables,而是firewalle.
解決方法
一、保持firewall方式管理
如果要添加范圍例外端口 如 1000-2000
語法命令如下:啟用區域端口和協議組合
firewall-cmd [–zone=] --add-port=[-]/ [–timeout=]
此舉將啟用端口和協議的組合。端口可以是一個單獨的端口 或者是一個端口范圍 - 。協議可以是 tcp 或 udp。
實際命令如下:
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (–permanent永久生效,沒有此參數重啟后失效)
firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent
重新載入
firewall-cmd --reload
查看
firewall-cmd --zone=public --query-port=80/tcp
刪除
firewall-cmd --zone=public --remove-port=80/tcp --permanent
二、還原傳統的管理方式
關閉防火牆
systemctl stop firewalld
systemctl mask firewalld
並且安裝iptables-services:
yum install iptables-services
設置開機啟動:
systemctl enable iptables //其他設置 systemctl stop iptables systemctl start iptables systemctl restart iptables systemctl reload iptables
保存設置
service iptables save
開放某個端口 在/etc/sysconfig/iptables里添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCE
------------------------------------------------------------------- 粗略的分割線---------------------------------------------
第一種方案相關
開啟服務器
# systemctl restart iptables Job for iptables.service failed because the control process exited with error code. See "systemctl status iptables.service" and "journalctl -xe" for details.
# /etc/init.d/iptables status -bash: /etc/init.d/iptables: No such file or directory [root@iZwz90ebr6tsvoc9gn67h1Z sysconfig]# firewall-cmd --zone=public --add-port=2181/tcp --permanent FirewallD is not running
發現報: FirewallD is not running問題,下面解決這個問題:
1)查看firewalld狀態:systemctl status firewalld,如果是dead狀態,即防火牆未開啟。
啟動一個服務:systemctl start firewalld.service
關閉一個服務:systemctl stop firewalld.service
重啟一個服務:systemctl restart firewalld.service
顯示一個服務的狀態:systemctl status firewalld.service
在開機時啟用一個服務:systemctl enable firewalld.service
在開機時禁用一個服務:systemctl disable firewalld.service
查看服務是否開機啟動:systemctl is-enabled firewalld.service
查看已啟動的服務列表:systemctl list-unit-files|grep enabled
查看啟動失敗的服務列表:systemctl --failed
--- 加端口號 firewall-cmd --permanent --zone=public --add-port=3306/tcp 關閉防火牆 systemctl stop firewalld
最后,重啟防火牆,成功了!
最后還是沒有回調。。。。。。。。原因是阿里雲要配置些東西:https://www.cnblogs.com/yrjns/p/12491448.html
參考: https://www.cnblogs.com/wayneliu007/p/10372601.html
https://blog.csdn.net/qq_37246351/article/details/88313418