• nginx+uwsgi+django


    一、安装平台

    1、安装pcre

    cd /home
    mkdir -p /home/install/nginx && cd /home/install/nginx

    tar -zxvf pcre-8.36.tar.gz
    cd pcre-8.36
    ./configure
    make && make install
    cd ..

    2、安装Nginx

    tar -zxvf nginx-1.9.1.tar.gz
    cd nginx-1.9.1
    ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-cc-opt='-O3' --with-cpu-opt=opteron
    make && make install
    cd ..

    3、安装MySql-python

    tar -zxvf MySQL-python-1.2.3.tar.gz
    cd MySQL-python-1.2.3
    python setup.py install
    cd ..

    4、先安装libxml,在安装uwsgi

    yum -y install libxml*

    tar -zxvf uwsgi-2.0.10.tar.gz
    cd uwsgi-2.0.10
    make
    cp uwsgi /usr/bin


    二、平台配置

    1、Nginx相关配置

    cd /usr/local/nginx/conf

    修改vim django_uwsgi.conf配置文件:

    # Django project
    server {
    listen 80;
    server_name 192.168.20.128;

    location / {
    uwsgi_pass 127.0.0.1:9000;
    include uwsgi_params;
    access_log off;
    }

    location ^~ /static {
    root /opt/jumpserver;
    }

    location ^~ /admin/ {
    uwsgi_pass 127.0.0.1:9000;
    include uwsgi_params;
    access_log off;
    }

    location ~* ^.+.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg)$ {
    root /opt/jumpserver/static;
    access_log off;
    }

    }

    nginx添加uwsgi输出头支持和追加子配置文件django_uwsgi.conf

    vim nginx.conf


    http{
    ........
    include uwsgi_params;
    include django_uwsgi.conf;
    }


    2、UWSGI配置

    mkdir -p /home/uwsgi;cd /home/uwsgi
    mkdir -p /opt/jumpserver/logs
    echo "" > /opt/jumpserver/logs/django.log
    vim uwsgi.xml

    <uwsgi>
    <socket>127.0.0.1:9000</socket>
    <listen>80</listen>
    <master>true</master>
    <pidfile>/usr/local/nginx/uwsgi.pid</pidfile>
    <processes>8</processes>
    <pythonpath>/opt/jumpserver</pythonpath>
    <pythonpath>/opt/</pythonpath>
    <module>django_wsgi</module>
    <profiler>true</profiler>
    <memory-report>true</memory-report>
    <enable-threads>true</enable-threads>
    <logdate>true</logdate>
    <limit-as>6048</limit-as>
    <daemonize>/opt/jumpserver/logs/django.log</daemonize>
    </uwsgi>

    3、创建应用模块

    cd /opt/jumpserver
    vim django_wsgi.py


    import os
    os.environ['DJANGO_SETTINGS_MODULE'] = 'jumpserver.settings'
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()


    4、启动服务

    cd /lib64/
    ln -s libpcre.so.0.0.1 libpcre.so.1
    /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    /usr/local/nginx/sbin/nginx


    7、查看进程

    [root@Master-jumpserver uwsgi]# ps -ef|grep uwsgi|grep -v grep
    root 9590 1 0 06:31 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    root 9591 9590 0 06:31 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    root 9592 9590 0 06:31 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    root 9593 9590 0 06:31 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    root 9594 9590 0 06:31 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    root 9595 9590 0 06:31 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    root 9596 9590 0 06:31 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    root 9597 9590 0 06:31 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    root 9598 9590 0 06:31 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml

    8、监听端口
    [root@Master-jumpserver uwsgi]# netstat -an|grep 9000
    tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN

    [root@Master-jumpserver uwsgi]# netstat -lpnt
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN 1100/slapd
    tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 9590/uwsgi
    tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1255/mysqld
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9600/nginx
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1118/sshd
    tcp 0 0 :::389 :::* LISTEN 1100/slapd
    tcp 0 0 :::22 :::* LISTEN 1118/sshd
    tcp 0 0 ::1:25 :::* LISTEN 1347/master
    [root@Master-jumpserver uwsgi]# lsof -i :80
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    nginx 9600 root 6u IPv4 43367 0t0 TCP *:http (LISTEN)
    nginx 9601 nobody 3u IPv4 43635 0t0 TCP 192.168.20.128:http->192.168.20.1:52147 (ESTABLISHED)
    nginx 9601 nobody 6u IPv4 43367 0t0 TCP *:http (LISTEN)


    6、可以正常访问并登录 http://192.168.20.128/login/


    7、运行index.js log_handler.py 可以修改service.sh脚本
    manage.py runserver 0.0.0.0:80 不需要在运行

    cd /opt/jumpserver/
    vim service.sh

    如图1.npg
    如图2.npg

    运行

    sh service.sh start

    附uwsgi启动脚本

    cd /home/uwsgi
    vim uwsgiserver.sh


    #!/bin/bash
    if [ $1 = start ];then
    psid=`ps aux|grep "uwsgi"|grep -v "grep"|wc -l`
    if [ $psid -gt 2 ];then
    echo "uwsgi is running!"
    exit 0
    else
    /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    fi
    echo "Start uwsgi service [OK]"
    elif [ $1 = stop ];then
    killall -9 uwsgi
    echo "Stop uwsgi service [OK]"
    elif [ $1 = restart ];then
    killall -9 uwsgi
    /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
    echo "Restart uwsgi service [OK]"
    else
    echo "Usages: sh uwsgiserver.sh [start|stop|restart]"
    fi

    cd /home/uwsgi
    sh uwsgiserver.sh restart
    [uWSGI] parsing config file /home/uwsgi/uwsgi.xml
    Start uwsgi service [OK]

    更改配置重启nginx
    cd /home/uwsgi
    sh uwsgiserver.sh restart
    cd /usr/local/nginx/sbin
    ./nginx -s reload

  • 相关阅读:
    非递归遍历二叉树Java
    【滴滴实习】滴滴2023届产研秋招储备实习生正在火热招募中🔥
    c++从office word的xml源文本文件中提取空行后的首个段落
    自建脚本安装docker
    银河麒麟安装软件失败,可使用命令行安装
    Fiddler+Proxifier抓pc应用包(c/s架构)
    11. Spring高级AOP概念
    10. Spring高级IOC的深入剖析
    12. Spring高级注解驱动AOP开发入门
    9. Spring高级注解驱动开发入门
  • 原文地址:https://www.cnblogs.com/muzinan110/p/5053726.html
Copyright © 2020-2023  润新知