zoukankan      html  css  js  c++  java
  • centos7 + nginx+django 运行环境

    1、easy_install和pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的
    首先安装easy_install
    下载地址:https://pypi.python.org/pypi/ez_setup
    tar -zxf ez_setup-0.9.tar.gz
    cd ez_setup-0.9
    python ez_setup.py
    安装好easy_install 之后 再安装pip
    下载地址:https://pypi.python.org/pypi/pip
    tar -zxf pip-8.1.2.tar.gz
    cd pip-8.1.2
    python setup.py install
    
    
    2、安装 supervisor, 一个专门用来管理进程的工具
    pip install supervisor
    3、关闭防火墙
    临时关闭防火墙
    systemctl stop firewalld
     
    或者 开放需要的端口
    firewall-cmd --zone=public --add-port=80/tcp --permanent
    firewall-cmd --reload
    4. 使用 gunicorn / uwsgi 来部署 (二选一)
    4.1 使用 gunicorn
    pip install gunicorn
    在项目目录下运行下面的命令进行测试:
    gunicorn -w4 -b0.0.0.0:8001 zqxt.wsgi
    -w 表示开启多少个worker,-b 表示要使用的ip和port,我们这里用的是 80010.0.0.0代表监控电脑的所有 ip。
    
    4.2 使用 uwsgi
    pip install uwsgi
    使用 uwsgi 运行项目
    uwsgi --http :8001 --chdir /path/to/project --home=/path/to/env --module project.wsgi
    5、 使用supervisor来管理进程
    pip install supervisor
    echo_supervisord_conf > /etc/supervisord.conf
    打开 supervisor.conf 在最底部添加(每一行前面不要有空格,防止报错):
    [program:zqxt]
    command=/path/to/uwsgi --http :8003 --chdir /path/to/zqxt --module zqxt.wsgi
    directory=/path/to/zqxt
    startsecs=0
    stopwaitsecs=0
    autostart=true
    autorestart=true
    command 中写上对应的命令,这样,就可以用 supervisor 来管理了。
    
    启动 supervisor
    supervisord -c /etc/supervisord.conf
    重启 zqxt 程序(项目):
    supervisorctl -c /etc/supervisord.conf restart zqxt
    启动,停止,或重启 supervisor 管理的某个程序 或 所有程序:
     supervisorctl -c /etc/supervisord.conf [start|stop|restart] [program-name|all]
    以 uwsgi 为例,上面这样使用一行命令太长了,我们使用 ini 配置文件来搞定,比如项目在 /home/tu/zqxt 这个位置,
    在其中新建一个 uwsgi.ini 全路径为 /home/tu/zqxt/uwsgi.ini
    [uwsgi]
    socket = /tmp/zqxt.sock
    chdir=/home/tu/zqxt
    wsgi-file = zqxt/wsgi.py
    touch-reload=/home/tu/zqxt/reload
     
    processes = 2
    threads = 4
     
    chmod-socket = 664
    chown-socket=tu:www-data
    注意上面的 /tmp/zqxt.sock ,一会儿我们把它和 nginx 关联起来。
     
    在项目上新建一个空白的 reload 文件,只要 touch 一下这个文件(touch reload) 项目就会重启。
    修改 supervisor 配置文件中的 command 一行:
    [program:zqxt]
    command=/path/to/uwsgi --ini /home/tu/zqxt/uwsgi.ini
    directory=/path/to/zqxt
    startsecs=0
    然后重启一下 supervisor:
    supervisorctl -c /etc/supervisord.conf restart zqxt
    supervisorctl -c /etc/supervisord.conf restart all
    6、. 配置 Nginx
    server {
        listen      80;
        server_name www.ziqiangxuetang.com;
        charset     utf-8;
     
        client_max_body_size 75M;
     
        location /media  {
            alias /path/to/project/media;
        }
     
        location /static {
            alias /path/to/project/static;
        }
     
        location / {
            uwsgi_pass  unix:///tmp/zqxt.sock;
            include     /etc/nginx/uwsgi_params;
        }
    }
    激活网站:
    ln -s /etc/nginx/sites-available/zqxt.conf /etc/nginx/sites-enabled/zqxt.conf
    测试配置语法问题
    service nginx configtest
    重启 nginx 服务器:
    service nginx reload 或者 
    service nginx restart
    [root@controller ~]# openstack compute service list
    +----+--------------------+------------+----------+---------+-------+----------------------------+
    | Id | Binary             | Host       | Zone     | Status  | State | Updated At                 |
    +----+--------------------+------------+----------+---------+-------+----------------------------+
    |  1 | nova-consoleauth   | controller | internal | enabled | up    | 2016-02-09T23:11:15.000000 |
    |  2 | nova-scheduler     | controller | internal | enabled | up    | 2016-02-09T23:11:15.000000 |
    |  3 | nova-conductor     | controller | internal | enabled | up    | 2016-02-09T23:11:16.000000 |
    |  4 | nova-compute       | computer001| nova     | enabled | up    | 2016-02-09T23:11:20.000000 |
    +----+--------------------+------------+----------+---------+-------+----------------------------+
  • 相关阅读:
    CTeX里面CTRL-Space和中文输入法的冲突问题解决
    用LaTeX画树形结构
    统计学howto
    Lights Out Game
    ubuntu下安装 Source insight
    github常用命令
    编程珠玑:第7章(初略估算)的阅读体会
    在windows上安装common lisp开发环境
    睡眠十律:程序员必看
    网络和服务器编程
  • 原文地址:https://www.cnblogs.com/lliqiang/p/6507292.html
Copyright © 2011-2022 走看看