1、問題
使用阿里雲服務器時遇到一個問題,就是只能開一個命令窗口,加入運行node服務,只能起一個服務,不能啟多個服務。pm2可以解決這個問題。
2、pm2簡介
官網:https://pm2.keymetrics.io/docs/usage/quick-start/
pm2是一個進程管理工具,可以用它來管理你的node進程,並查看node進程的狀態。
(1)安裝
$ npm install pm2@latest -g # or $ yarn global add pm2
(2)啟服務
pm2 start 可執行js
pm2 start app.js --name www_itying_com
pm2 start app.js -i 3 --name www_itying_com 3 啟動 3 個進程 (自帶負載均衡)
(3)阿里雲實例
(4) 重啟服務
pm2 stop all # 停止所有進程
pm2 restart all # 重啟所有進程
pm2 reload all # 0 秒停機重載進程 (用於 NETWORKED 進程)
也可以只啟動某個應用。
(5)顯示所有進程狀態
pm2 logs
(6)殺死進程
pm2 delete 0 # 殺死指定的進程 pm2 delete all # 殺死全部進程