This is the 21st day of my participation in Gwen Challenge

PM2

PM2 is a node process management tool

role

Simplify node application management tasks such as performance monitoring, automatic restart, and load balancing

The installation

npm install -g pm2
Copy the code

Pm2 project directory introduction

├─ $HOME/.pm2 will contain All Related Files ├── $HOME/.pm2/logs Will contain All Applications $HOME/.pm2/pids will contain All Applications ├── $HOME/.pm2/pm2 /pm2 /pm2 /pm2 /pm2 /pm2 $HOME/.pm2/ RPC. Sock Socket file For Remote Commands ├─ $HOME/.pm2/pub. Sock Socket file for publishable Events ├─ $HOME/.pm2/conf.js PM2 ConfigurationCopy the code

An introduction to

Pm2. Keymetrics. IO/docs/usage /…

Common commands

  • Start the

    • pm2 start app.js –watch -i 2
    • Parameters that
      • — Watch: Monitors changes in the application directory and automatically restarts once changes occur. If you want to listen for directories that are not heard, it is best to use configuration files.
      • -i –instances: indicates the number of instances enabled for load balancing. If -i 0 or -i Max, the number of instances is determined based on the current number of machine cores.
      • –ignore-watch: excludes the listening directory/file, which can be a specific filename or a re. –ignore-watch=”test node_modules “some scripts”
      • -n –name: indicates the application name. You can use it when viewing application information.
      • -o –output: indicates the path of the standard output log file.
      • -e –error: indicates the path of the error log file.
      • – Interpreter: The interpreter Pm2 should use for Executing app (bash, python…) . Say you use coffee Script to write your app.
    • Restart pm2 restart app.js
    • Stop the pm2 stop app_name | app_id stop application-specific pm2 list available app_name and app_id pm2 stop all stop all
    • Delete pm2 delete app_id Pm2 delete all
    • View the process status pm2 list
    • View information about a process. Pm2 list app_id
  • The configuration file

  • instructions

    • The configuration items in the configuration file correspond to the command line parameters one by one.
    • Can choose yamL or JSON file, it depends on the personal wash.
    • Json-formatted configuration files, pM2 is treated as a normal JS file, so you can add comments or write code in it, which is great for dynamically adjusting the configuration.
    • If the configuration file is specified at startup, the command line parameters are ignored. (Except for individual arguments, such as –env)
  • example

  • Automatic restart

    • pm2 start app.js –watch
  • Context switching

  • Load balancing

    • Pm2 start app.js -i 3 # Start three processes
    • Pm2 start app.js -i Max # Start a process based on the number of CPU cores on the machine
  • The log view

    pm2 logs

  • Instruction TAB completion

  • Automatic startup upon startup

    • Save the current process status through pm2 Save.
    • The pm2 startup [platform] command is used to generate the automatic startup command. (Remember to check console output)
    • Paste the command generated in Step 2 to the console.
  • The incoming node args

    • The command line
      • pm2 start app.js –node-args=”–harmony”
  • The configuration file

  • Remote deployment

    • Pm2. Keymetrics. IO/docs/usage /…
  • To monitor the monitor

    • pm2 monitor
  • The system automatically restarts when the memory usage exceeds the upper limit

    • pm2 start big-array.js –max-memory-restart 20M
  • Update the pm2

    • $pm2 save # Remember to save the process state
    • $ npm install
    • pm2 -g $ pm2 update
  • pm2+nginx

    • Pm2. Keymetrics. IO/docs/tutori…
  • On-line monitoring system

  • Pm2 programming interface

  • Module extension system