創(chuàng)建配置項(xiàng)
在你的git倉(cāng)庫(kù)根目錄中新建pm2配置文件ecosystem.config.js,如注釋所示,或者執(zhí)行pm2 init初始化文件ecosystem.config.js。
module.exports = {
apps : [{
//pm2名字
name: "nextcn",
//pm2運(yùn)行腳本
script: "./app.js",
//環(huán)境變量
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}],
deploy: {
// "production" is the environment name
production: {
// 服務(wù)器端SSH key 地址, 默認(rèn) $HOME/.ssh
key: "$HOME/.ssh",
// SSH user 需配置
user: "root",
// SSH host 需配置
host: ["47.98.138.195"],
// SSH options with no command-line flag, see 'man ssh'
// can be either a single string or an array of strings
ssh_options: "StrictHostKeyChecking=no",
// GIT remote/branch
ref: "origin/master",
// GIT ssh遠(yuǎn)程地址 需配置
repo: "git@github.com:raoenhui/next-site-cn.git",
// 放入服務(wù)器端地址 需配置
path: "/ice/pm2",
// Pre-setup command or path to a script on your local machine
"pre-setup": "echo 'This is a pre-setup command'",
// Post-setup commands or path to a script on the host machine
// eg: placing configurations in the shared dir etc
"post-setup": "ls -la",
// pre-deploy action
"pre-deploy-local": "echo 'This is a pre-deploy-local command'",
// post-deploy action
"post-deploy": "npm install && pm2 reload ecosystem.config.js --env production'"
},
}
}
安裝
pm2 deploy production setup
服務(wù)器上的git版本需要在v1.8以上,否則fetch不成功,代碼更新不了??蓞⒄?a target="_blank" rel="nofollow">CENTOS安裝高版本GIT
image.png
更新
pm2 deploy production update
回滾
pm2 deploy production revert 1
可查看提交記錄,回滾到想要的版本
pm2 deploy production list
強(qiáng)制提交
pm2 deploy production --force
當(dāng)你代碼有修改但是不想提交時(shí)可以強(qiáng)制發(fā)布
參考資料
Happy coding .. :)
