155 lines
2.8 KiB
Markdown
155 lines
2.8 KiB
Markdown
# 系统服务安装指南
|
|
|
|
## 快速安装(推荐)
|
|
|
|
```bash
|
|
cd /home/ubuntu/nanocode/weixin-nanobot-bridge
|
|
|
|
# 1. 安装服务
|
|
sudo ./scripts/install-service.sh
|
|
|
|
# 2. 启动服务
|
|
sudo systemctl start weixin-nanobot-bridge
|
|
|
|
# 3. 检查状态
|
|
sudo systemctl status weixin-nanobot-bridge
|
|
```
|
|
|
|
## 使用管理脚本
|
|
|
|
```bash
|
|
# 查看所有命令
|
|
./scripts/manage.sh help
|
|
|
|
# 常用命令
|
|
./scripts/manage.sh start # 启动服务
|
|
./scripts/manage.sh stop # 停止服务
|
|
./scripts/manage.sh restart # 重启服务
|
|
./scripts/manage.sh status # 查看状态
|
|
./scripts/manage.sh logs # 查看日志
|
|
./scripts/manage.sh test # 测试 API
|
|
```
|
|
|
|
## 手动管理
|
|
|
|
### Bridge 服务
|
|
|
|
```bash
|
|
# 启动
|
|
sudo systemctl start weixin-nanobot-bridge
|
|
|
|
# 停止
|
|
sudo systemctl stop weixin-nanobot-bridge
|
|
|
|
# 重启
|
|
sudo systemctl restart weixin-nanobot-bridge
|
|
|
|
# 查看状态
|
|
sudo systemctl status weixin-nanobot-bridge
|
|
|
|
# 查看日志
|
|
sudo journalctl -u weixin-nanobot-bridge -f
|
|
|
|
# 开机自启
|
|
sudo systemctl enable weixin-nanobot-bridge
|
|
|
|
# 取消开机自启
|
|
sudo systemctl disable weixin-nanobot-bridge
|
|
```
|
|
|
|
### 微信适配器服务(可选)
|
|
|
|
```bash
|
|
# 安装服务
|
|
sudo ./scripts/install-weixin-service.sh
|
|
|
|
# 注意:微信服务需要先完成一次扫码登录
|
|
# 首次运行需要手动执行:
|
|
node weixin-bridge.js
|
|
# 扫码登录成功后,按 Ctrl+C 退出
|
|
# 然后再启动服务:
|
|
sudo systemctl start weixin-nanobot-adapter
|
|
```
|
|
|
|
## 验证安装
|
|
|
|
```bash
|
|
# 1. 检查服务状态
|
|
sudo systemctl status weixin-nanobot-bridge
|
|
|
|
# 2. 检查端口
|
|
lsof -i :5000
|
|
|
|
# 3. 测试 API
|
|
./scripts/manage.sh test
|
|
# 或
|
|
curl http://$(curl -s ifconfig.me):5000/health
|
|
```
|
|
|
|
## 故障排查
|
|
|
|
### 服务无法启动
|
|
|
|
```bash
|
|
# 查看详细错误
|
|
sudo journalctl -u weixin-nanobot-bridge -n 50
|
|
|
|
# 检查日志文件
|
|
tail -f logs/server.log
|
|
tail -f logs/service-error.log
|
|
```
|
|
|
|
### 端口被占用
|
|
|
|
```bash
|
|
# 查看占用进程
|
|
lsof -i :5000
|
|
|
|
# 结束占用进程
|
|
kill -9 <PID>
|
|
|
|
# 重启服务
|
|
sudo systemctl restart weixin-nanobot-bridge
|
|
```
|
|
|
|
### 权限问题
|
|
|
|
```bash
|
|
# 检查文件权限
|
|
ls -la src/server.py
|
|
|
|
# 修复权限
|
|
sudo chown -R ubuntu:ubuntu /home/ubuntu/nanocode/weixin-nanobot-bridge
|
|
```
|
|
|
|
## 卸载服务
|
|
|
|
```bash
|
|
sudo ./scripts/manage.sh uninstall
|
|
# 或手动执行:
|
|
sudo systemctl stop weixin-nanobot-bridge
|
|
sudo systemctl disable weixin-nanobot-bridge
|
|
sudo rm /etc/systemd/system/weixin-nanobot-bridge.service
|
|
sudo systemctl daemon-reload
|
|
```
|
|
|
|
## 系统启动顺序
|
|
|
|
开机后自动启动顺序:
|
|
1. 网络服务启动
|
|
2. nanobot 启动(如果已配置)
|
|
3. weixin-nanobot-bridge 启动
|
|
4. weixin-nanobot-adapter 启动(如果已配置)
|
|
|
|
## 监控检查
|
|
|
|
可以添加定时检查:
|
|
|
|
```bash
|
|
# 添加到 crontab
|
|
crontab -e
|
|
|
|
# 添加以下行(每5分钟检查一次)
|
|
*/5 * * * * curl -sf http://localhost:5000/health || sudo systemctl restart weixin-nanobot-bridge
|
|
```
|