zoukankan      html  css  js  c++  java
  • django+uwsgi+nginx实现负载均衡

    一、部署设备:

    nginx服务器:192.168.110.128(转交设备)

    uwsgi服务器:192.168.110.129/130/131(负载设备)

    二、环境配置:

    1、django环境(192.168.110.129/130/131)

    #系统环境
    yum
    install -y gcc-c++ yum install -y vim yum update eple-release
    #pip安装
    yum install -y python3-pip
    #python3安装
    yum install -y python3
    #虚拟环境安装
    pip install virtualenv pip isntall virtualenvwrapper #配置虚拟环境 cd vim ~/.bashrc 行末加入: VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh #立即生效
    source
    ~/.bashrc #创建虚拟环境:
    mkvirtualenv dj_nginx
    workon dj_nginx pip
    install -r requirements.txt
    #uwsgi安装:
    yum install -y python-dev.x86-64
    pip isntall uwsgi
    #搜集静态文件
    python manage.py collectstatic
    #关闭防火墙
    systemctl stop firewalld

     2、uwsgi.ini配置(192.168.110.129/130/131)

    [uwsgi]
    #使用nginx连接时使用
    socket=192.168.110.129:8082
    #直接做web服务器使用
    http=192.168.10.129:8080
    #项目目录
    chdir=/home/xxx
    #项目中wsgi.py文件的目录,相对于项目目录
    wsgi-file=xxx/wsgi.py
    processes=8
    threads=16
    buffer-size = 65536*1024*1024*1024
    master=True
    pidfile=uwsgi.pid
    daemonize=uwsgi.log
    virtualenv=/root/.virtualenvs/xxx

    3、nginx.conf配置(192.168.110.128)

      1 #user  nobody;
      2 worker_processes  8;
      3 worker_rlimit_nofile 65535;
      4 
      5 #error_log  logs/error.log;
      6 #error_log  logs/error.log  notice;
      7 #error_log  logs/error.log  info;
      8 
      9 #pid        logs/nginx.pid;
     10 
     11 
     12 events {
     13     worker_connections  65535;
     14     use epoll;
     15     multi_accept on;
     16 }
     17 
     18 http {
     19     include       mime.types;
     20     default_type  application/octet-stream;
     21 
     22     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
     23     #                  '$status $body_bytes_sent "$http_referer" '
     24     #                  '"$http_user_agent" "$http_x_forwarded_for"';
     25 
     26     #access_log  logs/access.log  main;
     27 
     28     sendfile        on;
     29     #tcp_nopush     on;
     30 
     31     #keepalive_timeout  0;
     32     keepalive_timeout  65;
     33 
     34     #gzip  on;
     35 
     42     upstream monitor {
     43         server 192.168.110.128:8082;
     44         server 192.168.110.129:8082;
     45         server 192.168.110.130:8082;
     46         server 192.168.110.131:8082;
     47     }
     48 
     95     server {
     96             listen       8080;
     97             server_name  localhost;
     98 
     99             location /{
    100                 include uwsgi_params;
    101                 uwsgi_pass monitor;
    102             }
    103 
    104             location /static{
    106                 alias /var/www/monitor/static;
    107             }
    108 
    109             error_page   500 502 503 504  /50x.html;
    110             location = /50x.html {
    111             root   html;
    112             }
    113     }
    114 }
  • 相关阅读:
    学习笔记_2012_4_13垃圾回收原理与String类的学习
    第五篇
    HTML练习代码
    上课第一天base关键字
    第四篇
    firebug使用指南
    HTML5的新特性
    UML建模
    CSS学习总结
    (转载)About me [my way]
  • 原文地址:https://www.cnblogs.com/Fmaj7/p/13259960.html
Copyright © 2011-2022 走看看