在網上找到pm2.目前彷佛最多見的線上部署nodejs項目的有forever,pm2這兩種。
使用場合:node
npm install -g pm2
$ npm install -g pm2
命令行全局安裝pm2$ pm2 start app.js 或者 pm2 start bin/www
啓動node項目web
$ pm2 stop bin/www 中止pm2服務$ pm2 list
列出由pm2管理的全部進程信息,還會顯示一個進程會被啓動多少次,由於沒處理的異常。shell
$ pm2 monit
監視每一個node進程的CPU和內存的使用狀況npm
$ 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
殺死所有進程json
運行進程的不一樣方式:$ 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
啓動 並 生成一個配置文件api
在項目根目錄添加一個processes.json:
內容以下:數組
{ "apps": [ { "name": "mywork", "cwd": "/srv/node-app/current", "script": "bin/www", "log_date_format": "YYYY-MM-DD HH:mm Z", "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 } ] }
說明:app
能夠經過pm2 start processes.json
來啓動。
也能夠把命令寫在package.json裏。以下:負載均衡
經過npm run pm2
來啓動。網站