nodejs deployment configuration pm2

Tall on the first node on the deployment of ways:

Directly node appto start, if the error could stop the entire operation directly,

supervisor feel that it is brought as a development environment.

There seems most common online deployment nodejs project are forever, pm2 both.

Use:

 

  • supervisor development environment is used.
  • forever manage multiple sites, each site has little traffic, no monitoring.
  • pm2 site visit than the larger, require a complete monitoring interface

 

pm2 main features:

 

  • Built-in load balancing (using Node cluster cluster module)
  • Background process
  • 0 seconds off Overload, I understand the general idea is to maintain the upgrade when no downtime.
  • Ubuntu and CentOS has a startup script
  • Stop unstable process (to avoid infinite loop)
  • Console Detection
  • Provide HTTP API
  • Remote control and real-time interface API (Nodejs module allows administrators to interact and PM2 process 

 

Use npm / cnpm global installation:

npm install -g pm2

pm2 command (more project directory use):

$ pm2 start app.js  Start app project

$ pm2 list Listed by all processes pm2 information management, but also a display process will be started many times, not because of abnormal processing.

 

$ pm2 monit Each node monitors the process of CPU and memory usage

$ pm2 logs Show all processes log

$ pm2 stop all Stop all processes

$ pm2 restart all Restart all processes

$ pm2 reload all 0Second stop overloading process (for NETWORKED process)

$ pm2 stop 0 Stop the specified process

$ pm2 restart 0 Restart the specified process

$ pm2 startup Produce init script to keep the process alive

$ pm2 web Run robust computer API endpoint (http: // localhost: 9615)

$ pm2 delete 0 Kill the specified process

$ pm2 delete all Kill all processes

 

Way to start the process in more detail:

$ pm2 start app.js -i max Start the maximum number of processes based on the number of valid CPU

$ pm2 start app.js -i 3 Start three processes

$ pm2 start app.js -x Start with a fork app.js mode instead of using cluster

$ pm2 start app.js -x -- -a 23 App.js start mode and with a fork passing parameters (-a 23)

$ pm2 start app.js --name serverone Start a process and named it serverone

$ pm2 stop serverone Stop serverone process

$ pm2 start app.json Start the process, set options in the app.json

$ pm2 start app.js -i max -- -a 23 In - after passing parameters to app.js

$ pm2 start app.js -i max -e err.log -o out.log Start and generate a configuration file

Pm2 startup configuration file:

You can pm2 start processes.jsonbe started.

Add File processes.json in the project root directory:

{
 "apps": [
 {
  "name": "mywork",
  "cwd": "/srv/node-app/current",
  "script": "bin/xxx",
  "log_date_format": "YYYY-MM-DD HH:mm:ss",
  "error_file": "/var/log/node-app/node-app.stderr.log",
  "out_file": "log/node-app.stdout.log",
  "pid_file": "pids/node-geo-api.pid",
  "instances": 6,
  "min_uptime": "200s",
  "max_restarts": 10,
  "max_memory_restart": "1M",
  "cron_restart": "1 0 * * *",
  "watch": false,
  "merge_logs": true,
  "exec_interpreter": "node",
  "exec_mode": "fork",
  "autorestart": false,
  "vizion": false
 }
 ]
}

processes.json Description:

  • apps: json structure, apps is an array, each array member corresponding application is running in a pm2
  • name: Application Name
  • cwd: the directory where the application
  • script: script path of the application
  • log_date_format:
  • error_file: custom application error log file
  • out_file: custom application log files
  • pid_file: custom application pid file
  • instances:
  • min_uptime: The minimum running time set here is that, if the application exits 60s in the 60s, pm2 will assume the program quit unexpectedly, this time triggered restart set the number of max_restarts
  • max_restarts: Sets the number of applications quit unexpectedly restart, the default 15 times (counting from 0)
  • cron_restart: time to start to solve the problem can be resolved to restart
  • watch: whether to enable monitoring mode, the default is false. If set to true, when the application changes, pm2 will automatically reload. Here you can also set the file you want to monitor.
  • merge_logs:
  • exec_interpreter: script type of application, shell used here, the default is nodejs
  • exec_mode: application startup mode, set here is cluster_mode (clusters), the default is fork
  • Automatically restart when enabling / disabling application crashes or exits: autorestart
  • vizion: Enable / disable vizion characteristics (version control)

 

Start command can also write in package.json in:

"scripts": {
"start": "node ./bin/xxx",
"pm2":"pm2 start processes.json"
},

 

Guess you like

Origin www.cnblogs.com/minutes/p/11020130.html