Files
gerrit/开放端口29419.sh
2025-12-22 17:12:39 +08:00

83 lines
2.0 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
# 开放 Gerrit SSH 端口 29419 的防火墙脚本
echo "=========================================="
echo "开放 Gerrit SSH 端口 29419"
echo "=========================================="
# 检查是否有 root 权限
if [ "$EUID" -ne 0 ]; then
echo "❌ 此脚本需要 root 权限,请使用 sudo 运行"
echo ""
echo "使用方法:"
echo " sudo bash 开放端口29419.sh"
exit 1
fi
# 检查 firewall-cmd 是否可用
if ! command -v firewall-cmd &> /dev/null; then
echo "❌ 未找到 firewall-cmd 命令"
echo " 可能使用的是 iptables请手动配置"
exit 1
fi
echo ""
echo "步骤 1: 检查当前防火墙状态..."
firewall-cmd --state
echo ""
echo "步骤 2: 检查当前开放的端口..."
firewall-cmd --list-ports
echo ""
echo "步骤 3: 添加端口 29419/tcp..."
firewall-cmd --permanent --add-port=29419/tcp
if [ $? -eq 0 ]; then
echo "✅ 端口 29419/tcp 已添加到防火墙规则"
else
echo "❌ 添加端口失败"
exit 1
fi
echo ""
echo "步骤 4: 重新加载防火墙配置..."
firewall-cmd --reload
if [ $? -eq 0 ]; then
echo "✅ 防火墙配置已重新加载"
else
echo "❌ 重新加载失败"
exit 1
fi
echo ""
echo "步骤 5: 验证端口是否已开放..."
if firewall-cmd --list-ports | grep -q "29419/tcp"; then
echo "✅ 端口 29419/tcp 已成功开放"
else
echo "⚠️ 警告:端口可能未正确添加,请手动检查"
fi
echo ""
echo "步骤 6: 检查端口监听状态..."
if netstat -tlnp 2>/dev/null | grep -q ":29419"; then
echo "✅ Gerrit 服务正在监听端口 29419"
netstat -tlnp | grep 29419
else
echo "⚠️ 警告:未检测到端口 29419 的监听,请检查 Gerrit 服务状态"
fi
echo ""
echo "=========================================="
echo "完成!"
echo "=========================================="
echo ""
echo "如果使用云服务器,还需要在云控制台的安全组中开放端口 29419"
echo ""
echo "测试连接:"
echo " ssh -p 29419 renjianbo@101.43.95.130 gerrit version"
echo ""