节点使用中转服务器连接主控
有时候主控在国外、节点在国内,国内节点封海外导致无法直连主控,这时可以搭建一台中转服务器转发节点与主控之间的通讯。
配置中转服务器
中转服务器需要与主控和节点都网络相通,并放行 88(主控通讯端口)和 9200(Elasticsearch)端口。登录中转服务器,用 root 执行:
mkdir -p /data/sh/;
cat > /data/sh/iptables.sh <<'EOF'
master_ip="这里替换为主控ip"
local_ip=`ip ad | grep "inet " | grep -v 127.0.0.1 | head -n 1 | awk '{print $2}' | awk -F'/' '{print $1}'`
sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 88 -j DNAT --to-destination $master_ip:88
iptables -t nat -A POSTROUTING -p tcp --dport 88 -j SNAT --to-source $local_ip
iptables -t nat -A PREROUTING -p tcp --dport 9200 -j DNAT --to-destination $master_ip:9200
iptables -t nat -A POSTROUTING -p tcp --dport 9200 -j SNAT --to-source $local_ip
EOF
chmod +x /data/sh/iptables.sh;
/data/sh/iptables.sh;
echo "/data/sh/iptables.sh" >> /etc/rc.local;
修改节点配置
登录需要走中转的 V6 节点,用 root 执行以下命令。把 中转服务器IP 替换为实际 IP,其余不用改:
bash -s <<'CDNFLY_RELAY'
new_master_ip="中转服务器IP"
set -euo pipefail
conf="/opt/cdnfly-go/agent/conf/config.yaml"
filebeat="/opt/cdnfly-go/agent/conf/filebeat.yml"
ts="$(date +%Y%m%d%H%M%S)"
cp -a "$conf" "$conf.$ts.bak"
cp -a "$filebeat" "$filebeat.$ts.bak"
sed -i "/^master:/,/^[^[:space:]]/ s|^\([[:space:]]*\)ip:.*|\1ip: '$new_master_ip'|" "$conf"
sed -i "/^log:/,/^[^[:space:]]/ s|^\([[:space:]]*\)ip:.*|\1ip: '$new_master_ip'|" "$conf"
sed -i "/^output\.elasticsearch:/,/^[^[:space:]#]/ s|^[[:space:]]*hosts:.*| hosts: [\"$new_master_ip:9200\"]|" "$filebeat"
systemctl restart filebeat.service agent-socket.service agent-task.service
systemctl is-active filebeat.service agent-socket.service agent-task.service
CDNFLY_RELAY
说明:
- v6 节点的 nginx
listen_80.conf/listen_other.conf等配置由主控自动同步,无需手动修改。 - 命令会自动备份原配置(同目录生成带时间戳的
.bak文件)。
检查结果
grep -A3 '^master:' /opt/cdnfly-go/agent/conf/config.yaml
grep -A2 '^log:' /opt/cdnfly-go/agent/conf/config.yaml
确认两处 IP 已改为中转服务器 IP,且主控后台中节点恢复在线、访问日志正常上报。