奥门巴黎人手机网址【app】

Python3条件搭建(uWSGI+Django+Nginx+Python+MySQL)

2019-12-04 12:20·澳门巴黎人彩票

<chdir>/data/web/vpssite</chdir>

2、安装Nginx

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

三、Nginx 安装

#vi nginx.conf
追加子配置文件django_uwsgi.conf

case "$1" in
    start)
        if [ $uwsgi_pn -ge 5 ];then
            action "uwsgi is running!" /bin/false
        else
            start
            ERVAL=0
        fi
        ;;
    stop)
        if [ $uwsgi_pn -ge 5 ];then
            stop
            ERVAL=0
        else
            action "uwsgi no running!" /bin/false
        fi
        ;;
    reload)
        if [ $uwsgi_pn -ge 5 ];then
            $uwsgi --reload $uwsgi_pid >&/dev/null
            ERVAL=$?
            [ $ERVAL -eq 0 ] && action "uwsgi reloading ..." /bin/true
        else
            action "uwsgi reload error" /bin/false
        fi
        ;;
    restart)
        stop
        sleep 2
        start
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        ERVAL=2
esac
exit $ERVAL

uwsgi_pass 127.0.0.1:8630;

二、平台配置
1、平台意况认证
1.1、项目地点:/opt/www/Purgesys
创立项目方法:

# Create your models here.

cd MySQL-python-1.2.3

http{
……..
include django_uwsgi.conf;
}
http{ …….. include django_uwsgi.conf; }
3、UWSGI配置
#mkdir -p /home/uwsgi;cd /home/uwsgi
#mkdir -p /opt/www/logs
#echo “” > /opt/www/logs/django.log
#vi uwsgi.xml

from django.shortcuts import render
from django.http import HttpResponse
from app01 import models  #引进数据类模版
# Create your views here.

import MySQLdb

前边平素接收Nginx+法斯特cgi来搭建python web服务器,本文介绍Nginx+UWSGI组合来落到实处。uWSGI 是八个便捷的、纯C语言开辟的、自维护的、对开辟者友好的WSGI服务器,旨在提供专业的 Python web应用公布和支付。它更相符python web的标准合同,速度要比法斯特cgi要快、质量更是平静。
生机勃勃、安装平台
1、安装pcre

 INT  :马上杀死全体uWSGI;同于:--stop

二、安装uWSGI

4、安装MySql-python

uid、gid:设置客户和组

七、配置Django app

3、安装python&Mysql-python

uWSGI:多个依照自有的uwsgi契约,wsgi和谐和http服务左券的web网关

后生可畏旦遭受错误:python: error while loading shared libraries: libpython2.7.so.1.0:

6、查看进度
#[[email protected] nginx]# ps -ef|grep uwsgi|grep -v grep

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

print data

view plaincopy to clipboardprint?
import os
os.environ[DJANGO_SETTINGS_MODULE] = ‘Purgesys.settings’
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
import os os.environ[DJANGO_SETTINGS_MODULE] = ‘Purgesys.settings’ import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
5、运营服务
#/usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
#/usr/local/nginx/sbin/nginx

#uwsgi --stop /tmp/project-master.pid

server_name blog.hysia.com;

引用
wget
tar -zxvf Python-2.5.1.tgz
cd Python-2.5.1
./configure && make && make install
echo “export PATH=$PATH:/usr/local/bin” >> /etc/profile
source /etc/profile

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See
    # for more information.
    include /etc/nginx/conf.d/*.conf;

wget

引用
root 21652 1 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21653 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21654 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21655 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21656 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21657 216

看下边进程是少了四个主进程,通过systemctl 查看就领会了:

cd uwsgi-1.9.17

引用
wget
tar -zxvf Django-1.2.3.tar.gz
cd Django-1.2.3
python setup.py install
cd ..

树立uWSGI的布局文件,在django项目中确立uwsgi.ini文件:

uwsgi -x /data/web/vpssite/django.xml

引用
wget
tar -zxvf uwsgi-0.9.6.2.tar.gz
cd uwsgi-0.9.6.2
make
cp uwsgi /usr/bin

#uwsgi --ini /djproject/mysite/uwsgi.ini    #开行服务

sys.path.insert(0, os.path.dirname(__file__))

引用
cd /home
mkdir -p /home/install/nginx && cd /home/install/nginx
wget
tar -zxvf pcre-8.00.tar.gz
cd pcre-8.00
./configure
make && make install
cd ..

def index(request):    #增加视图函数
  return HttpResponse('hello world')

瞩目编写翻译的时候要增进参数:--with-cc-opt='-O3' --with-cpu-opt=opteron

引用
cd ../
wget mysql-python/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz?r=&ts=1285248455&use_mirror=nchc">
cd MySQL-python-1.2.2
python setup.py install

在setting中,Django私下认可使用的是sqlite数据库:

接下来保存OK.

1.2、查看项目(现身以下文件构造表达项目已成立成功卡塔尔(قطر‎
#tree Purgesys

#建设结构二个数据库,前边要用到
MySQL [(none)]> create database django;
Query OK, 1 row affected (0.00 sec)

ldconfig

5、安装Django

#cat urls.py
from django.contrib import admin
from django.urls import path
from app01 import views  #导入app01视图
urlpatterns = [
    path('admin/', admin.site.urls),
    path('',views.index,name='index'),  #增添路由
]

error_log /var/log/nginx/blog.hysia.com-error.log ;

引用
Purgesys
|– __init__.py
|– manage.py
|– settings.py
`– urls.py

#cd mysite/
#django-admin startapp app01

application = WSGIHandler()

引用
cd /opt/www
django-admin.py startproject Purgesys

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel python-devel

from django.core.handlers.wsgi import WSGIHandler

引用
wget
tar -zxvf nginx-0.8.50.tar.gz
cd nginx-0.8.50/
./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 ..

events {
    worker_connections 1024;
}

6.yum是选拔python写的,晋级新本子的python后会招致yum不可用,如下为运营yum时的失实提示:

6、安装uWSGI

yum -y install nginx

python setup.py build

2、Nginx相关配置
#cd /usr/local/nginx/conf
#vi django_uwsgi.conf

成立项目:

四、安装MySql-python

web服务器,本文介绍Nginx+UWSGI组合来达成。uWSGI 是二个高速的、纯C语言开采的、自维护的、对开拓者友...

#cmd步入django项目路径下
#python manage.py migrate #开创表布局,非model类的别的表,django所须求的
#python manage.py makemigrations app名 #做多少迁移的策画
如:python manage.py makemigrations app01 app01是项目中的app名字
#python manage.py migrate # 推行迁移,创造medel表布局

极端中输入 python,踏入python交互作用方式,输入如下:

view plaincopy to clipboardprint?
<uwsgi>
<socket>127.0.0.1:9000</socket>
<listen>200</listen>
<master>true</master>
<pidfile>/usr/local/nginx/uwsgi.pid</pidfile>
<processes>8</processes>
<pythonpath>/opt/www/Purgesys</pythonpath>
<pythonpath>/opt/www/</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/www/logs/django.log</daemonize>
</uwsgi>
<uwsgi>   <socket>127.0.0.1:9000</socket>   <listen>200</listen>   <master>true</master>   <pidfile>/usr/local/nginx/uwsgi.pid</pidfile>   <processes>8</processes>   <pythonpath>/opt/www/Purgesys</pythonpath>   <pythonpath>/opt/www/</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/www/logs/django.log</daemonize> </uwsgi>
4、创立应用模块
cd /opt/www/Purgesys
vi django_wsgi.py

ENGINE : 钦命数据库驱动,不相同的数据库那个字段差别,下边是大规模的聚焦数据库的ENGINE的写法:

[[email protected] ~]# which yum

view plaincopy to clipboardprint?
# Django project
server {
listen 80;
server_name purgesys.domain.com;
location / {
uwsgi_pass 127.0.0.1:9000;
include uwsgi_params;
access_log off;
}
location ^~ /static {
root /opt/www/Purgesys;
}
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/www/Purgesys/static;
access_log off;
}
}
# Django project server {         listen  80;         server_name purgesys.domain.com;           location / {             uwsgi_pass   127.0.0.1:9000;             include     uwsgi_params;             access_log  off;         }          location ^~ /static {                 root   /opt/www/Purgesys;         }          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/www/Purgesys/static;             access_log   off;         }  }
*Nginx-0.8.50暗许已增添uwsgi输出头支持
include uwsgi_params;

server {
    listen 80;
    server_name localhost;
    charset    utf-8;
    access_log      /var/log/nginx/nginx_access.log main;
    error_log      /var/log/nginx/nginx_error.log;
    client_max_body_size 75M;

yum -y install gcc gcc-c++ rpm-build mysql* libtool-ltdl* libtool automake autoconf libtool make setuptool 二、编写翻译安装python2.7.5 1. 下载python2.7...

 INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'app01'
        ]

django.VERSION

module:钦赐web应用的输入模块,如Django项目下的wsgi.py接口文件

[[email protected] nginx-1.4.2]# ./configure --with-http_stub_status_module --prefix=/usr/local/nginx --with-cc-opt='-O3' --with-cpu-opt=opteron

    location / {
        include    /etc/nginx/uwsgi_params;  #加载uwsgi模块
        uwsgi_pass  127.0.0.1:9090;  #持有乞求转到9090端口交给uwsgi管理
        }
    }

/usr/bin/yum

第风姿罗曼蒂克顾客端通过浏览器访谈服务器财富;nginx作为对外地劳工务的端口(80卡塔尔国,nginx采取到客商端http乞求后会解包深入分析,假使是静态文件就去安顿的静态文件中找出资源并回到给顾客端,要是是动态能源,nginx就因此布署文件将呼吁传递给uwsgi管理,并转载给uwsgi,wsgi遵照需要调用django工程的文书和函数,管理后django将重回值交给wsgi,wsgi将再次回到值举办李包裹装,转载给uWSGI,uWSGI选择到数量后转发给nginx,最后回到给顾客端。

<pythonpath>..</pythonpath>

processes:运维进度数

./configure --prefix=/usr/local/python27 --enable-shared

HOST: 由于平日的数据库都以C/S架构的,所以得内定数据库服务器之处,大家日常数据库服务器和顾客端都以介意气风发台主机上面,所以平常暗中同意都填127.0.0.1

There was a problem importing one of the Python modules

wsgi-file:内定运营的公文

No module named yum

threads:运维线程数

if not os.path.dirname(__file__) in sys.path[:1]:

#kill -HUP `cat /tmp/project-mast.pid`

拍卖形式:

#cat /etc/RedHat-release
CentOS Linux release 7.5.1804 (Core)
#uname -r
3.10.0-862.3.2.el7.x86_64

然后在app目摄像造个django.xml文件,作为uWSGI运维的布署文件,内容如下:

(2)安装python

焚林而猎办法:

#这里是以post形式提交,要求更正Django项目setting设置中的MIDDLEWARE,将csrf安全机制注销了:

首先在你的app目录成立个wsgi.py 文件,内容如下:

#vim /etc/init.d/uwsgi

}

此间运用yum安装nginx:

  1. 解压文件

(2)配置djando静态文件加载

改为:

uwsgi非时限信号调控:

tar xvf Python-2.7.5.tar.bz2

2、安装python3.6.5

即可

#cat templates/app01/home.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
    <style>
    body{
        background-image: url('/static/78556.jpg');
    }
    </style>
</head>
<body>
<form action="" method="post">  #付出数据给自家
      <p><input type="text" name="username"/></p>
      <p><input type="text" name="password"/></p>
      <p><input type="text" name="age"/></p>
      <p><input type="text" name="salary"/></p>
      <p><input type="submit" value="提交"/></p>
</form>
<table border="1">
  <thead>
      <tr>
                <th>用户名</th>
                <th>密码</th>
                <th>年龄</th>
                <th>工资</th>
      </tr>
  </thead>
            <tbody>
                {% for item in data %} #巡回获取传入字典数据
                <tr>
                    <td>{{item.name}}</td>
                    <td>{{item.password}}</td>
                    <td>{{item.age}}</td>
                    <td>{{item.salary}}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>

因为作者最后接纳xml配置django app 的配置,所以编译 uWSGI 时候要求把libxml编写翻译进去

#netstat -lntp|grep "uwsgi"
tcp        0      0 127.0.0.1:9090          0.0.0.0:*              LISTEN      103596/uwsgi       
tcp        0      0 127.0.0.1:9001          0.0.0.0:*              LISTEN      103596/uwsgi

<module>wsgi</module>

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

六、nginx配置

    access_log  /var/log/nginx/access.log  main;

<uwsgi>

PORT:数据库服务器端口,mysql默以为3306

for data in cur.fetchall():

悬停服务器:

drwxr-xr-x. 3 root root 4096 May 3 15:15 python2.6

#vim app01/views.py
def home(request):
  return render(request,'app01/home.html')

剩余的就大约了

#cat app01/views.py

access_log /var/log/nginx/blog.hysia.com-access.log ;

#ps -ef|grep "uwsgi"  #翻看进度
root    103596      1  2 16:02 ?        00:00:00 /usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini
root    103598 103596  0 16:02 ?        00:00:00 /usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini
root    103599 103596  0 16:02 ?        00:00:00 /usr/local/python356/bin/uwsgi --ini /djproject/mysite/uwsgi.ini

  1. 下载python2.7.5,保存到 /data/qtongmon/software

编排运维脚本:

import os,sys

#ln -s /usr/local/python356/bin/django-admin /usr/local/bin/django-admin

mkdir /usr/local/python27

#改进运营脚本路线
sed -i 's#^basedir=#basedir=/usr/local/mysql#g' /etc/init.d/mysqld
sed -i 's#^datadir=#datadir=/mysql/data#g' /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
#运行和关闭MySQL
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
#方法2:
/usr/local/mysql/bin/msyql_safe &    #后台运转
mysqladmin shutdown  #大雅关闭MySQL服务
#翻开运转情状
#netstat -lntup|grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*              LISTEN      70099/mysqld       

server {

4、安装nginx