The PM2 is a process manager for a node app with load-balancing capabilities.
PM2 is perfect when you want to take advantage of all of your standalone code on all the CPUs on the server and ensure that the process is always alive, with 0 seconds of overloading. It is ideal for IaaS architectures, but not for PAAs scenarios (which will then develop PAAs solutions).
Note: SaaS, PAAs, and IaaS are cloud service models.
SaaS Software-as-a-service, such as Google's Gmail mailbox service. For app users.
PaaS platform-as-a-service. Google's Gae, for example, for development users
IaaS Infrastructure as a service, such as Amazon's Aws,iaas, is useful for startups that don't know how successful a new application/website will be.
Please refer toCloud service Model: SaaS, PAAs and IaaS, which one is right for you?
Key Features:
built-in load balancer (using node cluster cluster module)
running in the background
0 Seconds of downtime overload, I understand the general meaning is that maintenance upgrades do not require downtime.
start-up scripts with Ubuntu and CentOS
Stop an unstable process (avoid infinite loops)
Console Detection
provide HTTP API
remote control and real-time interface API (Nodejs module, allows interaction with PM2 process Manager)
tested Nodejs v0.11 v0.10 v0.8 version, compatible with Coffeescript, based on Linux and MacOS.
installation
NPM install-g PM2
Usage
$ npm Install pm2-g # command-line installation PM2
$ PM2 Start App.js-i 4 #后台运行pm2, start 4 x app.js
# You can also pass the ' max ' argument to start
# The correct number of processes depends on the number of cores in the CPU
$ pm2 Start app.js--name My-api # naming process
$ PM2 List # shows all process states
$ PM2 Monit # Monitor All Processes
$ PM2 Logs # show all process logs
$ pm2 Stop all # stops all processes
$ pm2 Restart all # restart all processes
$ pm2 Reload All # 0 seconds Downtime Heavy process (for networked process)
$ pm2 Stop 0 # stops the specified process
$ pm2 Restart 0 # Restart the specified process
$ PM2 Startup # generates INIT script to keep the process alive
$ PM2 Web # runs the robust computer API endpoint (http://localhost:9615)
$ pm2Delete0 # kills the specified process
$ pm2DeleteAll # kills All processes
Different ways to run a process:
$ pm2 start App.js-i Max # starts the maximum number of processes based on the number of active CPUs
$ PM2 Start App.js-i 3 # start 3 processes
$ pm2 Start app.js-x #用fork模式启动 app.js instead of using cluster
$ PM2 Start App.js-x---a 23 # start app.js with fork mode and pass parameters (-a 23)
$ pm2 Start app.js--name ServerOne # Start a process and name it ServerOne
$ pm2 Stop ServerOne # stop ServerOne process
$ pm2 Start App.json # START process, set options in App.json
$ pm2 Start App.js-i Max---a #在--pass parameters to App.js
$ pm2 Start app.js-i max-e err.log-o Out.log # Start and generate a profile
You can also execute apps written in other languages (fork mode):
$ pm2 start my-bash-script.sh-x--interpreter bash
$ pm2 start my-python-script.py-x--interpreter python
0-second shutdown Overload:
This feature allows you to reload the code without losing the requested connection.
Note:
can only be used for Web applications
running in node 0.11.x version
run in cluster mode (default mode)
$ PM2 Reload All
Coffeescript:
$ PM2 Start My_app.coffee #这就是全部
PM2 ready for the product level service?
Just test on your server
$ git clone https://Github.com/unitech/pm2.git
$ CD PM2
NPM Install # or NPM install--dev if devdependencies is not installed
$ NPM Test
PM2 List
Lists all the process information that is managed by PM2, and also shows how many times a process will be started because of unhandled exceptions.
PM2 Monit monitor the CPU and memory usage of each node process.
NODE.JS--PM2 Introduction