Files

8.6 KiB
Raw Permalink Blame History

代理管理平台 - 项目总结

📁 项目结构

/app/proxy-platform/
├── cmd/
│   ├── scheduler/main.go       # 调度中心入口
│   └── agent/main.go           # 节点 Agent 入口
├── internal/
│   ├── models/models.go        # 数据模型
│   ├── repository/repository.go # 数据访问层
│   ├── handler/handler.go      # HTTP 处理器
│   ├── config/config.go        # 配置管理
│   ├── socks5/socks5.go        # SOCKS5 实现
│   ├── scheduler/scheduler.go  # 调度引擎
│   ├── agent/agent.go          # Agent 客户端
│   ├── warp/warp.go            # WARP 管理
│   └── unlock/unlock.go        # 解锁检测
├── configs/
│   ├── scheduler.yaml          # 调度中心配置
│   └── agent.yaml              # Agent 配置
├── deployments/
│   ├── docker-compose.yml      # Docker Compose
│   ├── Dockerfile.scheduler    # 调度中心镜像
│   └── Dockerfile.agent        # Agent 镜像
├── go.mod
├── Makefile
├── README.md
└── PLAN.md

已完成功能

1. 核心模块

  • SOCKS5 服务端

    • 支持 SOCKS5 协议
    • 用户名密码认证
    • 连接数限制
    • 数据转发
  • 调度引擎

    • 4 种负载均衡策略(最小延迟、最小连接数、加权轮询、随机)
    • 节点选择算法
    • 解锁能力筛选
    • 健康检查
  • 节点 Agent

    • WARP 连接管理
    • 心跳上报
    • 解锁检测
    • 指令执行
  • WARP 管理

    • 连接/断开
    • IP 刷新
    • 防重复 IP
    • 账号注册
  • 解锁检测

    • 6 种服务检测(GPT、Netflix、Disney+、YouTube、Claude、Gemini
    • 关键词匹配
    • 区域识别

2. 数据库设计

  • users - 用户表
  • nodes - 节点表
  • node_groups - 节点组表
  • unlock_statuses - 解锁状态表
  • ip_change_logs - IP 变更日志表
  • connection_logs - 连接日志表
  • ip_refresh_rules - IP 刷新规则表

3. API 接口

用户管理

  • GET /api/v1/users - 获取用户列表
  • POST /api/v1/users - 创建用户
  • GET /api/v1/users/:id - 获取用户
  • PUT /api/v1/users/:id - 更新用户
  • DELETE /api/v1/users/:id - 删除用户

节点管理

  • GET /api/v1/nodes - 获取节点列表
  • POST /api/v1/nodes - 创建节点
  • GET /api/v1/nodes/:id - 获取节点
  • PUT /api/v1/nodes/:id - 更新节点
  • DELETE /api/v1/nodes/:id - 删除节点
  • POST /api/v1/nodes/:id/refresh-ip - 刷新 IP

Agent 接口

  • POST /api/v1/agent/heartbeat - 心跳上报
  • POST /api/v1/agent/unlock/report - 上报解锁状态
  • POST /api/v1/agent/ip/change/result - 上报 IP 变更

规则管理

  • GET /api/v1/rules - 获取规则列表
  • POST /api/v1/rules - 创建规则
  • GET /api/v1/rules/:id - 获取规则
  • PUT /api/v1/rules/:id - 更新规则
  • DELETE /api/v1/rules/:id - 删除规则

统计接口

  • GET /api/v1/stats/overview - 获取概览
  • GET /api/v1/stats/traffic - 获取流量统计

4. 部署配置

  • Docker Compose 配置
  • Dockerfile(调度中心、Agent
  • Makefile(构建、测试、部署)

🚀 快速启动

方式一:Docker Compose(推荐)

cd /app/proxy-platform

# 启动所有服务
docker-compose -f deployments/docker-compose.yml up -d

# 查看日志
docker-compose -f deployments/docker-compose.yml logs -f

# 停止服务
docker-compose -f deployments/docker-compose.yml down

方式二:手动启动

# 1. 启动数据库
docker-compose -f deployments/docker-compose.yml up -d postgres redis

# 2. 构建程序
make build

# 3. 启动调度中心
./bin/scheduler

# 4. 在节点服务器上启动 Agent
./bin/agent

📋 后续待完善

Phase 2(建议优先级)

  1. 管理面板前端

    • Vue 3 + Element Plus
    • 用户管理界面
    • 节点管理界面
    • 统计报表
  2. 规则引擎完善

    • IP 更换规则持久化
    • 规则触发逻辑
    • 规则优先级
  3. 统计功能

    • 流量统计
    • 用户统计
    • 节点统计

Phase 3(扩展功能)

  1. 流量分流

    • iptables 配置
    • WARP 路由规则
    • 原生 IP 直连
  2. 监控告警

    • Prometheus + Grafana
    • 告警规则
    • 通知渠道
  3. 性能优化

    • 连接池优化
    • 缓存策略
    • 负载测试

🔧 技术栈

组件 技术
后端语言 Go 1.21+
Web 框架 Gin
数据库 PostgreSQL 15
缓存 Redis 7
容器 Docker + Docker Compose
日志 Zap
配置 Viper

📊 架构图

┌─────────────────────────────────────────────────────────┐
│                     用户层                               │
│                  SOCKS5 客户端                          │
└────────────────────────┬────────────────────────────────┘
                         │
                         ▼
┌─────────────────────────────────────────────────────────┐
│              调度中心 (scheduler)                        │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐ │
│  │ SOCKS5 服务  │  │   调度引擎   │  │   API 服务   │ │
│  └──────────────┘  └──────────────┘  └──────────────┘ │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐ │
│  │  规则引擎    │  │  健康检查    │  │  数据库      │ │
│  └──────────────┘  └──────────────┘  └──────────────┘ │
└────────────────────────┬────────────────────────────────┘
                         │
                         ▼
┌─────────────────────────────────────────────────────────┐
│              节点服务器 (agent)                          │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐ │
│  │  WARP 客户端 │  │  解锁检测    │  │  心跳上报    │ │
│  └──────────────┘  └──────────────┘  └──────────────┘ │
│  ┌──────────────┐  ┌──────────────┐                   │
│  │  SOCKS5 服务 │  │  流量分流    │                   │
│  └──────────────┘  └──────────────┘                   │
└─────────────────────────────────────────────────────────┘

📝 使用示例

创建用户

curl -X POST http://localhost:8080/api/v1/users \
  -H "Content-Type: application/json" \
  -d '{
    "username": "user1",
    "password": "password123",
    "traffic_quota": 107374182400,
    "expire_days": 30
  }'

添加节点

curl -X POST http://localhost:8080/api/v1/nodes \
  -H "Content-Type: application/json" \
  -d '{
    "node_id": "node_001",
    "name": "US-Node-1",
    "host": "1.2.3.4",
    "port": 1080,
    "region": "US",
    "weight": 100
  }'

使用代理

# 使用 curl
curl --socks5 user1:password123@localhost:1080 https://httpbin.org/ip

# 使用 Python
import requests
proxies = {
    'http': 'socks5://user1:password123@localhost:1080',
    'https': 'socks5://user1:password123@localhost:1080'
}
r = requests.get('https://httpbin.org/ip', proxies=proxies)
print(r.json())

项目编译状态: 成功
代码行数: ~3000 行
预计开发时间: 已完成 Phase 1 核心功能

下一步建议:

  1. 启动测试(需要 PostgreSQL 和 Redis
  2. 开发管理面板前端
  3. 完善规则引擎
  4. 部署到生产环境