1、腾讯云

10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

操作系统

Ubuntu Server 16.04.1 LTS 64位

10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

获取root权限

ubuntu@VM-0-9-ubuntu:~$ sudo passwd root
Enter new UNIX password:  root
Retype new UNIX password: 
passwd: password updated successfully
ubuntu@VM-0-9-ubuntu:~$ 
ubuntu@VM-0-9-ubuntu:~$ su -
Password: 
root@VM-0-9-ubuntu:~# 

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

 

2、Mysql

1、安装mysqly ,需要y确认

apt-get install mysql-server

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

设置MySQL密码 ,输入两次密码,回车即可

10 腾讯云、django2.0、uwsgi、mysql、nginx 部署  10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

查看MySQL版本命令

root@VM-0-9-ubuntu:~# mysql --version
mysql  Ver 14.14 Distrib 5.7.23, for Linux (x86_64) using  EditLine wrapper

 

运行数据库Mysql安全配置向导: 输入root密码,4个回车 ok

  mysql_secure_installation

10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

启动mysql服务

root@VM-0-9-ubuntu:~# service mysql start

 

 配置字符集,

root@VM-0-9-ubuntu:~# vim /etc/mysql/my.cnf     # 添加如下代码,保存退出
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8

[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
character-set-server=utf8

[mysql]
no-auto-rehash
default-character-set=utf8

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

重启mysql服务

root@VM-0-9-ubuntu:~# service mysql restart

 

2、测试数据库

创建项目的数据库    # 我的数据库 cnblog

root@VM-0-9-ubuntu:~# mysql -uroot -proot

mysql>  CREATE DATABASE `cnblog` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cnblog             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

 

 

3、python3 +django2.0

1、Ubuntu自带python3.5版本

root@VM-0-9-ubuntu:~# python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> 

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

 2、安装pip3

root@VM-0-9-ubuntu:~# apt-get install python3-pip

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

测试pip3

root@VM-0-9-ubuntu:~# pip3

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

3、安装django2.0

root@VM-0-9-ubuntu:~# pip3 install django==2.0

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

测试

root@VM-0-9-ubuntu:~# python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import django
>>> 

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

4、 uWSGI,uwsgi,WSGI

1、uWSGI介绍

uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。

要注意 WSGI / uwsgi / uWSGI 这三个概念的区分。

  1. WSGI是一种Web服务器网关接口。它是一个Web服务器(如nginx,uWSGI等服务器)与web应用(如用Flask框架写的程序)通信的一种规范。
  2. uwsgi是一种线路协议而不是通信协议,在此常用于在uWSGI服务器与其他网络服务器的数据通信。
  3. 而uWSGI是实现了uwsgi和WSGI两种协议的Web服务器。
  4. uwsgi协议是一个uWSGI服务器自有的协议,它用于定义传输信息的类型(type of information),每一个uwsgi packet前4byte为传输信息类型描述,它与WSGI相比是两样东西

  10 腾讯云、django2.0、uwsgi、mysql、nginx 部署10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

10 腾讯云、django2.0、uwsgi、mysql、nginx 部署10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

uWSGI的主要特点如下

  1. 超快的性能
  2. 低内存占用(实测为apache2的mod_wsgi的一半左右)
  3. 多app管理(终于不用冥思苦想下个app用哪个端口比较好了-.-)
  4. 详尽的日志功能(可以用来分析app性能和瓶颈)
  5. 高度可定制(内存大小限制,服务一定次数后重启等)

总而言之uwgi是个部署用的好东东,正如uWSGI作者所吹嘘的:

If you are searching for a simple wsgi-only server, uWSGI is not for you, but if you are building a real (production-ready) app that need to be rock-solid,
fast and easy to distribute/optimize for various load-average, you will pathetically and morbidly fall in love (we hope) with uWSGI.

 

 

2、uwsgi模块安装

root@VM-0-9-ubuntu:~# pip3 install uwsgi
Collecting uwsgi

  10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

  测试:新建test.py 输入以下内容

root@VM-0-9-ubuntu:~# vim test.py

 

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"]

 

  uwsgi启动8000端口,浏览器访问你的ip:8000

root@VM-0-9-ubuntu:~# uwsgi --http :8000 --wsgi-file test.py

  10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

 

5、上传本地django项目,测试

1、用xftp上传到

home下的ubuntu目录下

root@VM-0-9-ubuntu:/home/ubuntu# pwd
/home/ubuntu

 10 腾讯云、django2.0、uwsgi、mysql、nginx 部署

安装tree命令,查看目录结构

root@VM-0-9-ubuntu:/home/ubuntu# apt install tree

 

root@VM-0-9-ubuntu:/home/ubuntu# tree

 

└── cnblog
    ├── blog
    │?? ├── migrations
    │?? │?? └── __pycache__
    │?? ├── templatetags
    │?? │?? └── __pycache__
    │?? └── utils
    │??     └── __pycache__
    ├── cnblog
    ├── logger
    ├── media
    │?? ├── add_article_img
    │?? └── avatars
    ├── static?? ├── blog
    │?? │?? └── bs
    │?? │??     ├── css
    │?? │??     ├── fonts
    │?? │??     └── js
    │?? ├── bootstrap3
    │?? │?? ├── css
    │?? │?? ├── fonts
    │?? │?? └── js
    │?? ├── css
    │?? ├── font
    │?? ├── img
    │?? ├── js
    │?? └── kindeditor
    │??     ├── asp
    │??     ├── asp.net
    │??     │?? └── bin
    │??     ├── jsp
    │??     │?? └── lib
    │??     ├── lang
    │??     ├── php
    │??     ├── plugins
    │??     │?? ├── anchor
    │??     │?? ├── autoheight
    │??     │?? ├── baidumap
    │??     │?? ├── clearhtml
    │??     │?? ├── code
    │??     │?? ├── emoticons
    │??     │?? │?? └── images
    │??     │?? ├── filemanager
    │??     │?? │?? └── images
    │??     │?? ├── fixtoolbar
    │??     │?? ├── flash
    │??     │?? ├── image
    │??     │?? │?? └── images
    │??     │?? ├── insertfile
    │??     │?? ├── lineheight
    │??     │?? ├── link
    │??     │?? ├── map
    │??     │?? ├── media
    │??     │?? ├── multiimage
    │??     │?? │?? └── images
    │??     │?? ├── pagebreak
    │??     │?? ├── plainpaste
    │??     │?? ├── preview
    │??     │?? ├── quickformat
    │??     │?? ├── table
    │??     │?? ├── template
    │??     │?? │?? └── html
    │??     │?? └── wordpaste
    │??     └── themes
    │??         ├── common
    │??         ├── default??         ├── qq
    │??         └── simple
    └── templates
        ├── backend
        └── blog
View Code

相关文章:

  • 2021-07-20
  • 2022-12-23
  • 2021-04-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2021-06-04
相关资源
相似解决方案