设置如下

设置如下

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

我在 RHEL 6.5 上设置了高可用性。我的 Stack 是

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. x.x.x.x (main machine)
2. y.y.y.y (slave machine)

共享存储

1. /apps (SAN)

/apps 在两台机器上均可用作共享存储

运行 django + uwsgi 的应用程序

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

uwsgi 配置

[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 设置中运行?

答案1

我不会在 HA 设置中运行 uwsgi。只需让 nginx 与本地 uwsgi 通信,并在带有 pacemaker 或 loadbalander 的 HA 设置中运行 nginx。

相关内容