
sudo yum install nodejs npm
sudo npm install -g pm2
module.exports = {
apps: [
// 测试环境 - 工具版本
{
name: 'quicking-web-dev',
instances: 1,
exec_mode: 'fork', // 改为 fork 模式而不是 cluster
cwd: '/home/ec2-user/server/quicking-h5',
script: './server/index.mjs',
interpreter: '/usr/bin/node', // 或者实际的 node 路径
log_date_format: 'YYYY-MM-DD HH:mm Z',
error_file: './logs/err.log',
out_file: './logs/out.log',
log_file: './logs/combined.outerr.log',
time: true,
autorestart: true,
max_restarts: 10,
min_uptime: '10s',
max_memory_restart: '2G',
watch: false,
ignore_watch: ['node_modules', 'logs', '.nuxt', '.output'],
env: {
PORT: 6999
}
},
// 测试环境 - 社交版本
{
name: 'earning-web-dev',
instances: 1,
exec_mode: 'fork', // 改为 fork 模式而不是 cluster
cwd: '/home/ec2-user/server/quicking-h5',
script: './server/index.mjs',
args: 'start',
log_date_format: 'YYYY-MM-DD HH:mm Z',
error_file: './logs/err.log',
out_file: './logs/out.log',
log_file: './logs/combined.outerr.log',
time: true,
autorestart: true,
max_restarts: 10,
min_uptime: '10s',
max_memory_restart: '2G',
watch: false,
ignore_watch: ['node_modules', 'logs', '.nuxt', '.output'],
env: {
PORT: 6888
}
},
// 正式环境 - 工具版本
{
name: 'quicking-web',
instances: 1,
exec_mode: 'fork', // 改为 fork 模式而不是 cluster
cwd: '/home/ec2-user/server/quicking-h5',
script: './server/index.mjs',
args: 'start',
log_date_format: 'YYYY-MM-DD HH:mm Z',
error_file: './logs/err.log',
out_file: './logs/out.log',
log_file: './logs/combined.outerr.log',
time: true,
autorestart: true,
max_restarts: 10,
min_uptime: '10s',
max_memory_restart: '2G',
watch: false,
ignore_watch: ['node_modules', 'logs', '.nuxt', '.output'],
env: {
PORT: 6999
}
},
// 正式环境 - 社交版本
{
name: 'earning-web',
instances: 1,
exec_mode: 'fork', // 改为 fork 模式而不是 cluster
cwd: '/home/ec2-user/server/quicking-h5',
script: './server/index.mjs',
args: 'start',
log_date_format: 'YYYY-MM-DD HH:mm Z',
error_file: './logs/err.log',
out_file: './logs/out.log',
log_file: './logs/combined.outerr.log',
time: true,
autorestart: true,
max_restarts: 10,
min_uptime: '10s',
max_memory_restart: '2G',
watch: false,
ignore_watch: ['node_modules', 'logs', '.nuxt', '.output'],
env: {
PORT: 6888
}
}
]
}
rm -rf /home/ec2-user/server/quicking-h5/; mkdir /home/ec2-user/server/quicking-h5/; mkdir /home/ec2-user/server/quicking-h5/logs/; tar -zxvf /home/ec2-user/server/quicking-h5-bf/dist.tgz -C /home/ec2-user/server/quicking-h5; cd /home/ec2-user/server/quicking-h5 pm2 delete quicking-web #PORT=6999 pm2 start server/index.mjs --name quicking-web pm2 start /home/ec2-user/server/quicking-h5/ecosystem.config.cjs --only quicking-web
# 启动应用
pm2 start ecosystem.config.cjs
# 启动应用并指定名称
pm2 start aecosystem.config.cjs --name my-app
# 启动应用并监听文件变化(开发模式)
pm2 start ecosystem.config.cjs --watch
# 启动应用并指定实例数(集群模式)
pm2 start ecosystem.config.cjs -i max
# 从 package.json 启动
pm2 start npm --name "my-app" -- start
# 列出所有应用
pm2 list
pm2 ls
pm2 status
# 查看特定应用信息
pm2 show app-name
# 监控所有应用
pm2 monit
# 停止应用
pm2 stop app-name
pm2 stop all
# 重启应用
pm2 restart app-name
pm2 restart all
# 重载应用(零停机重启)
pm2 reload app-name
pm2 reload all
# 删除应用
pm2 delete app-name
pm2 delete all
# 查看所有应用日志
pm2 logs
# 查看特定应用日志
pm2 logs app-name
# 查看最后 N 行日志
pm2 logs --lines 200
# 清空日志
pm2 flush
# 以 JSON 格式输出日志
pm2 logs --json
# 查看系统信息
pm2 show pm2
# 生成启动脚本
pm2 startup
# 保存当前进程列表
pm2 save
# 恢复保存的进程列表
pm2 resurrect
# 更新 PM2
pm2 update
# 查看详细的应用信息
pm2 show app-name
# 查看 PM2 自身日志
pm2 logs pm2
# 检查 PM2 版本和状态
pm2 --version
pm2 info
# 重置 PM2(清除所有应用)
pm2 kill
生成中...
感谢您的支持与鼓励
您的支持是我们前进的动力

期待您的精彩留言!
成为第一个评论的人吧 ✨