node 使用pm2管理node服务

1. How to run command in backend?

$ nohup npm start &
or
$ npm start &
$ disown

参考 https://unix.stackexchange.com/questions/3886/difference-between-nohup-disown-and

 

2. pm2 (好好看看教程 https://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/)

Install - https://pm2.keymetrics.io/

log位置 ~/.pm2/logs,查看xxx-error.log或者xxx-out.log

// 启动和重启
pm2 start --name pinpoint-backend ./dist/main.js
pm2 restart pinpoint-backend

// 列出任务
pm2 list


// 日志分片
pm2 install pm2-logrotate

pm2 set pm2-logrotate:max_size 50M
pm2 set pm2-logrotate:max_size YYYY-MM-DD
pm2 set pm2-logrotate:compress true
pm2 set pm2-logrotate:rotateInterval '0 0 * * *'
pm2 set pm2-logrotate:retain 30

pm2 restart all

3. node 内存问题 JavaScript heap out of memory

// https://futurestud.io/tutorials/pm2-how-to-start-your-app-with-node-js-v8-arguments
// https://futurestud.io/tutorials/pm2-start-node-js-app-with-increased-memory-limit-from-json-configuration#:~:text=js%20file%20located%20within%20the,memory%20limit%20of%208%20GB

// max-old-space-size OR max_old_space_size, I don't know.
pm2 start --node-args="--max_old_space_size=4096" --name pinpoint-backend ./dist/main.js

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值