配置pm2自動部署前,請確保已經可以ssh免密登陸服務器。html
1、建立ecosystem.jsongit
{ "apps" : [{ "name" : "HTTP-API", "script" : "http.js" }], "deploy" : { // "production" is the environment name "production" : { "user" : "ubuntu", "host" : ["192.168.0.13"],
"port" : "11111", "ref" : "origin/master", "repo" : "git@github.com:Username/repository.git", "path" : "/var/www/my-repository"
"ssh_options" : "StrictHostKeyChecking=no",
"post-deploy": "npm install && pm2 startOrRestart ecosystem.json --env production"
}, } }
2、github
經過以下命令初始化服務器npm
pm2 deploy ecosystem.json production setup
每次本地代碼更改後提交到遠程倉庫後執行以下命令更新線上程序json
pm2 deploy ecosystem.json production