Add deployment scripts and documentation

- Add deployment scripts (deploy.sh, test_connection.sh, core/start_server.sh)
- Add deployment documentation (DEPLOYMENT_INFO.md, DEPLOYMENT_SUCCESS.md)
- Add .env.example configuration template
- Add requirements.txt for Python dependencies
- Update README.md with latest information
- Update core/server.py with improvements

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
你的用户名
2025-11-04 15:19:44 +08:00
parent a05a7dd40e
commit c4be264ea5
9 changed files with 911 additions and 1 deletions

252
DEPLOYMENT_SUCCESS.md Normal file
View File

@@ -0,0 +1,252 @@
# Funstat MCP 部署成功报告
## ✅ 部署状态:成功
**部署时间**: 2025-11-02
**服务器**: 172.16.74.159 (atai)
**服务进程**: PID 105552
---
## 🌐 访问信息
### 外部访问
- **SSE 端点**: http://172.16.74.159:8091/sse
- **消息端点**: http://172.16.74.159:8091/messages
### 内部访问(服务器内)
- http://127.0.0.1:8091/sse
- http://127.0.0.1:8091/messages
### 监听配置
- **监听地址**: 0.0.0.0 (所有网络接口)
- **监听端口**: 8091
- **协议**: HTTP + SSE
---
## ✅ 服务状态
```bash
# 进程状态
PID: 105552
运行中: ✅
内存使用: 78304 KB
# 网络状态
端口: 0.0.0.0:8091 LISTEN
防火墙: inactive (无限制)
# Telegram 连接
状态: ✅ 已连接
Bot: @openaiw_bot (KT超级数据)
账号: @xiaobai_80 (ID: 7363537082)
代理: socks5://127.0.0.1:1080
```
---
## 📋 部署清单
### 1. 系统环境
- [x] Ubuntu 24.04.3 LTS
- [x] Python 3.12.3
- [x] v2ray 代理运行中 (端口 1080)
### 2. 项目部署
- [x] 代码部署到 /home/atai/funstat-mcp
- [x] 虚拟环境创建 (.venv)
- [x] 依赖包安装完成 (mcp, telethon, starlette, uvicorn, PySocks, etc.)
### 3. 配置文件
- [x] .env 环境变量配置
- [x] Session 文件 (~/telegram_sessions/funstat_bot.session)
- [x] 启动脚本 (start_server_with_env.sh)
### 4. 服务配置
- [x] 监听地址: 0.0.0.0:8091
- [x] 代理配置: socks5://127.0.0.1:1080
- [x] 自动重启脚本
---
## 🔧 管理命令
### 启动服务
```bash
ssh atai@172.16.74.159
cd /home/atai/funstat-mcp/core
bash start_server_with_env.sh
```
### 停止服务
```bash
ssh atai@172.16.74.159
pkill -f 'funstat.*server.py'
```
### 查看日志
```bash
ssh atai@172.16.74.159
tail -f /tmp/funstat_sse.log
```
### 检查状态
```bash
ssh atai@172.16.74.159
ps aux | grep 'python.*server.py' | grep -v grep
ss -tuln | grep 8091
```
### 测试访问
```bash
# 从服务器内部测试
ssh atai@172.16.74.159
curl -s -o /dev/null -w '%{http_code}\n' http://172.16.74.159:8091/sse
# 从本地测试(如果网络可达)
curl -s -o /dev/null -w '%{http_code}\n' http://172.16.74.159:8091/sse
```
---
## 🔄 重新部署
### 方法 1: 使用部署脚本(本地执行)
```bash
cd /Users/hahaha/projects/funstat-mcp
bash deploy.sh
```
然后登录服务器启动:
```bash
ssh atai@172.16.74.159
cd /home/atai/funstat-mcp/core
bash start_server_with_env.sh
```
### 方法 2: 手动部署
```bash
# 1. 打包代码
cd /Users/hahaha/projects/funstat-mcp
tar --exclude='.git' --exclude='.venv' -czf /tmp/funstat-mcp.tar.gz .
# 2. 上传到服务器
scp /tmp/funstat-mcp.tar.gz atai@172.16.74.159:/tmp/
# 3. 在服务器上解压并重启
ssh atai@172.16.74.159
cd /home/atai/funstat-mcp
tar -xzf /tmp/funstat-mcp.tar.gz
cd core
bash start_server_with_env.sh
```
---
## ⚠️ 重要说明
### 网络要求
- ⚠️ **服务器无法直接访问 Telegram**,必须通过 v2ray 代理(端口 1080
- ✅ v2ray 代理已配置并运行正常
- ✅ 服务已配置使用 socks5://127.0.0.1:1080 代理
### 代理依赖
如果代理服务停止Telegram 连接将失败。检查代理状态:
```bash
ssh atai@172.16.74.159
ps aux | grep v2ray
ss -tuln | grep 1080
```
### Session 文件
- 路径: ~/telegram_sessions/funstat_bot.session
- 大小: 72KB
- 权限: 600 (仅所有者可读写)
- ⚠️ 包含登录凭证,务必保管好
### 防火墙
- 当前状态: inactive (无防火墙限制)
- 端口 8091 对所有网络开放
- 如需限制访问,可配置 ufw 规则
---
## 📊 访问日志示例
服务器日志显示已有外部访问:
```
INFO: 172.16.72.87:61462 - "GET /sse HTTP/1.1" 406 Not Acceptable
INFO: 172.16.74.159:58984 - "GET /sse HTTP/1.1" 406 Not Acceptable
INFO: 172.16.72.87:61532 - "GET /sse HTTP/1.1" 200 OK
```
- 406 响应: 正常,表示客户端未发送正确的 Accept 头
- 200 响应: 成功建立 SSE 连接
---
## 🛡️ 安全建议
1. ✅ Session 文件已设置权限保护 (600)
2. ✅ .env 文件包含敏感信息,不要提交到 Git
3. ⚠️ 服务监听 0.0.0.0,建议配置防火墙限制访问 IP
4. ⚠️ 定期备份 session 文件
5. ⚠️ 确保 v2ray 代理服务稳定运行
### 推荐的防火墙配置(可选)
```bash
sudo ufw allow from <your-ip>/32 to any port 8091
sudo ufw enable
```
---
## 📞 技术支持
如遇问题,按以下顺序排查:
1. **服务未启动**
```bash
cd /home/atai/funstat-mcp/core
bash start_server_with_env.sh
```
2. **无法连接 Telegram**
- 检查 v2ray 代理: `ps aux | grep v2ray`
- 检查代理端口: `ss -tuln | grep 1080`
- 查看服务日志: `tail -50 /tmp/funstat_sse.log`
3. **Session 文件锁定**
```bash
pkill -9 python3
sleep 2
cd /home/atai/funstat-mcp/core
bash start_server_with_env.sh
```
4. **依赖包缺失**
```bash
cd /home/atai/funstat-mcp
source .venv/bin/activate
pip install -r requirements.txt
```
---
## ✅ 验证清单
部署完成后,确认以下项目:
- [x] 服务进程正在运行
- [x] 端口 8091 正在监听
- [x] Telegram 连接成功
- [x] SSE 端点响应正常
- [x] 日志文件正常记录
- [x] 可从外部访问(如果网络可达)
---
**部署完成时间**: 2025-11-02
**状态**: ✅ 成功运行
**下次维护**: 定期检查日志和代理状态