我创建了一个upstart脚本,以便守护node.js应用程序:
description "app_name"
start on startup
stop on shutdown
script
export HOME="/home/ubuntu/nodeapp"
exec sudo -u nodejs /usr/local/bin/node $HOME/app/server.js production 2>>/var/log/app_name.error.log >>/var/log/app_name.log
end script
我的monit脚本如下:
check host app_name with address 127.0.0.1
start "/sbin/start app_name"
stop "/sbin/stop app_name"
if failed port 80 protocol HTTP
request /ok
with timeout 5 seconds
then restart
它工作正常,但现在我想将nginx作为负载均衡器添加到上游,如下所示:
upstream cluster1 {
least_conn;
server 127.0.0.1:8000;
server 127.0.0.1:8001;
}
server {
listen 0.0.0.0:80;
location / {
proxy_pass http://cluster1;
}
}
那么我应该如何更改upstart和monit脚本以支持它呢?
答案 0 :(得分:0)
你应该创建三个monit检查,一个用于nginx,一个用于每个nodejs实例:
check host nginx with address 127.0.0.1
start "/sbin/start nginx"
stop "/sbin/stop nginx"
if failed port 80 protocol HTTP
request /ok
with timeout 5 seconds
then restart
check host app_name_on_8000 with address 127.0.0.1
start "/sbin/start app_name_on_8000"
stop "/sbin/stop app_name_on_8000"
if failed port 8000 protocol HTTP
request /ok
with timeout 5 seconds
then restart
check host app_name_on_8001 with address 127.0.0.1
start "/sbin/start app_name_on_8001"
stop "/sbin/stop app_name_on_8001"
if failed port 8000 protocol HTTP
request /ok
with timeout 5 seconds
then restart
这将在nodejs实例失败时重新启动,nginx如果失败或两个nodejs实例都关闭