跳到主要内容

私有化部署指南

Anima 支持私有化部署,让您可以在自己的服务器上运行 Anima 服务,实现完全自主可控的内网穿透解决方案。

📋 目录


🏗️ 部署架构

系统架构图

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│ Anima 客户端 │────│ Anima 服务端 │────│ 本地服务 │
│ (用户设备) │ │ (您的服务器) │ │ (内网设备) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
│ │ │
┌─────────┐ ┌─────────┐ ┌─────────┐
│ 用户网络 │ │ 公网服务器 │ │ 内网环境 │
└─────────┘ └─────────┘ └─────────┘

组件说明

  • Anima 服务端: 运行在您的服务器上,负责转发流量
  • Anima 客户端: 运行在需要穿透的内网设备上
  • 管理后台: Web 界面,用于管理隧道和监控状态

💻 服务器要求

硬件要求

组件最低配置推荐配置
CPU1 核心2+ 核心
内存1 GB4+ GB
存储20 GB100+ GB
网络10 Mbps100+ Mbps

软件要求

  • 操作系统: Linux (Ubuntu 20.04+, CentOS 8+, Debian 11+)
  • 容器: Docker 20.10+ 和 Docker Compose 2.0+
  • 域名: 用于 SSL 证书和管理后台访问
  • 防火墙: 开放必要端口

网络端口

端口协议说明
443TCPHTTPS 管理后台
8080TCP客户端连接端口
80TCPHTTP 重定向到 HTTPS

🚀 安装服务端

方法一:Docker Compose(推荐)

  1. 下载部署文件
# 创建项目目录
mkdir -p /opt/anima
cd /opt/anima

# 下载部署配置
curl -O https://raw.githubusercontent.com/anima-dev/anima/main/deploy/docker/docker-compose.yml
curl -O https://raw.githubusercontent.com/anima-dev/anima/main/deploy/docker/.env.example
  1. 配置环境变量
# 复制环境变量文件
cp .env.example .env

# 编辑配置文件
nano .env

主要配置项:

# 域名配置
DOMAIN=your-domain.com
ADMIN_DOMAIN=admin.your-domain.com

# 数据库配置
POSTGRES_PASSWORD=your_secure_password
REDIS_PASSWORD=your_redis_password

# JWT 密钥
JWT_SECRET=your_jwt_secret_key

# 邮箱配置(可选)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASS=your-app-password
  1. 启动服务
# 启动所有服务
docker-compose up -d

# 查看服务状态
docker-compose ps

# 查看日志
docker-compose logs -f

方法二:源码编译

  1. 安装依赖
# Ubuntu/Debian
sudo apt update
sudo apt install -y git golang-go postgresql redis-server

# CentOS/RHEL
sudo yum install -y git golang postgresql-server redis
  1. 编译服务端
# 克隆源码
git clone https://github.com/anima-dev/anima.git
cd anima/server

# 编译
go build -o anima-server cmd/frps/main.go

# 安装
sudo mv anima-server /usr/local/bin/
  1. 配置服务端

创建配置文件 /etc/anima/frps.toml

# 服务端配置
bindPort = 8080
vhostHTTPPort = 80
vhostHTTPSPort = 443

# 认证配置
auth.method = "token"
auth.token = "your_secure_token"

# 日志配置
log.to = "/var/log/anima/frps.log"
log.level = "info"
log.maxDays = 7

# 管理后台
webServer.addr = "0.0.0.0"
webServer.port = 8080
webServer.user = "admin"
webServer.password = "your_admin_password"

⚙️ 配置客户端

连接到私有化服务器

  1. 初始化配置
anima config init

按提示输入:

  • 服务器地址: your-domain.com:8080your-ip:8080
  • API Token: 从私有化部署的管理后台获取
  1. 验证连接
# 测试连接
anima ping

# 查看配置
anima config show

配置文件示例

创建 ~/.anima/config.toml

[server]
# 私有化服务器地址
addr = "your-domain.com:8080"
token = "your_private_token"
timeout = 30

[client]
name = "my-device"
log_level = "info"

# 示例隧道配置
[tunnels.webapp]
type = "http"
local_port = 3000
subdomain = "myapp"

[tunnels.ssh]
type = "tcp"
local_port = 22
remote_port = 2222

🌐 域名配置

DNS 配置

  1. 添加 A 记录
# 主域名
your-domain.com A your-server-ip

# 管理后台
admin.your-domain.com A your-server-ip

# 通配符子域名(用于隧道)
*.your-domain.com A your-server-ip
  1. 验证 DNS 解析
# 检查主域名
nslookup your-domain.com

# 检查通配符域名
nslookup test.your-domain.com

Nginx 反向代理(可选)

如果需要使用 Nginx 作为反向代理:

server {
listen 80;
server_name your-domain.com admin.your-domain.com *.your-domain.com;
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl http2;
server_name your-domain.com;

ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;

location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

🔒 SSL 证书

Let's Encrypt 证书(推荐)

  1. 安装 Certbot
# Ubuntu/Debian
sudo apt install certbot

# CentOS/RHEL
sudo yum install certbot
  1. 申请证书
# 申请通配符证书
sudo certbot certonly --manual --preferred-challenges dns \
-d your-domain.com \
-d admin.your-domain.com \
-d *.your-domain.com

# 按提示添加 DNS TXT 记录验证域名所有权
  1. 自动续期
# 添加定时任务
sudo crontab -e

# 添加以下行(每天检查续期)
0 12 * * * /usr/bin/certbot renew --quiet

自签名证书(测试环境)

# 生成私钥
openssl genrsa -out server.key 2048

# 生成证书请求
openssl req -new -key server.key -out server.csr

# 生成自签名证书
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

📊 监控和维护

系统监控

  1. 资源监控
# 查看系统资源使用
htop
df -h
free -h

# 查看服务状态
docker-compose ps
systemctl status anima-server
  1. 日志监控
# 查看服务端日志
docker-compose logs -f anima-server

# 查看客户端日志
tail -f ~/.anima/logs/anima.log

备份策略

  1. 数据库备份
# PostgreSQL 备份
docker-compose exec postgres pg_dump -U anima anima > backup_$(date +%Y%m%d).sql

# 自动备份脚本
#!/bin/bash
BACKUP_DIR="/opt/backups"
DATE=$(date +%Y%m%d_%H%M%S)
docker-compose exec postgres pg_dump -U anima anima > $BACKUP_DIR/anima_$DATE.sql
  1. 配置文件备份
# 备份配置
tar -czf anima_config_$(date +%Y%m%d).tar.gz /opt/anima/.env /etc/anima/

安全建议

  1. 防火墙配置
# 只开放必要端口
sudo ufw allow 22/tcp # SSH
sudo ufw allow 80/tcp # HTTP
sudo ufw allow 443/tcp # HTTPS
sudo ufw allow 8080/tcp # Anima 服务端口
sudo ufw enable
  1. 定期更新
# 更新系统
sudo apt update && sudo apt upgrade -y

# 更新 Docker 镜像
docker-compose pull
docker-compose up -d

🆘 故障排除

常见问题

  1. 客户端连接失败
# 检查网络连接
ping your-domain.com
telnet your-domain.com 8080

# 检查防火墙
sudo ufw status
sudo iptables -L
  1. 证书问题
# 检查证书有效期
openssl x509 -in /path/to/cert.pem -text -noout | grep "Not After"

# 测试 SSL 连接
openssl s_client -connect your-domain.com:443
  1. 性能问题
# 查看系统负载
uptime
iostat -x 1

# 查看网络连接
netstat -tulpn | grep :8080
ss -tulpn | grep :8080

📞 技术支持


最后更新: 2025年1月 文档版本: v1.0.0