Files
aiagent/开放端口脚本.sh
2026-01-19 00:09:36 +08:00

44 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 开放8037和8038端口的脚本
echo "正在检查并开放端口 8037 和 8038..."
# 方法1: 使用firewalld (CentOS/RHEL 7+)
if command -v firewall-cmd &> /dev/null; then
echo "检测到 firewalld使用 firewalld 开放端口..."
sudo firewall-cmd --permanent --add-port=8037/tcp
sudo firewall-cmd --permanent --add-port=8038/tcp
sudo firewall-cmd --reload
echo "✅ firewalld 端口已开放"
exit 0
fi
# 方法2: 使用ufw (Ubuntu/Debian)
if command -v ufw &> /dev/null; then
echo "检测到 ufw使用 ufw 开放端口..."
sudo ufw allow 8037/tcp
sudo ufw allow 8038/tcp
echo "✅ ufw 端口已开放"
exit 0
fi
# 方法3: 使用iptables
echo "使用 iptables 开放端口..."
sudo iptables -I INPUT -p tcp --dport 8037 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 8038 -j ACCEPT
# 保存iptables规则根据系统不同
if [ -f /etc/redhat-release ]; then
# CentOS/RHEL
sudo service iptables save 2>/dev/null || sudo iptables-save > /etc/sysconfig/iptables
elif [ -f /etc/debian_version ]; then
# Debian/Ubuntu
sudo iptables-save > /etc/iptables/rules.v4 2>/dev/null || echo "请手动保存iptables规则"
fi
echo "✅ iptables 端口已开放"
echo ""
echo "⚠️ 注意:如果使用云服务器(如腾讯云、阿里云等),还需要在云控制台配置安全组规则:"
echo " - 开放入站规则TCP 8037"
echo " - 开放入站规则TCP 8038"