#!/bin/bash # 3x-ui-agent 节点一键安装脚本 # 用法: bash install-agent.sh --master http://MASTER_IP:2053 --token YOUR_AGENT_TOKEN [--name my-node] # 要求: Debian/Ubuntu/Alpine/CentOS (amd64/arm64), root 运行 set -e RED='\033[0;31m'; GREEN='\033[0;32m'; NC='\033[0m' info() { echo -e "${GREEN}[INFO]${NC} $1"; } error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } [[ $EUID -ne 0 ]] && error "请用 root 运行" MASTER=""; TOKEN=""; NAME="agent-node" while [[ $# -gt 0 ]]; do case $1 in --master) MASTER="$2"; shift 2;; --token) TOKEN="$2"; shift 2;; --name) NAME="$2"; shift 2;; *) error "未知参数: $1";; esac done [[ -z "$MASTER" ]] && error "缺少 --master 参数" [[ -z "$TOKEN" ]] && error "缺少 --token 参数 (从主控面板 API 获取)" ARCH=$(uname -m) case "$ARCH" in x86_64|amd64) BIN_ARCH="amd64";; aarch64|arm64) BIN_ARCH="arm64";; *) error "不支持的架构: $ARCH (仅支持 amd64/arm64)";; esac # 二进制下载地址(本仓 Gitea Releases,tag 沿用 v3.7.0-agent.1) XUI_URL="${XUI_URL:-https://git.881218.xyz/rogue/3x-ui-agent/releases/download/v3.7.0-agent.1/x-ui-linux-${BIN_ARCH}}" XRAY_VER="26.6.27" info "创建目录..." mkdir -p /usr/local/x-ui/bin /etc/x-ui info "下载 agent 二进制..." curl -fL -o /usr/local/x-ui/x-ui "$XUI_URL" || error "agent 下载失败" chmod +x /usr/local/x-ui/x-ui info "下载 xray v${XRAY_VER}..." cd /usr/local/x-ui/bin case "$BIN_ARCH" in amd64) XRAY_ZIP="Xray-linux-64.zip";; arm64) XRAY_ZIP="Xray-linux-arm64-v8a.zip";; esac curl -fL -o "$XRAY_ZIP" "https://github.com/XTLS/Xray-core/releases/download/v${XRAY_VER}/${XRAY_ZIP}" || error "xray 下载失败" unzip -o -q "$XRAY_ZIP" xray && mv xray "xray-linux-${BIN_ARCH}" && chmod +x "xray-linux-${BIN_ARCH}" rm -f "$XRAY_ZIP" info "下载 geo 文件..." curl -fL -o geoip.dat "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" || error "geoip 下载失败" curl -fL -o geosite.dat "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat" || error "geosite 下载失败" info "写入 agent 配置..." cat > /etc/x-ui/agent.json </dev/null || true; sleep 1 nohup /usr/local/x-ui/x-ui agent > /tmp/agent.log 2>&1 & sleep 8 if grep -q "Starting 3x-ui agent" /tmp/agent.log 2>/dev/null; then info "agent 启动成功!" echo "" echo " 主控: $MASTER" echo " 节点名: $NAME" echo " 日志: tail -f /tmp/agent.log" echo " agent 会在 30 秒内从主控拉取配置" else error "启动失败,查看日志: cat /tmp/agent.log" fi