-
Notifications
You must be signed in to change notification settings - Fork 94
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
node的部署方案 #43
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pm2
安装pm2
新建一份
index.js
测试,运行以下命令测试运行
你可以执行以下命令来重启和暂停服务
比如
pm2 stop index.js
,暂停上面的index.js
服务自动重启
当文件改动则自动重启服务
这里是监控整个项目的文件,如果只想监听指定文件和目录,建议通过下面配置文件的
watch、ignore_watch
字段来设置配置文件
编写一份
ecosystem.json
文件,完整配置说明请参考官方文档配置完后你可以执行以下命令
这里注意的是配置文件改变了之后要先
delete
再start
配置文件才能生效负载均衡
命令如下,表示开启三个进程。如果-i 0,则会根据机器当前核数自动开启尽可能多的进程
日志查看
除了可以打开日志文件查看日志外,还可以通过
pm2 logs
来查看实时日志。这点对于线上问题排查非常重要比如某个node服务突然异常重启了,那么可以通过pm2提供的日志工具来查看实时日志,看是不是脚本出错之类导致的异常重启。
内存使用超过上限自动重启
如果想要你的应用,在超过使用内存上限后自动重启,那么可以加上--max-memory-restart参数。(有对应的配置项)
参考文档
The text was updated successfully, but these errors were encountered: