服务器部署简介
XBlade Studio 服务器部署指南 - 包含机器人部署、服务器配置和运维管理。
概述
本文档提供 XBlade 项目的完整服务器部署指南,包括做市机器人、刷量机器人的部署,以及服务器环境配置、监控和维护。
服务器信息
生产服务器 (主要部署)
| 项目 | 值 |
|---|---|
| 域名 | c9.one |
| IP 地址 | 13.212.6.186 |
| 实例类型 | c7i.xlarge |
| 区域 | ap-southeast-1 (新加坡) |
| CPU | 4 vCPU (Intel Xeon Platinum 8488C) |
| 内存 | 7.6 GB |
| 磁盘 | 484 GB |
| 系统 | Ubuntu 24.04.3 LTS |
测试服务器
| 项目 | 值 |
|---|---|
| 域名 | c9plus.top |
| IP 地址 | 13.212.240.41 |
| 实例类型 | c7i.large |
| 区域 | ap-southeast-1 (新加坡) |
| CPU | 2 vCPU (Intel Xeon Platinum 8488C) |
| 内存 | 3.7 GB |
| 磁盘 | 484 GB |
| 系统 | Ubuntu 24.04.3 LTS |
部署架构
用户请求
↓
Cloudflare CDN (c9.one / c9plus.top)
↓
AWS ELB (负载均衡器)
↓
EC2 实例 (13.212.6.186 / 13.212.240.41)
↓
├── Nginx (反向代理)
│ ├── renance.xyz → Next.js (3000)
│ └── api-sepolia.renance.xyz → Rust Backend (8080)
├── PostgreSQL + TimescaleDB (5432)
├── Redis (6379)
└── 机器人服务
├── 做市机器人 (pure_market_maker.py)
└── 刷量机器人 (multi_tier_bot_simple.py)
运行中的服务
生产服务器服务
| 服务 | 版本 | 端口 | 状态 | 说明 |
|---|---|---|---|---|
| Nginx | 1.24.0 | 80, 443 | ✓ 运行中 | Web服务器/反向代理 |
| PostgreSQL | 16.11 | 5432 | ✓ 运行中 | 主数据库 |
| TimescaleDB | 2.24.0 | - | ✓ 已启用 | 时序数据扩展 |
| Redis | 7.0.15 | 6379 | ✓ 运行中 | 缓存服务 |
| axblade-backend | - | 8080 | ✓ 运行中 | Rust后端服务 |
域名配置
| 域名 | 服务 | 后端端口 | SSL证书 |
|---|---|---|---|
| renance.xyz | 前端 (Next.js) | 3000 | ✓ Let's Encrypt |
| api-sepolia.renance.xyz | Rust 后端 | 8080 | ✓ Let's Encrypt |
SSL 证书到期日期: 2026-03-26
自动续期: ✓ 已启用 (certbot timer)
快速开始
1. SSH 连接
使用密钥登录(推荐)
# 生产服务器
ssh -i ~/.ssh/id_ed25519_xblade hexchange@13.212.6.186
# 测试服务器
ssh -i ~/.ssh/id_ed25519_xblade hexchange@13.212.240.41
使用 SSH 配置别名
在 ~/.ssh/config 中添加:
# 生产服务器
Host c9-prod
HostName 13.212.6.186
User hexchange
IdentityFile ~/.ssh/id_ed25519_xblade
IdentitiesOnly yes
# 测试服务器
Host c9plus-test
HostName 13.212.240.41
User hexchange
IdentityFile ~/.ssh/id_ed25519_xblade
IdentitiesOnly yes
快捷连接:
ssh c9-prod # 连接生产服务器
ssh c9plus-test # 连接测试服务器
2. 部署机器人
部署做市机器人
# 1. 连接服务器
ssh c9-prod
# 2. 进入项目目录
cd ~/XBlade_maker_bot
# 3. 配置环境变量
vim .env
# 4. 启动做市机器人
./start_pure_maker.sh
# 5. 查看运行状态
screen -ls
screen -r bot
部署刷量机器人
# 1. 连接服务器
ssh c9-prod
# 2. 进入项目目录
cd ~/XBlade_maker_bot
# 3. 启动刷量机器人
./start_multi_tier.sh
# 4. 查看运行状态
screen -ls
screen -r bot
3. 查看服务状态
# 查看所有服务状态
sudo systemctl status nginx postgresql redis-server axblade-backend
# 查看后端服务日志
sudo journalctl -u axblade-backend -f
# 查看 Nginx 日志
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log
部署方式
方式一:GitHub Actions 自 动部署
项目配置了 GitHub Actions 自动部署,代码推送到 main 分支后自动部署到服务器。
工作流文件: .github/workflows/deploy.yml
name: Deploy Bot to Server
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Copy Files to Server
uses: appleboy/scp-action@master
with:
host: 13.212.240.41
username: hexchange
password: ${{ secrets.SERVER_PASSWORD }}
source: "."
target: "~/XBlade_maker_bot"
exclude: ".git,.github,.env"
- name: Post-Deployment Commands
uses: appleboy/ssh-action@master
with:
host: 13.212.240.41
username: hexchange
password: ${{ secrets.SERVER_PASSWORD }}
script: |
cd ~/XBlade_maker_bot
chmod +x *.sh
echo "Deployment completed!"
触发方式:
- 自动触发:推送代码到 main 分支
- 手动触发:在 GitHub Actions 页面点击 "Run workflow"
方式二:手动部署
# 1. 本地打包代码
cd ~/Desktop/XBlade_maker_bot
tar -czf bot.tar.gz --exclude='.git' --exclude='__pycache__' .
# 2. 上传到服务器
scp bot.tar.gz c9-prod:~/
# 3. 在服务器上解压
ssh c9-prod
cd ~
tar -xzf bot.tar.gz -C XBlade_maker_bot/
cd XBlade_maker_bot
chmod +x *.sh
# 4. 重启服务
screen -S bot -X quit || true
./start_pure_maker.sh
环境配置
机器人环境变量
编辑 .env 文件配置机器人参数:
# API 配置
API_URL=https://api-sepolia.renance.xyz
CHAIN_ID=421614
# 合约地址
VAULT_ADDRESS=0xAAbdbE3F3382D8E620cDeCD9b06022b8E63bE33D
USDT_ADDRESS=0x572E474C3Cf364D085760784F938A1Aa397a8B9b
# 账户配置(在 accounts.csv 中配置)
# 格式: name,address,private_key
数据库配置
PostgreSQL 连接信息:
| 参数 | 值 |
|---|---|
| 主机 | 127.0.0.1 |
| 端口 | 5432 |
| 数据库 | axblade_prod |
| 用户名 | axblade |
| 密码 | ChujXi6cEAvo9J3T0C6wQgdK |
连接字符串:
postgresql://axblade:ChujXi6cEAvo9J3T0C6wQgdK@127.0.0.1:5432/axblade_prod
监控和维护
服务健康检查
# 检查后端 API
curl https://api-sepolia.renance.xyz/health
# 检查数据库连接
psql -h 127.0.0.1 -U axblade -d axblade_prod -c "SELECT version();"
# 检查 Redis
redis-cli ping
# 检查 Nginx
sudo nginx -t
日志查看
# 后端服务日志
sudo journalctl -u axblade-backend -f
# Nginx 访问日志
sudo tail -f /var/log/nginx/access.log
# Nginx 错误日志
sudo tail -f /var/log/nginx/error.log
# PostgreSQL 日志
sudo tail -f /var/log/postgresql/postgresql-16-main.log
# 机器人日志
tail -f ~/XBlade_maker_bot/bot.log
服务管理命令
# 重启服务
sudo systemctl restart nginx
sudo systemctl restart postgresql
sudo systemctl restart redis-server
sudo systemctl restart axblade-backend
# 查看服务状态
sudo systemctl status nginx
sudo systemctl status postgresql
sudo systemctl status redis-server
sudo systemctl status axblade-backend
# 启用/禁用开机自启
sudo systemctl enable nginx
sudo systemctl disable nginx
机器人管理
# 查看运行中的机器人
screen -ls
# 进入机器人会话
screen -r bot
# 停止机器人(在 screen 会话中)
Ctrl+C
# 退出 screen 会话(不停止机器人)
Ctrl+A, D
# 强制停止机器人
screen -S bot -X quit
# 重启机器人
screen -dmS bot ./start_pure_maker.sh
性能优化
系统资源监控
# CPU 和内存使用
htop
# 磁盘使用
df -h
# 网络连接
ss -tlnp
# 进程监控
ps aux | grep python
ps aux | grep axblade
PostgreSQL 优化
TimescaleDB 已自动调优,基于 7.6 GB 内存和 4 CPU:
| 参数 | 值 |
|---|---|
| shared_buffers | 1945MB |
| effective_cache_size | 5835MB |
| maintenance_work_mem | 995872kB |
| work_mem | 4979kB |
| max_worker_processes | 23 |
| max_parallel_workers | 4 |
Nginx 优化
# /etc/nginx/nginx.conf
worker_processes auto;
worker_connections 1024;
# 启用 gzip 压缩
gzip on;
gzip_types text/plain text/css application/json application/javascript;
# 客户端缓存
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
安全配置
防火墙规则
# 查看当前规则
sudo ufw status
# 允许 SSH
sudo ufw allow 22/tcp
# 允许 HTTP/HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# 启用防火墙
sudo ufw enable