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)
$ pm2 Delete 0 # kills the specified process
$ pm2 Delete all # 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)
$ 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 cloneHttps://github.com/Unitech/pm2.git
$ cd PM2
npm Install # or NPM install--dev if devdependencies is not installed
$ NPM Test
PM2 Nodejs Study (i)