init: 狐蒂云活动监控项目初始化
This commit is contained in:
191
DEPLOY.md
Normal file
191
DEPLOY.md
Normal file
@@ -0,0 +1,191 @@
|
||||
# 狐蒂云活动监控 - 部署指南
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
hdy/
|
||||
├── public/ # 静态资源
|
||||
│ ├── index.html # 监控页面
|
||||
│ └── 1671896015.mp3 # 提示音频
|
||||
├── auto-buy/ # 自动抢购脚本
|
||||
│ ├── index.js
|
||||
│ ├── config.js
|
||||
│ └── package.json
|
||||
├── monitor-server.js # 主服务
|
||||
├── package.json
|
||||
└── DEPLOY.md # 本文件
|
||||
```
|
||||
|
||||
## 部署方式
|
||||
|
||||
### 方式一:直接部署(推荐)
|
||||
|
||||
#### 1. 准备环境
|
||||
- Node.js 16+
|
||||
- npm 或 yarn
|
||||
|
||||
#### 2. 安装依赖
|
||||
```bash
|
||||
# 主项目依赖
|
||||
npm install
|
||||
|
||||
# 自动抢购脚本依赖(可选)
|
||||
cd auto-buy
|
||||
npm install
|
||||
cd ..
|
||||
```
|
||||
|
||||
#### 3. 启动服务
|
||||
```bash
|
||||
# 开发模式
|
||||
npm start
|
||||
|
||||
# 生产模式(使用 PM2)
|
||||
npm install -g pm2
|
||||
pm2 start monitor-server.js --name "hdy-monitor"
|
||||
pm2 save
|
||||
pm2 startup
|
||||
```
|
||||
|
||||
#### 4. 访问
|
||||
- 本地:http://localhost:3000
|
||||
- 公网:http://你的服务器IP:3000
|
||||
|
||||
---
|
||||
|
||||
### 方式二:Docker 部署
|
||||
|
||||
#### 1. 构建镜像
|
||||
```bash
|
||||
docker build -t hdy-monitor .
|
||||
```
|
||||
|
||||
#### 2. 运行容器
|
||||
```bash
|
||||
# 前台运行
|
||||
docker run -p 3000:3000 hdy-monitor
|
||||
|
||||
# 后台运行
|
||||
docker run -d -p 3000:3000 --name hdy-monitor hdy-monitor
|
||||
|
||||
# 带自动重启
|
||||
docker run -d -p 3000:3000 --name hdy-monitor --restart always hdy-monitor
|
||||
```
|
||||
|
||||
#### 3. 查看日志
|
||||
```bash
|
||||
docker logs -f hdy-monitor
|
||||
```
|
||||
|
||||
#### 4. 停止/删除
|
||||
```bash
|
||||
docker stop hdy-monitor
|
||||
docker rm hdy-monitor
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 方式三:Docker Compose 部署
|
||||
|
||||
```bash
|
||||
# 启动
|
||||
docker-compose up -d
|
||||
|
||||
# 查看日志
|
||||
docker-compose logs -f
|
||||
|
||||
# 停止
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 方式四:Vercel/Netlify 部署(仅前端)
|
||||
|
||||
如果只需要前端页面,可以将 `public` 文件夹部署到静态托管服务。
|
||||
|
||||
但需要注意:API 功能需要单独部署后端服务。
|
||||
|
||||
---
|
||||
|
||||
## 生产环境配置
|
||||
|
||||
### 1. 修改端口
|
||||
编辑 `monitor-server.js`:
|
||||
```javascript
|
||||
const PORT = process.env.PORT || 3000;
|
||||
```
|
||||
|
||||
### 2. 配置环境变量
|
||||
创建 `.env` 文件:
|
||||
```env
|
||||
PORT=3000
|
||||
NODE_ENV=production
|
||||
```
|
||||
|
||||
### 3. 使用 Nginx 反向代理
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name your-domain.com;
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 配置 HTTPS(Let's Encrypt)
|
||||
```bash
|
||||
# 安装 Certbot
|
||||
sudo apt install certbot python3-certbot-nginx
|
||||
|
||||
# 获取证书
|
||||
sudo certbot --nginx -d your-domain.com
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 常见问题
|
||||
|
||||
### 1. 端口被占用
|
||||
```bash
|
||||
# 查找占用 3000 端口的进程
|
||||
lsof -i :3000
|
||||
|
||||
# 或修改 monitor-server.js 中的端口
|
||||
```
|
||||
|
||||
### 2. 防火墙设置
|
||||
```bash
|
||||
# Ubuntu/Debian
|
||||
sudo ufw allow 3000
|
||||
|
||||
# CentOS
|
||||
sudo firewall-cmd --permanent --add-port=3000/tcp
|
||||
sudo firewall-cmd --reload
|
||||
```
|
||||
|
||||
### 3. 云服务器安全组
|
||||
- 阿里云/腾讯云/AWS 等需要在控制台开放 3000 端口
|
||||
|
||||
---
|
||||
|
||||
## 更新部署
|
||||
|
||||
```bash
|
||||
# 拉取最新代码
|
||||
git pull
|
||||
|
||||
# 重启服务
|
||||
pm2 restart hdy-monitor
|
||||
|
||||
# 或 Docker
|
||||
docker-compose down
|
||||
docker-compose up -d
|
||||
```
|
||||
Reference in New Issue
Block a user