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

20190718 - PM2 #48

Open
onvno opened this issue Jul 18, 2019 · 6 comments
Open

20190718 - PM2 #48

onvno opened this issue Jul 18, 2019 · 6 comments

Comments

@onvno
Copy link
Owner

onvno commented Jul 18, 2019

@onvno
Copy link
Owner Author

onvno commented Jul 18, 2019

@onvno
Copy link
Owner Author

onvno commented Jun 23, 2020

PM2开机自启动

1.启动服务:pm2 start app.js
2.保存服务:pm2 save
3.设置开机启动:pm2 startup

centos7 可以通过systemctl查看服务状态

@onvno
Copy link
Owner Author

onvno commented Jun 23, 2020

PM2常用命令

# app指pm2创建的项目名
pm2 show app # 显示应用程序的所有信息
pm2 -h # 查看pm2帮助信息,显示命令用法
pm2 start app.js -n project # 将应用设置别名为project
pm2 list # 显示所有项目
pm2 stop app # 停止应用服务
pm2 restart app # 重启应用服务
pm2 delete app # 在进程中删除应用
pm2 status # 查看状态
pm2 monit # 查看占用的CPU和内存

@onvno
Copy link
Owner Author

onvno commented Jun 23, 2020

常见问题

Vagrant and pm2 #289
Start the same app on different ports #322
Using ansible with pm2
Cron string as argument
Restart when process reaches a specific memory amount
Sticky sessions and socket.io discussion
EACCESS - understanding pm2 user/root rights

@onvno
Copy link
Owner Author

onvno commented Jun 23, 2020

PM2配置文件

{
    "apps": {
        "name": "wuwu",                             // 项目名         
        "script": "./bin/www",                      // 执行文件
        "cwd": "./",                                // 根目录
        "args": "",                                 // 传递给脚本的参数
        "interpreter": "",                          // 指定的脚本解释器
        "interpreter_args": "",                     // 传递给解释器的参数
        "watch": true,                              // 是否监听文件变动然后重启
        "ignore_watch": [                           // 不用监听的文件
            "node_modules",
            "logs"
        ],
        "exec_mode": "cluster_mode",                // 应用启动模式,支持fork和cluster模式
        "instances": 4,                             // 应用启动实例个数,仅在cluster模式有效 默认为fork;或者 max
        "max_memory_restart": 8,                    // 最大内存限制数,超出自动重启
        "error_file": "./logs/app-err.log",         // 错误日志文件
        "out_file": "./logs/app-out.log",           // 正常日志文件
        "merge_logs": true,                         // 设置追加日志而不是新建日志
        "log_date_format": "YYYY-MM-DD HH:mm:ss",   // 指定日志文件的时间格式
        "min_uptime": "60s",                        // 应用运行少于时间被认为是异常启动
        "max_restarts": 30,                         // 最大异常重启次数,即小于min_uptime运行时间重启次数;
        "autorestart": true,                        // 默认为true, 发生异常的情况下自动重启
        "cron_restart": "",                         // crontab时间格式重启应用,目前只支持cluster模式;
        "restart_delay": "60s"                      // 异常重启情况下,延时重启时间
        "env": {
           "NODE_ENV": "production",                // 环境参数,当前指定为生产环境 process.env.NODE_ENV
           "REMOTE_ADDR": "爱上大声地"               // process.env.REMOTE_ADDR
        },
        "env_dev": {
            "NODE_ENV": "development",              // 环境参数,当前指定为开发环境 pm2 start app.js --env_dev
            "REMOTE_ADDR": ""
        },
        "env_test": {                               // 环境参数,当前指定为测试环境 pm2 start app.js --env_test
            "NODE_ENV": "test",
            "REMOTE_ADDR": ""
        }
    }
}

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