Tools: Essential Guide: 在VPS上部署MySQL数据库:性能优化指南
在VPS上部署MySQL数据库:性能优化指南
为什么部署总是这么难?
我的部署清单(照着做不会错)
步骤1:创建云服务器
步骤2:连接服务器
步骤3:安装 Node.js
步骤4:部署应用
步骤5:使用 PM2 保持运行
步骤6:配置防火墙 第一次部署项目的时候,我在服务器上折腾了8个小时。现在回想起来,如果当时有人告诉我这些坑,20分钟就能搞定。 今天我把完整的部署流程整理出来,保证你看完就能上手,不走弯路。 说实话,部署这事儿最坑的不是技术难度,而是: 这是我总结的部署 checklist,每次部署都过一遍: 点击 "Create Droplet",等待1分钟 现在访问 http://your_server_ip,你的应用已经在线了! 使用 DigitalOcean 的 $4/月套餐: Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse
$ ssh root@your_server_ip
ssh root@your_server_ip
ssh root@your_server_ip
# 更新系统
-weight: 500;">apt -weight: 500;">update && -weight: 500;">apt -weight: 500;">upgrade -y # 安装 Node.js 20.x
-weight: 500;">curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
-weight: 500;">apt -weight: 500;">install -y nodejs # 验证安装
node --version
-weight: 500;">npm --version
# 更新系统
-weight: 500;">apt -weight: 500;">update && -weight: 500;">apt -weight: 500;">upgrade -y # 安装 Node.js 20.x
-weight: 500;">curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
-weight: 500;">apt -weight: 500;">install -y nodejs # 验证安装
node --version
-weight: 500;">npm --version
# 更新系统
-weight: 500;">apt -weight: 500;">update && -weight: 500;">apt -weight: 500;">upgrade -y # 安装 Node.js 20.x
-weight: 500;">curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
-weight: 500;">apt -weight: 500;">install -y nodejs # 验证安装
node --version
-weight: 500;">npm --version
# 克隆你的项目
-weight: 500;">git clone https://github.com/your-username/your-project.-weight: 500;">git
cd your-project # 安装依赖
-weight: 500;">npm -weight: 500;">install # 启动应用
-weight: 500;">npm -weight: 500;">start
# 克隆你的项目
-weight: 500;">git clone https://github.com/your-username/your-project.-weight: 500;">git
cd your-project # 安装依赖
-weight: 500;">npm -weight: 500;">install # 启动应用
-weight: 500;">npm -weight: 500;">start
# 克隆你的项目
-weight: 500;">git clone https://github.com/your-username/your-project.-weight: 500;">git
cd your-project # 安装依赖
-weight: 500;">npm -weight: 500;">install # 启动应用
-weight: 500;">npm -weight: 500;">start
# 安装 PM2
-weight: 500;">npm -weight: 500;">install -g pm2 # 启动应用
pm2 -weight: 500;">start app.js --name "my-app" # 设置开机自启
pm2 startup
pm2 save
# 安装 PM2
-weight: 500;">npm -weight: 500;">install -g pm2 # 启动应用
pm2 -weight: 500;">start app.js --name "my-app" # 设置开机自启
pm2 startup
pm2 save
# 安装 PM2
-weight: 500;">npm -weight: 500;">install -g pm2 # 启动应用
pm2 -weight: 500;">start app.js --name "my-app" # 设置开机自启
pm2 startup
pm2 save
# 允许 HTTP 和 HTTPS
ufw allow 80
ufw allow 443
ufw allow 22
ufw -weight: 500;">enable
# 允许 HTTP 和 HTTPS
ufw allow 80
ufw allow 443
ufw allow 22
ufw -weight: 500;">enable
# 允许 HTTP 和 HTTPS
ufw allow 80
ufw allow 443
ufw allow 22
ufw -weight: 500;">enable - 教程都过时了:去年的教程,今年的系统版本已经变了
- 漏了关键步骤:防火墙、权限、环境变量,少一个都不行
- 本地能跑,服务器就挂:端口占用、路径不对、依赖缺失 - 忘了开防火墙端口,调试了2小时才发现
- 用 root 用户跑应用,被黑客攻击了
- 没配置进程守护,服务器重启后应用就挂了 - 一个 DigitalOcean 账号(点击注册获取 $200 免费额度)
- 一个 Node.js 项目 - 登录 DigitalOcean 控制台
- 点击 "Create" → "Droplets"
- 选择配置: 镜像:Ubuntu 22.04 LTS
套餐:Basic $4/月(足够小项目使用)
数据中心:选择离你最近的
SSH Key:添加你的公钥(推荐)
- 镜像:Ubuntu 22.04 LTS
- 套餐:Basic $4/月(足够小项目使用)
- 数据中心:选择离你最近的
- SSH Key:添加你的公钥(推荐)
- 点击 "Create Droplet",等待1分钟 - 镜像:Ubuntu 22.04 LTS
- 套餐:Basic $4/月(足够小项目使用)
- 数据中心:选择离你最近的
- SSH Key:添加你的公钥(推荐) - 安装 Nginx 反向代理
- 配置 SSL 证书(Let's Encrypt)
- 设置 CI/CD 自动部署