zhibo/部署指南-1.15.149.240.md
2025-12-30 17:28:20 +08:00

279 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 直播系统部署指南
## 服务器信息
- **IP地址**: 1.15.149.240
- **部署目录**: /opt/zhibo
## 需要部署的服务
| 服务 | 端口 | 说明 |
|------|------|------|
| Admin API | 30001 | 管理后台API |
| Front API | 8081 | 前端/APP API |
| Admin Web | 80 | 管理后台界面 |
---
## 第一步:上传文件到服务器
### 方法1使用SCP命令推荐
打开PowerShell或CMD在项目根目录执行
```powershell
# 1. 创建服务器目录
ssh root@1.15.149.240 "mkdir -p /opt/zhibo/{admin-api,front-api,admin-web,logs,scripts}"
# 2. 上传Admin API JAR包
scp Zhibo/zhibo-h/crmeb-admin/target/Crmeb-admin.jar root@1.15.149.240:/opt/zhibo/admin-api/
# 3. 上传Front API JAR包
scp Zhibo/zhibo-h/crmeb-front/target/Crmeb-front.jar root@1.15.149.240:/opt/zhibo/front-api/
# 4. 上传前端文件
scp -r Zhibo/admin/dist/* root@1.15.149.240:/opt/zhibo/admin-web/
```
### 方法2使用SFTP工具
使用FileZilla、WinSCP等工具连接服务器手动上传
- `Zhibo/zhibo-h/crmeb-admin/target/Crmeb-admin.jar``/opt/zhibo/admin-api/`
- `Zhibo/zhibo-h/crmeb-front/target/Crmeb-front.jar``/opt/zhibo/front-api/`
- `Zhibo/admin/dist/` 目录下所有文件 → `/opt/zhibo/admin-web/`
---
## 第二步SSH登录服务器配置
```bash
ssh root@1.15.149.240
```
### 2.1 创建启动脚本
```bash
# 创建Admin API启动脚本
cat > /opt/zhibo/scripts/start-admin-api.sh << 'EOF'
#!/bin/bash
APP_NAME="Crmeb-admin"
JAR_FILE="/opt/zhibo/admin-api/${APP_NAME}.jar"
LOG_FILE="/opt/zhibo/logs/admin-api.log"
# 停止旧进程
pid=$(pgrep -f "${APP_NAME}.jar")
[ -n "$pid" ] && kill -9 $pid && echo "停止旧进程: $pid" && sleep 2
# 启动
nohup java -Xms512m -Xmx1024m -jar $JAR_FILE \
--spring.redis.host=127.0.0.1 \
> $LOG_FILE 2>&1 &
echo "Admin API 启动成功,端口: 30001"
EOF
# 创建Front API启动脚本
cat > /opt/zhibo/scripts/start-front-api.sh << 'EOF'
#!/bin/bash
APP_NAME="Crmeb-front"
JAR_FILE="/opt/zhibo/front-api/${APP_NAME}.jar"
LOG_FILE="/opt/zhibo/logs/front-api.log"
# 停止旧进程
pid=$(pgrep -f "${APP_NAME}.jar")
[ -n "$pid" ] && kill -9 $pid && echo "停止旧进程: $pid" && sleep 2
# 启动
nohup java -Xms512m -Xmx1024m -jar $JAR_FILE \
--spring.redis.host=127.0.0.1 \
> $LOG_FILE 2>&1 &
echo "Front API 启动成功,端口: 8081"
EOF
# 创建一键启动脚本
cat > /opt/zhibo/scripts/start-all.sh << 'EOF'
#!/bin/bash
echo "启动所有服务..."
/opt/zhibo/scripts/start-admin-api.sh
sleep 5
/opt/zhibo/scripts/start-front-api.sh
echo "完成!"
EOF
# 创建停止脚本
cat > /opt/zhibo/scripts/stop-all.sh << 'EOF'
#!/bin/bash
pkill -f "Crmeb-admin.jar" && echo "Admin API 已停止"
pkill -f "Crmeb-front.jar" && echo "Front API 已停止"
EOF
# 赋予执行权限
chmod +x /opt/zhibo/scripts/*.sh
```
### 2.2 配置Nginx
```bash
# 创建Nginx配置
cat > /etc/nginx/conf.d/zhibo.conf << 'EOF'
# 管理后台
server {
listen 80;
server_name _;
root /opt/zhibo/admin-web;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
# Admin API代理
location /api/admin/ {
proxy_pass http://127.0.0.1:30001/api/admin/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /api/public/ {
proxy_pass http://127.0.0.1:30001/api/public/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
# Front API (供APP调用)
server {
listen 8080;
server_name _;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket支持
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
}
EOF
# 测试并重载Nginx
nginx -t && systemctl reload nginx
```
---
## 第三步:启动服务
```bash
# 启动所有服务
/opt/zhibo/scripts/start-all.sh
# 查看日志
tail -f /opt/zhibo/logs/admin-api.log
tail -f /opt/zhibo/logs/front-api.log
# 检查端口
netstat -tlnp | grep -E "30001|8081"
```
---
## 第四步:验证部署
### 检查服务状态
```bash
# 检查进程
ps aux | grep -E "Crmeb-admin|Crmeb-front"
# 检查端口
ss -tlnp | grep -E "30001|8081|80|8080"
```
### 测试接口
```bash
# 测试Admin API
curl http://localhost:30001/api/public/version
# 测试Front API
curl http://localhost:8081/api/front/index
```
---
## 访问地址
| 服务 | 地址 |
|------|------|
| 管理后台 | http://1.15.149.240 |
| Admin API | http://1.15.149.240:30001 |
| Front API | http://1.15.149.240:8081 |
| Front API (Nginx) | http://1.15.149.240:8080 |
---
## 常用命令
```bash
# 启动所有服务
/opt/zhibo/scripts/start-all.sh
# 停止所有服务
/opt/zhibo/scripts/stop-all.sh
# 单独启动Admin API
/opt/zhibo/scripts/start-admin-api.sh
# 单独启动Front API
/opt/zhibo/scripts/start-front-api.sh
# 查看日志
tail -100f /opt/zhibo/logs/admin-api.log
tail -100f /opt/zhibo/logs/front-api.log
```
---
## APP配置
部署完成后需要修改Android APP的API地址
文件:`android-app/app/src/main/java/com/example/livestreaming/net/ApiConfig.java`
```java
public static final String BASE_URL = "http://1.15.149.240:8081/";
```
然后重新编译APK。
---
## 故障排查
### 服务启动失败
```bash
# 查看详细日志
cat /opt/zhibo/logs/admin-api.log
cat /opt/zhibo/logs/front-api.log
# 检查Java版本
java -version # 需要JDK 1.8
# 检查Redis是否运行
redis-cli ping
```
### 端口被占用
```bash
# 查看端口占用
lsof -i :30001
lsof -i :8081
# 杀掉占用进程
kill -9 <PID>
```