nodejs高大上的部署方式 - PM2介绍
tag:
NodeJs
P(rocess)M(anager)2:一个内置负载均衡功能的Node.js应用的进程管理器。
它可以让你的应用永远保持活着,0秒重载,促进常见的系统管理任务。
在生产模式中启动一个应用程序是一样容易的:
$ pm2 start app.js
PM2是不断被超过1000的测试。 官方网站:http://pm2.keymetrics.io/
在Linux上运行(稳定)和MacOSX(稳定)和Windows(稳定)。
安装PM2
$ npm install pm2 -g
# Or install the V2 release candidate //或安装V2版本
$ npm install pm2@next -g
主要特点
命令概述
$ npm install pm2 -g # 安装PM2
$ pm2 start app.js # 开始,守护进程和自动重新启动应用程序
$ pm2 start app.js -i 4 # 开始在集群模式的应用实例4
# 它将负载平衡网络查询到每个应用程序
$ pm2 start app.js --name="api" # 启动应用程序,并命名它“api”
$ pm2 start app.js --watch # 重启应用当文件改变时
$ pm2 start script.sh # 启动bash脚本
$ pm2 list # PM2所有进程列表
$ pm2 monit # 显示每个应用程序的内存和cpu的使用情况
$ pm2 show [app-name] # 显示某个应用程序的信息
$ pm2 logs # 显示所有应用程序的日志
$ pm2 logs [app-name] # 显示某个应用程序的日志
$ pm2 flush
$ pm2 stop all # 停止所有的应用
$ pm2 stop 0 # 停止id为1的进程
$ pm2 restart all # 重启所有应用
$ pm2 reload all # Reload all apps in cluster mode
$ pm2 gracefulReload all # Graceful reload all apps in cluster mode
$ pm2 delete all # Kill and delete all apps
$ pm2 delete 0 # Delete app with id 0
$ pm2 scale api 10 # Scale app with name api to 10 instances
$ pm2 reset [app-name] # Reset number of restart for [app-name]
$ pm2 startup # Generate a startup script to respawn PM2 on boot
$ pm2 save # Save current process list
$ pm2 resurrect # Restore previously save processes
$ pm2 update # Save processes, kill PM2 and restore processes
$ pm2 generate # Generate a sample json configuration file
$ pm2 deploy app.json prod setup # Setup "prod" remote server
$ pm2 deploy app.json prod # Update "prod" remote server
$ pm2 deploy app.json prod revert 2 # Revert "prod" remote server by 2
$ pm2 module:generate [name] # Generate sample module with name [name]
$ pm2 install pm2-logrotate # Install module (here a log rotation system)
$ pm2 uninstall pm2-logrotate # Uninstall module
$ pm2 publish # Increment version, git push and npm publish