# 安装部署 ## 部署方式 REX 支持三种部署方式:Docker、二进制、配置文件。 ## Docker 部署 ### 快速启动 ```bash docker run -d \ --name rex-hub \ -p 8080:8080 \ -v rex-data:/data \ jeelin/rex-hub:latest ``` ### Docker Compose ```yaml version: '3.8' services: rex-hub: image: jeelin/rex-hub:latest container_name: rex-hub ports: - "8080:8080" volumes: - rex-data:/data restart: unless-stopped volumes: rex-data: ``` ### 环境变量 | 变量 | 说明 | 默认值 | |------|------|--------| | `REX_DATA_DIR` | 数据目录 | `/data` | | `REX_SECRET_KEY` | 加密密钥 | 自动生成 | | `REX_LISTEN_ADDR` | 监听地址 | `0.0.0.0:8080` | ## 二进制部署 ### 下载 从 [GitHub Releases](https://github.com/JeeLin/REX/releases) 下载对应平台的二进制文件。 支持平台: - Linux (x86_64, aarch64) - macOS (x86_64, aarch64) - Windows (x86_64) ### 启动 ```bash # Linux / macOS ./rex-hub # Windows rex-hub.exe ``` 首次启动会在当前目录创建 `data/` 目录存放配置和数据库。 ## Agent 部署 ### 注册 Agent 1. 在 Hub 控制台创建环境,获取注册令牌 2. 在目标服务器部署 Agent 二进制 ### Agent 启动 ```bash # 使用注册令牌启动 ./rex-agent --token --hub-url https://your-hub.com ``` ### Agent Docker 部署 ```bash docker run -d \ --name rex-agent \ -e REX_HUB_URL=https://your-hub.com \ -e REX_REGISTRATION_TOKEN= \ jeelin/rex-agent:latest ``` ## 配置文件 ### 配置文件位置 - Linux/macOS: `~/.config/rex/config.toml` - Windows: `%APPDATA%\REX\config.toml` ### 配置示例 ```toml [server] listen_addr = "0.0.0.0:8080" [data] dir = "/var/lib/rex" [auth] session_timeout = 3600 [update] auto_check = true ``` ## 首次使用 ### 1. 访问控制台 打开浏览器访问 `http://localhost:8080` ### 2. 设置密码 首次访问需要设置管理员密码。 ### 3. 创建环境 1. 进入「环境」页面 2. 点击「新建环境」 3. 填写名称、描述 4. 选择连接方式(直连或 Agent 代理) ### 4. 添加资源 1. 在环境详情页点击「新建资源」 2. 选择协议类型(SSH/MySQL/Redis 等) 3. 填写连接信息 4. 测试连接 5. 保存 ### 5. 连接使用 1. 进入工作空间 2. 在左侧连接树选择资源 3. 双击打开对应控制台 ## HTTPS 配置 ### 使用反向代理 推荐使用 Nginx 或 Caddy 进行 TLS 终止: ```nginx server { listen 443 ssl; server_name rex.example.com; ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location /ws/ { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } ``` ### 内置 TLS REX 也支持内置 TLS 配置: ```toml [server.tls] enabled = true cert_file = "/path/to/cert.pem" key_file = "/path/to/key.pem" ```