pm2 基础使用

发表于 node 分类,标签:

版本信息

作者时间主要变更内容链接
吴惟刚2022年4月18日http://wuweigang.com/?id=369

pm2 是什么?

pm2是node进程管理工具, 可以将程序运行在后台,不受终端影响。

node 应用普通启动方式:

1
node app.js

这种方式关闭终端就结束进程;

pm2可以后台运行,终端关闭不影响。

1
pm2 start app.js

pm2 安装

1
2
3
4
5
6
7
// npm方式
npm  instal pm2 -g

// cnpm方式
cnpm  instal pm2 -g
// yarn方式
yarn global  add pm2

更新pm2

  1. 更新pm2版本

1
2
3
4
5
// npm方式
npm  instal pm2@latest -g

// cnpm方式
cnpm  instal pm2@latest -g

  1. 更新内存

1
pm2 update

pm2 常用命令

开始应用

1
2
3
4
5
6
7
8
// node  js
pm2  start  app.js
//  sh 文件
pm2 start app.sh
//  其他1
pm2 start app.py  --watch
// 其他2
pm2 start binary-file  --port  1520

启动后会对应出现一个表

idnamenamespaceversionmodepiduptimerestartsstatuscpumemuserwatching
0hexo_rundefault0.0.0fork227548m0online0%26mbrootdisabled
1mockdefault1.0.0fork777046m0online0%26.2mbrootdisabled












以下命令中用到的 name,id 就是上面表中对应的

停止应用

1
pm2  stop  name|id|all

重启应用

1
pm2  restart  name|id|all

删除应用

1
pm2  delete  name|id|all

重载应用

restart会中断服务,而reload不会

1
pm2  reload  name|id|all

查看当前运行的应用

1
pm2 list |ls|status

查看某一个进程的详细信息

1
pm2 show name|id

查看日志

1
2
pm2  logs
pm2 logs --lines 200

官方站点

0 篇评论

发表我的评论