简体   繁体   English

Monit守护程序每60秒会失效一次Node.js

[英]Daemonized Node.js fails every 60 seconds with Monit

Gurus of SO SO大师

I am running Node.js as a daemon using monit & it turns out that it fails every 60 seconds on the dot. 我正在使用monit将Node.js作为守护程序运行,事实证明它每60秒在该点上失败一次。 Here's my monit.log 这是我的monit.log

root@mybox:/etc/monit# tail -f /var/log/monit.log
[UTC Sep  4 12:07:50] info     : 'nodejs' start: /sbin/start
[UTC Sep  4 12:08:50] error    : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8000] via TCP
[UTC Sep  4 12:08:50] info     : 'nodejs' trying to restart
[UTC Sep  4 12:08:50] info     : 'nodejs' stop: /sbin/stop
[UTC Sep  4 12:08:50] info     : 'nodejs' start: /sbin/start
[UTC Sep  4 12:09:50] error    : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8000] via TCP
[UTC Sep  4 12:09:50] info     : 'nodejs' trying to restart
[UTC Sep  4 12:09:50] info     : 'nodejs' stop: /sbin/stop
[UTC Sep  4 12:09:50] info     : 'nodejs' start: /sbin/start
[UTC Sep  4 12:10:50] info     : 'nodejs' connection succeeded to INET[127.0.0.1:8000] via TCP

Here's my monit config from monitrc 这是我的monitrc的monit配置

set logfile /var/log/monit.log

check host nodejs with address 127.0.0.1
    start program = "/sbin/start nodeapp"
    stop program  = "/sbin/stop nodeapp"
    if failed port 8000 protocol HTTP
        request /
        with timeout 10 seconds
    then restart

Am I doing something wrong in this configuration or is there some other reason Node seems to fail so regularly? 我在此配置中做错什么了吗,或者是否有其他原因导致Node经常失败? Where else should I look to pinpoint this problem? 我还应该在哪里寻找这个问题?

Thank you. 谢谢。

First make sure that the application doesn't crash after multiple requests. 首先,请确保该应用程序在多次请求后不会崩溃。 A good way to do is this with ab (apache benchmark). 一个很好的方法是使用ab(Apache基准)。 If you're sure that your code is stable then it likely an issue with Monit. 如果您确定代码稳定,那么Monit可能有问题。

ab -c 10 -n 1000 http://127.0.0.1:8000/

Seems you want to run NodeJS as service using Monitrc. 似乎您想使用Monitrc将NodeJS作为服务运行。 If you use Ubuntu, then you should consider using Runit. 如果使用Ubuntu,则应考虑使用Runit。 I have use it on Amazon EC2 nearly 3 month without any restart and it's stable. 我已经在Amazon EC2上使用了将近3个月,没有任何重新启动,并且它很稳定。

Here are guide for running NodeJS as service : 这是将NodeJS作为服务运行的指南:

http://www.yodi.me/blog/2011/09/05/run-nodejs-in-ubuntu-11-dot-04-ec2-with-user-permission-and-run-as-service/ http://www.yodi.me/blog/2011/09/05/run-nodejs-in-ubuntu-11-dot-04-ec2-with-user-permission-and-run-as-service/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM