使用pm2管理系统进程
tags: 网站
修改日期:2019年01月22日
版本:v1.0
作者:whl
[toc]
一、安装pm2
# 安装pm2
npm i -g pm2
# 检验安装
pm2 ls
[root@whl-bwg-dc3 ~]# pm2 ls
-------------
__/\\\\\\\\\\\\\\\\\\\\\\\\\\____/\\\\\\\\____________/\\\\\\\\____/\\\\\\\\\\\\\\\\\\_____
_\\/\\\\\\/////////\\\\\\_\\/\\\\\\\\\\\\________/\\\\\\\\\\\\__/\\\\\\///////\\\\\\___
_\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\//\\\\\\____/\\\\\\//\\\\\\_\\///______\\//\\\\\\__
_\\/\\\\\\\\\\\\\\\\\\\\\\\\\\/__\\/\\\\\\\\///\\\\\\/\\\\\\/_\\/\\\\\\___________/\\\\\\/___
_\\/\\\\\\/////////____\\/\\\\\\__\\///\\\\\\/___\\/\\\\\\________/\\\\\\//_____
_\\/\\\\\\_____________\\/\\\\\\____\\///_____\\/\\\\\\_____/\\\\\\//________
_\\/\\\\\\_____________\\/\\\\\\_____________\\/\\\\\\___/\\\\\\/___________
_\\/\\\\\\_____________\\/\\\\\\_____________\\/\\\\\\__/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_
_\\///______________\\///______________\\///__\\///////////////__
Runtime Edition
PM2 is a Production Process Manager for Node.js applications
with a built-in Load Balancer.
Start and Daemonize any application:
$ pm2 start app.js
Load Balance 4 instances of api.js:
$ pm2 start api.js -i 4
Monitor in production:
$ pm2 monitor
Make pm2 auto-boot at server restart:
$ pm2 startup
To go further checkout:
http://pm2.io/
-------------
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
┌──────────┬────┬─────────┬──────┬─────┬────────┬─────────┬────────┬─────┬─────┬──────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
└──────────┴────┴─────────┴──────┴─────┴────────┴─────────┴────────┴─────┴─────┴──────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
[root@whl-bwg-dc3 ~]#
二、使用pm2管理进程
# 启动进程
# node.js
pm2 start app.js --name=server
# python
pm2 start test.py --name=python-test --interpreter=pythion3
# prometheus
pm2 start prometheus --name=prometheus -- --config.file=prometheus.yml
三、常用命令
# 创建进程并命名
pm2 start app.js --name=server
# 重启进程
pm2 restart server
# 停止进程
pm2 stop server
# 查看进程日志
pm2 log server
# 监控所有进程
pm2 monit
# 以指定解释器启动进程
pm2 start test.py --interpreter=python3
# 以指定参数启动进程
pm2 start test.py -- --config=config.ini
四、PM集群模式
//TODO