Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM2的自动部署 #16

Open
JesseZhao1990 opened this issue Dec 18, 2017 · 0 comments
Open

PM2的自动部署 #16

JesseZhao1990 opened this issue Dec 18, 2017 · 0 comments

Comments

@JesseZhao1990
Copy link
Owner

JesseZhao1990 commented Dec 18, 2017

利用pm2自动发布

1.配置ssh免密登录

  • 查看本机是否有一对秘钥?mac 到~/.ssh目录下查看,windows到 C:\Users\zhangsan(自己的用户名).ssh
ls

id_rsa      id_rsa_vc      known_hosts  rhc.pub
id_rsa.pub  id_rsa_vc.pub  rhc

发现存在密钥对。若不存在,则生成一对

ssh-keygen -t rsa --P

  • 登录远程测试机,到用户目录下的.ssh文件夹下,查看是否有authorized_keys,没有的话创建一个
ssh root@111.231.243.123
cd ~/.ssh/
vim authorizd_keys

vim 打开authorized_keys之后,把你本机的公钥里的内容拷贝到远程机器的authorized_keys文件中,不要删除authorized_keys已有的公钥,在已有的内容的下面粘贴即可。然后保存文件。验证是否能免密登录了。

ssh root@111.231.243.123

经验证发现登录成功,没要求输入密码。此时免密登录的设置完成

2.配置文件

  • 确保本机已安装全局的pm2,下面是我本机的结果,已安装pm2,没安装的话,安装一下
npm list -g --depth=0   | grep pm2
-- pm2@2.8.0

没安装的话,全局安装一下pm2

npm install pm2 -g

  • 生成配置文件
pm2 ecosystem

  • 修改配置文件,根据自己的需求修改配置文件,可以指定登录的用户名,登录的机器,拉取的仓库和分支,项目存放路径,和发布之前干什么事,拉取代码之后干什么事。具体配置看官方文档。

3.发布

  • 在本项目的根目录下,运行创建环境的命令
pm2 deploy ecosystem.config.js dev setup

  • 发布命令
pm2 deploy ecosystem.config.js dev

学习pm2的deploy,详情请进入

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant