pm2

本文详细介绍PM2进程管理器的使用方法,包括安装、启动、监控、日志管理和部署等核心功能。PM2能够帮助开发者轻松管理Node.js和Python应用,实现自动重启、负载均衡和零秒停机重载等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

General 
$ npm install pm2 -g            # Install PM2 
$ pm2 start app.js              # Start, Daemonize and auto-restart application (Node) 
$ pm2 start app.py              # Start, Daemonize and auto-restart application (Python) 
$ pm2 start npm -- start        # Start, Daemonize and auto-restart Node application 
 
# Cluster Mode (Node.js only) 
$ pm2 start app.js -i 4         # Start 4 instances of application in cluster mode 
                                # it will load balance network queries to each app 
$ pm2 reload all                # Zero Second Downtime Reload 
$ pm2 scale [app-name] 10       # Scale Cluster app to 10 process 
 
# Process Monitoring 
$ pm2 list                      # List all processes started with PM2 
$ pm2 list --sort=<field>       # Sort all processes started with PM2 
$ pm2 monit                     # Display memory and cpu usage of each app 
$ pm2 show [app-name]           # Show all information about application 
 
# Log management 
$ pm2 logs                      # Display logs of all apps 
$ pm2 logs [app-name]           # Display logs for a specific app 
$ pm2 logs --json               # Logs in JSON format 
$ pm2 flush
$ pm2 reloadLogs
 
# Process State Management 
$ pm2 start app.js --name="api" # Start application and name it "api" 
$ pm2 start app.js -- -a 34     # Start app and pass option "-a 34" as argument 
$ pm2 start app.js --watch      # Restart application on file change 
$ pm2 start script.sh           # Start bash script 
$ pm2 start app.json            # Start all applications declared in app.json 
$ pm2 reset [app-name]          # Reset all counters 
$ pm2 stop all                  # Stop all apps 
$ pm2 stop 0                    # Stop process with id 0 
$ pm2 restart all               # Restart all apps 
$ pm2 gracefulReload all        # Gracefully reload all apps in cluster mode 
$ pm2 delete all                # Kill and delete all apps 
$ pm2 delete 0                  # Delete app with id 0 
 
# Startup/Boot management 
$ pm2 startup                   # Detect init system, generate and configure pm2 boot on startup 
$ pm2 save                      # Save current process list 
$ pm2 resurrect                 # Restore previously saved processes 
$ pm2 unstartup                 # Disable and remove startup system 
 
$ pm2 update                    # Save processes, kill PM2 and restore processes 
$ pm2 init                      # Generate a sample js configuration file 
 
# Deployment 
$ 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 
# Module system 
$ 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 

https://www.npmjs.com/package/pm2/v/2.10.1#commands-cheatsheet

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值