• 使用Gunicorn和nginx进行Flask服务部署


    Gunicorn  ‘Green Unicorn’ 是一个 UNIX 下的 WSGI HTTP 服务器

    在 Gunicorn 上运行 Flask 应用

    修改下面myproject为自己的服务文件名即可

    $ gunicorn myproject:app

    使用如下命令即可启动多个应用实例:

    $ gunicorn -w 4 -b 127.0.0.1:4000 myproject:app  

    输出如下内容代表服务创建成功:

    [2020-02-11 14:50:24 +0800] [892] [INFO] Starting gunicorn 20.0.4
    [2020-02-11 14:50:24 +0800] [892] [INFO] Listening at: http://0.0.0.0:5555 (892)
    [2020-02-11 14:50:24 +0800] [892] [INFO] Using worker: sync
    [2020-02-11 14:50:24 +0800] [895] [INFO] Booting worker with pid: 895
    [2020-02-11 14:50:24 +0800] [896] [INFO] Booting worker with pid: 896
    [2020-02-11 14:50:24 +0800] [898] [INFO] Booting worker with pid: 898
    [2020-02-11 14:50:24 +0800] [899] [INFO] Booting worker with pid: 899

    使用Nginx进行负载均衡

    修改配置文件:修改服务端口的url即可

    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    # Load dynamic modules. See /usr/share/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
        server
        {
            listen 5556; # nginx端口
            server_name localhost;
            location / {
                proxy_pass http://localhost:5555/run; 
                #服务端口的url,将当前请求代理到URL参数指定的服务器上,URL可以是主机名或者IP地址加PORT的形式
      } } }

    多机负载:

    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    # Load dynamic modules. See /usr/share/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
            upstream my.net{  
         #my.net是自定义的,在server结构中引用即可 #代理服务器为 两台机器192.168.22.136 192.168.22.147 # server servername:port server 192.168.22.136:80 max_fails=1 fail_timeout=300s; server 192.168.22.147:80 max_fails=1 fail_timeout=300s; } server { listen 5556; # nginx端口 server_name localhost; location / { proxy_pass http:mynet; } } }

    从配置文件启动: 

    sudo nginx -c nginx.conf
    凤舞九天
  • 相关阅读:
    对用户控件(ascx)属性(property)赋值
    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
    图片淡入淡出切换效果
    在用户控件(ASCX)创建用户控件(ASCX)
    Login failed for user 'xxx'
    一些较好的书
    儿子购买的书
    怀念以前做网管的日子
    Linux下selinux简单梳理
    Rsync同步时删除多余文件 [附:删除大量文件方法的效率对比]
  • 原文地址:https://www.cnblogs.com/ywheunji/p/14310444.html
Copyright © 2020-2023  润新知