pm2的經常使用操做命令

1、簡介
PM2是node進程管理工具,能夠利用它來簡化不少node應用管理的繁瑣任務,如性能監控、自動重啓、負載均衡等,並且使用很是簡單。node

2、前期必備
node 環境python

3、安裝
全局安裝web

npm install -g pm2

4、經常使用命令npm

$ npm install pm2 -g     # 命令行安裝 pm2 
$ pm2 start app.js -i 4  # 後臺運行pm2,啓動4個app.js 
                         # 也能夠把'max' 參數傳遞給 start
                         # 正確的進程數目依賴於Cpu的核心數目
$ pm2 start app.js --name my-api # 命名進程
$ pm2 list               # 顯示全部進程狀態
$ pm2 monit              # 監視全部進程
$ pm2 logs               # 顯示全部進程日誌
$ pm2 stop all           # 中止全部進程
$ pm2 restart all        # 重啓全部進程
$ pm2 reload all         # 0 秒停機重載進程 (用於 NETWORKED 進程)
$ pm2 stop 0             # 中止指定的進程
$ pm2 restart 0          # 重啓指定的進程
$ pm2 startup            # 產生 init 腳本 保持進程活着
$ pm2 web                # 運行健壯的 computer API endpoint (http://localhost:9615)
$ pm2 delete 0           # 殺死指定的進程
$ pm2 delete all         # 殺死所有進程
運行進程的不一樣方式

$ pm2 start app.js -i max    # 根據有效CPU數目啓動最大進程數目
$ pm2 start app.js -i 3      # 啓動3個進程
$ pm2 start app.js -x        #用fork模式啓動 app.js 而不是使用 cluster
$ pm2 start app.js -x -- -a 23   # 用fork模式啓動 app.js 而且傳遞參數 (-a 23)
$ pm2 start app.js --name serverone  # 啓動一個進程並把它命名爲 serverone
$ pm2 stop serverone       # 中止 serverone 進程
$ pm2 start app.json        # 啓動進程, 在 app.json裏設置選項
$ pm2 start app.js -i max -- -a 23                   #在--以後給 app.js 傳遞參數
$ pm2 start app.js -i max -e err.log -o out.log  # 啓動 並 生成一個配置文件
你也能夠執行用其餘語言編寫的app  ( fork 模式):
$ pm2 start my-bash-script.sh    -x --interpreter bash
$ pm2 start my-python-script.py -x --interpreter python

但願你們喜歡,也但願你們指點錯誤,也能夠加入qq羣439667347,你們一塊兒討論,一塊兒進步,後續更新中...json

相關文章
相關標籤/搜索