uwsgi + Django与nginx:高可用性设置

从https://stackoverflow.com/questions/25304968/uwsgi-django-with-nginx-high-availability-setup移到这里。

我在RHEL 6.5上设置了高可用性 我的堆栈是

1. uwsgi 2. nginx 3. django 4. Pacemaker 

现在我明白了,可以通过监视nginx_status轻松设置nginx

  location /nginx_status { # Turn on nginx stats stub_status on; access_log off; # Security: Only allow access from 192.168.1.100 IP # allow 127.0.0.1; # Send rest of the world to /dev/null # deny all; } 

这将确保nginx的心跳监视。

但是,我的问题是如何确保uwsgi将处于运行状态,以便当第二个nginx机器启动时它会识别uwsgi进程并将其绑定到它。 或者,如果uwsgi发生故障,如何确保将其恢复并重新绑定到nginx

设置如下

假设集群机器:

 1. xxxx (main machine) 2. yyyy (slave machine) 

共享存储

 1. /apps (SAN) 

/两台机器都可用作共享存储

运行django + uwsgi的应用程序

 1. virtualenv : /apps/venv 2. applicaiton in : /apps 3. uwsgi configuration in : /apps/config.d 4. running application : /apps/project 

uwsgiconfiguration

 [uwsgi] # the base directory (full path) chdir = /apps/project # Django's wsgi file module = project.wsgi # the virtualenv (full path) home = /apps/venv # process-related settings # master master = true # maximum number of worker processes processes = 4 # the socket (use the full path to be safe socket = /tmp/project.sock # ... with appropriate permissions - may be needed chmod-socket = 666 # clear environment on exit vacuum = true #daemonize daemonize = true #logging logger = file:/tmp/uwsgi.log 

我不知道uwsgi如何在HA安装中运行?

我不会在HA安装中运行uwsgi。 只要让nginx和本地的uwsgi交谈,然后在带有心脏起搏器或loadbalander的HA设置中运行nginx。