auto-deploy-demo/DEPLOYMENT.md

132 lines
2.1 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.

# 快速部署系统 - 部署文档
## 系统要求
- Node.js 18.0 或更高版本
- npm 9.0 或更高版本
- 腾讯云服务器 (推荐配置: 2核4G)
## 一、服务器环境配置
### 1. 安装 Node.js
```bash
# 使用 nvm 安装 Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 18
nvm use 18
```
### 2. 安装 PM2 (进程管理器)
```bash
npm install -g pm2
```
### 3. 配置防火墙
```bash
# 开放系统端口
firewall-cmd --permanent --add-port=8888/tcp
firewall-cmd --permanent --add-port=9000-9100/tcp
firewall-cmd --reload
```
### 4. 腾讯云安全组配置
在腾讯云控制台配置安全组规则:
- 开放 8888 端口 (管理界面)
- 开放 9000-9100 端口范围 (部署的项目)
## 二、项目部署
### 1. 上传项目代码
```bash
# 将项目上传到服务器
scp -r auto-deploy-demo root@your-server-ip:/opt/
```
### 2. 安装依赖
```bash
cd /opt/auto-deploy-demo
# 安装后端依赖
npm install
# 安装前端依赖并构建
cd client
npm install
npm run build
cd ..
```
### 3. 配置环境变量
创建 `.env` 文件:
```bash
cat > .env << EOF
PORT=8888
JWT_SECRET=your-secure-secret-key-change-this
HOST=your-server-ip
EOF
```
### 4. 启动服务
```bash
# 使用 PM2 启动
pm2 start server/index.js --name "deploy-system"
# 设置开机自启
pm2 startup
pm2 save
```
### 5. 验证部署
访问 `http://your-server-ip:8888` 检查系统是否正常运行。
## 三、Nginx 反向代理配置 (可选)
如需使用域名访问,可配置 Nginx
```nginx
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://127.0.0.1:8888;
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;
}
}
```
## 四、常见问题
### Q: 端口被占用怎么办?
检查端口占用:
```bash
lsof -i :8888
```
### Q: 如何查看日志?
```bash
pm2 logs deploy-system
```
### Q: 如何重启服务?
```bash
pm2 restart deploy-system
```