在Ubuntu 16里安装 python 3.6 + uWSGI + Nginx
环境:Ubuntu 16 64位
1.apt update # 更新软件源
2.apt install software-properties-common # 为安装python3.6做准备,ubuntu16自带的是python3.5
3.add-apt-repository ppa:deadsnakes/ppa # 安装ppa
4.apt updat # 更新软件源
5.apt install python3.6 python3.6-dev # 安装python3.6及开发包
6.rm /usr/bin/python3 # 移除原有的python3.5链接
7.ln -s /usr/bin/python3.6 /usr/bin/python3 # 创建python3链接到python3.6
8.apt install mysql-server # 安装mysql数据库,设置密码
9.apt install mongodb # 安装 mongodb
10.apt install python3-pip # 安装 python3-pip
11.apt python3-mysql.connector # 安装 mysql.connector
12.cd /mys/street_app_server/ # 切换到 app_server 文件所在的根目录
13.pip3 install -r requirements.txt # 安装依赖的python3包
14.create database CWS_APP; # 在mysql的命令行中,或在phpmyadmin中,创建 CWS_APP 数据库
15.python3 manage.py init # 初始化,会自动创建openluat_user和street_machine数据库及相应的数据表
16.python3 manage.py runserver # 如需测试,可运行
17.pip3 install uWSGI # 安装 uWSGI
18.apt install supervisor # 安装 supervisor,用来管理uWSGI
19.vi /etc/supervisor/conf.d/mys.conf # 创建新的 supervisor 配置文件,配置uWSGI运行,内容如下:
[program:uwsgi]
command=uwsgi --ini /mys/street_app_server/config/uwsgi_config.ini --listen 128
environment=production="1",FLASK_CONFIG="production"
startretries=8 ; max # of serial start failures (default 3)
stdout_logfile=/mys/log/uwsgi.log ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=10MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=8 ; # of stdout logfile backups (default 10)
stderr_logfile=/mys/log/uwsgi.log ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=10MB ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=8 ; # of stderr logfile backups (default 10)
20.service supervisor start # 启动 supervisor 服务
21.apt install nginx # 安装 nginx
22.vi /etc/nginx/sites-enabled/mys # 创建新站配置文件,内容如下:
server {
listen 80;
server_name szt.anqun.org;
root /mys/;
error_log /mys/log/mafunginx.error;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:33410; # 这里与uwsgi中的端口号相同
}
location ~* .txt {
root /mys/streetweb;
index index.html;
}
location /assets {
root /mys/streetweb;
index index.html;
autoindex on;
}
location /adminpage/assets {
root /mys/streetweb;
index index.html;
autoindex on;
}
location /adminpage/ {
root /mys/streetweb;
index index.html;
}
}
23.nginx -s reload # 重载nginx配置文件
24.在浏览器里访问 http://域名/adminpage/ 应该会显示登录界面,默认用户名是 15300002713 ,密码是 888888
25.如需配置数据库密码等,配置文件在 /mys/street_app_server/config 目录里
26.cd /mys # 转到包含有 emqttd-ubuntu16-64.zip 文件的目录,解压
27../emqttd/bin/emqttd start # 启动emqttd