RuoYi/deploy/README.md

124 lines
2.5 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.

# RuoYi 自动发布配置指南
## 原理
```
你 push 代码到 Gitee
Gitee 发送 Webhook 到服务器 :9000/webhook
webhook.py 验证签名 + 过滤 master 分支
触发 deploy.sh: git pull → mvn build → 停旧 → 启新
```
## 第一步:上传文件到服务器
在本地 `deploy/` 目录执行:
```bash
scp deploy.sh root@47.94.224.255:/opt/ruoyi/
scp webhook.py root@47.94.224.255:/opt/ruoyi/
scp ruoyi-webhook.service root@47.94.224.255:/etc/systemd/system/
```
## 第二步SSH 登录服务器配置
```bash
ssh root@47.94.224.255
```
### 2.1 设置脚本权限
```bash
chmod +x /opt/ruoyi/deploy.sh
chmod +x /opt/ruoyi/webhook.py
```
### 2.2 启动 Webhook 服务
```bash
systemctl daemon-reload
systemctl enable ruoyi-webhook
systemctl start ruoyi-webhook
systemctl status ruoyi-webhook
```
### 2.3 验证 Webhook 运行
```bash
curl http://localhost:9000/health
# 应返回: OK
```
### 2.4 开放防火墙端口(如有)
```bash
# 检查防火墙
firewall-cmd --state 2>/dev/null || echo "防火墙未运行"
# 如果需要开放
firewall-cmd --add-port=9000/tcp --permanent
firewall-cmd --reload
```
**阿里云安全组也需要放行 9000 端口**(入方向)。
## 第三步:配置 Gitee Webhook
1. 打开 https://gitee.com/zhangYuXinGit/system
2. 进入 **管理 → WebHooks**
3. 点击 "添加 WebHook"
4. 填写:
- **URL**: `http://47.94.224.255:9000/webhook`
- **密码**: `ruoyi-deploy-2024`
- **事件**: 勾选 "Push"(只选 Push 就够了)
5. 点击 "添加",然后点击 "测试" 验证连接
## 第四步:测试自动发布
在本地修改代码并推送:
```bash
cd E:\java\project\system
# 修改一些代码...
git add .
git commit -m "test: 测试自动发布"
git push
```
然后在服务器查看部署日志:
```bash
ssh root@47.94.224.255 "tail -f /opt/ruoyi/deploy.log"
```
## 常用运维命令
```bash
# 查看 webhook 日志
tail -f /opt/ruoyi/webhook.log
# 查看部署日志
tail -f /opt/ruoyi/deploy.log
# 查看应用日志
tail -f /opt/ruoyi/app.log
# 重启 webhook 服务
systemctl restart ruoyi-webhook
# 手动触发部署(不走 webhook
ssh root@47.94.224.255 "/opt/ruoyi/deploy.sh"
# 停止自动发布
systemctl stop ruoyi-webhook
systemctl disable ruoyi-webhook
```
## 安全建议
- 生产环境建议将 Webhook URL 改为 HTTPS
- 可修改 `webhook.py` 中的 `WEBHOOK_SECRET` 更换密钥
- 可在阿里云安全组中限制 9000 端口仅允许 Gitee 的 IP 访问