nodejs pm2 进程管理工具使用指南


nodejs pm2 进程管理工具使用指南

引言

nodeJS 发展的今天,无疑是一个巨大的成功。虽然目前还比不上服务端的 JAVA、PHP等语言,但是谁能保证明天呢?~!

pm2 简介

PM2.5是一个内置的负载平衡器Node.js应用生产过程管理。它允许您永久地保存应用程序,并在不停机的情况下重新加载它们

Install PM2

npm i -g pm2

使用方式

您可以使用命令的方式启动一个项目。但是本文推荐使用配置文件的方式启动项目。先说下命令吧。

重要的事情来了 如何使用配置文件~~~~

配置文件

Eg:

{
"apps" : [{
         "name":"test",

      "cwd":"/data/wwwroot/nodejs",

      "script":"./test.sh",

      "exec_interpreter":"bash",

      "min_uptime": "60s",

      "max_restarts": 30,

      "exec_mode" :"cluster_mode",

      "error_file" :"./test-err.log",

      "out_file":"./test-out.log",

      "pid_file":"./test.pid"

      "watch": false
}]
}

Eg 描述
Name String App 程序名称
Script String App.js 主程序入口
Cwd String “/data/wwwroot/nodejs” 启动目录
Args String “-a 13 -b 12” 包含所有通过CLI脚本字符串参数
Interpreter S “/usr/bin/python” 启动脚本相 默认 nodejs
interpreter_args S ”–harmony”
node_args S interpreter_args 的别名
instances N -1 启动应用程序数目
exec_mode S “cluster” 启动模式 可以是 “cluster” or “fork” 默认 fork
watch S || Array true 启用监听功能
ignore_watch A [”[/\]./”, “node_modules”] 忽略的监听项
max_memory_restart S '150M' 程序超过指定内存就重新启动
env Obj {“NODE_ENV”: “development”, “ID”: “42”} 环境变量
Env_ obj {“NODE_ENV”: “production”, “ID”: “89”}
source_map_support Boolean true 默认true 启动 source Map
instance_var S “NODE_APP_INSTANCE”
log_date_format S “YYYY-MM-DD HH:mm Z” 日志的日期格式
error_file S 错误日志路径
out_file S 输出文件的路径
combine_logs Boolean
merge_logs Boolean combine_logs的别名
pid_file S
min_uptime S 最小运行时间
listen_timeout N 8000 如果程序没有监听 则会自动重启
kill_timeout N 1600
wait_ready

官网详细地址

http://pm2.keymetrics.io/docs/usage/application-declaration/#advanced-features


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM