pm2一键部署
# SSH免登陆
ssh-keygen -t rsa -C "samyit@qq.com"
1
把本地的pub key上传到服务器的authorized_keys,注意空格及换行;
source .zshrc
修改端口及免登陆;
sudo service ssh restart
sudo service sshd restart
1
2
2
# PM2一键部署
拷贝待部署的服务器pub key 放入到git库ssh的后台配置中;
# 安装git
sudo apt-get install git
git --version
git config --global user.name samy
git config --global user.email "samyit@qq.com"
git config --list
1
2
3
4
5
2
3
4
5
# nodejs及相关库
#node安装
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
source .bashrc
nvm install 10
#cnpm安装
npm install -g cnpm --registry=https://registry.npm.taobao.org
#pm2安装
cnpm i -g pm2
#bee安装
go get github.com/beego/bee
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
由于安装了部分软件pm2 bee,本地还识别不了,故后得重启下服务器;
sudo reboot
1
# pm2部署命令
常用部署命令:
pm2 deploy deploy.json stage setup
pm2 deploy deploy.json stage
//可能会出现不识别的bash;
//修改.barshrc中的一个ls;注释掉;
1
2
3
4
5
2
3
4
5
package.json
"scripts": {
"bin": "node_modules/egg-scripts/bin/egg-scripts.js",
"build": "pkg . -t node8-win-x64 --out-path ./pkg -d",
"build:linux": "pkg . -t node8-linux-x64 --out-path ./pkg",
"build:mac": "pkg . -t node8-mac-x64 --out-path ./pkg -d",
"docker": "egg-scripts start --title=egg-server-etag --sticky",
"start": "egg-scripts start --daemon --title=egg-server-etag --sticky",
"stop": "egg-scripts stop --title=egg-server-etag",
"dev": "egg-bin dev --sticky --port 7082 --workers=1",
"debug": "egg-bin debug",
"test": "standard --fix && standard && egg-bin test --timeout 600000",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "standard && egg-bin cov",
"doc": "apidoc -i ./app -o public/doc",
"web": "cd web && npm run build:prod",
"fix": "standard --fix && standard",
"autod": "autod"
},
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
deploy.json
{
"apps" : [
{
"name" : "etag",
"script" : "etag/",
"env": {
"COMMON_VARIABLE": "true"
},
"env_production" : {
"NODE_ENV": "production",
"PORT": 7082
}
}
],
"deploy" : {
"stage" : {
"user" : "samy",
"host" : "102.108.111.xxx",
"port" : "96xx",
"ref" : "origin/master",
"repo" : "git@github.com:samyxx/etag-cloud.git",
"path" : "/home/samy/deploy/etag-cloud",
"post-deploy" : "cd etag-adm && cnpm install && npm stop && npm run dev &"
},
"dev": {
"user": "samy",
"host": "192.168.11.158",
"port": "22",
"ref": "origin/dev",
"repo": "git@github.com:xxx-intl/etag-cloud.git",
"path": "/home/samy/deploy/etag-cloud",
"post-deploy": "cd etag-adm && cnpm install && npm stop && npm start"
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
上次更新: 2022/04/15, 05:41:31