添加组
groupadd -g 1037 nodeGroup //添加一个id为1037名为nodeGroup的组
useradd node -u [uid] -g [xxx] -m -d /data/node
// 添加名为node的用户到gid为xxx的组 -m 自动建立目录
// -d 指定用户登录时的目录
1.检测本机是否安装了node
node -v (若输出版本号,则说明已安装)
2.安装node环境(如果已安装请跳到下一步)
在/usr/local/src下,下载node安装包
wget http://nodejs.org/dist/v11.5.0/node-v11.5.0-linux-x64.tar.xz
解压: tar -xf node-v11.5.0-linux-x64.tar.xz
cd node-v11.5.0-linux-x64
cp -r ./lib/node_modules/ /usr/local/lib/
cp -r ./include/node /usr/local/include/
mkdir -p /usr/local/man/man1/
cp ./share/man/man1/node.1 /usr/local/man/man1/
cp ./bin/node /usr/local/bin/
ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
3.全局安装pm2
npm install --global gulp
4.把项目压缩包放到/home/node下(已建好组和用户),假设项目压缩包名为wy.zip
解压:unzip wy.zip
mkdir conf
mkdir log
mkdir pids
cd wy
安装依赖项:npm install
gulp
cd ..
5.现在/home/node下是这样的
wy wy.zip conf log pid
6.编写pm2启动的配置文件
cd conf
vi wy.json
7.配置文件的内容为:
{
"apps": [
{
"name": "wy",
"cwd": "/home/node/wy",
"script": "bin/www",
"log_date_format": "YYYY-MM-DD HH:mm:ss.SSS",
"error_file": "/home/node/log/error.log",
"out_file": "/home/node/log/wy.log",
"pid_file": "/home/node/pids/wy.pid",
"min_uptime": "60s",
"max_restarts": 15,
"ignore_watch" : ["node_modules"],
"merge_logs": false,
"exec_interpreter": "node",
"exec_mode": "fork",
"autorestart": true,
"vizion": false
}
]
}
8.保存后,目前在/home/node/conf目录下
启动:pm2 start wy.json
查看启动状态:pm2 list
可能出现的问题
1.npm安装的时候出现错误
npm http GET https://registry.npmjs.org/supervisor
npm http GET https://registry.npmjs.org/supervisor
npm http GET https://registry.npmjs.org/supervisor
npm ERR! Error: CERT_NOT_YET_VALID
npm ERR! at SecurePair.<anonymous> (tls.js:1370:32)
npm ERR! at SecurePair.EventEmitter.emit (events.js:92:17)
npm ERR! at SecurePair.maybeInitFinished (tls.js:982:10)
npm ERR! at CleartextStream.read [as _read] (tls.js:469:13)
错误为:Error: CERT_NOT_YET_VALID 解决方案:
npm config set strict-ssl false
- pm2 list后,进程状态为error
到/home/node/log下查看日志文件
1.可能是端口被占用
2.pm2的配置文件错误
3.其他问题
网友评论