Ubuntu16.04?????????mysql + uwsgi + nginx????????????flask ??????

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu16.04?????????mysql + uwsgi + nginx????????????flask ??????相关的知识,希望对你有一定的参考价值。

???????????????   vim   param   ??????   ann   ??????nginx   set   ??????   rar   

1.??????mysql

Sudo apt-get install mysql

 

??????mysql?????????????????????,????????? /var/lib/mysql

sudo cp -R /var/lib/mysql/* /home/applex/mysqldb

sudo chown -R  mysql:mysql home/applex/mysqldb

sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf

 

??? [mysqld] ????????? datadir?????????

datadir = /home/applex/mysqldb

 

sudo vim /etc/apparmor.d/usr.sbin.mysqld

???  

/var/lib/mysql r  

/var/lib/mysql/** rwk  

?????????  

/home/applex/mysqldb r  

/home/applex/mysqldb/** rwk

 

 

??????mysql

sudo service apparmor restart

sudo service mysql restart

???

sudo  /etc/init.d/apparmor restart

sudo  /etc/init.d/mysql restart   

 

 

??????msyql?????????utf8

sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf

???[mysqld]???????????????

character-set-server=utf8

 

 

sudo gedit /etc/mysql/conf.d/mysql.cnf

??????
default-character-set=utf8 sudo gedit /etc/mysql/debian.cnf
??????
default-character-set=utf8

 

 

2.??????anaconda3

 

???????????????????????????sh????????????,??????

bash Anaconda3-2018.12-Linux-x86_64.sh

??????????????????

 

conda????????????????????????????????????, ???????????????????????????????????????python3.6,???????????????????????????conda??????

conda create -n myenv python=3.6

 

3.conda?????????????????????

 

?????????????????????,conda?????????????????????????????????,??????

pip install -e .

??????????????????????????????setup.py ???  MANIFEST.ini

 

??????????????????????????????, conda?????????????????????wheel????????????,??????

pip install xxx.whl

????????????????????????????????????????????????????????????????????????,?????????:

# [main.py]

form myproject import app

if ???__main__??? == __name__:

app.run()

????????????python main.py ??????flask?????????????????????????????????????????????????????????????????????

 

 

4.??????uwsgi

 

?????????conda???????????????,???pip??????uwsgi:

conda activate myenv

pip install uwsgi

 

??????uwsgi???UnicodeEncoding??????,?????????conda??????????????????unicode??????(????????????)

 

??????uwsgi????????????,????????????gcc4.7

/home/applex/conda/envs/myproject/compiler_compat/ld: error: lto-wrapper failed:

sudo apt-get install gcc-4.7

sudo rm /usr/bin/gcc

sudo ln -s /usr/bin/gcc-4.7 /usr/bin/gcc

 

??????uwsgi ???help??????uwsgi??????????????????

 

 

uwsgi ???help ??????????????????,???????????????,????????????libpcre3-dev

uwsgi: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

sudo apt-get install libpcre3 libpcre3-dev

find / -name libpcre.so.3

?????? /lib/x86_64-linux-gnu/libpcre.so.3

sudo ln -s /lib/x86_64-linux-gnu/libpcre.so.3 /usr/lib/libpcre.so.1

 

??????uwsgi????????????

# [my_uwsgi.ini]

# ??????python??????

pythonpath = /home/applex/conda/envs/myproject/bin

# ??????http????????????socket??????(?????????????????????)

http = 127.0.0.1:7878

# socket = 127.0.0.1:7878

# ???????????????(???process???)

workers = 4

# ???????????????

threads = 2

# ??????????????????

daemonize = /home/applex/myproject/server.log

# ??????app????????????

chdir = /home/applex/myproject

# ??????app????????????(?????????????????????????????????,??????????????????chdir)

# ???????????????py??????????????????????????????app??????

wsgi-file = ./main.py

# ??????application????????????

callable= app

??????

??????uwsgi?????????

uwsgi mypath/ my_uwsgi.ini

 

??????uwsgi????????????

ps -aux | grep uwsgi

 

?????????????????????

netstat -anp | grep 7878

 

??????uwsgi??????

pgrep uwsgi | xargs kill -s 9

 

????????????daemonize??????????????????????????????????????????

 

5. ??????redis

sudo apt-get install redis-server

 

6.??????nginx

sudo apt-get install nginx

 

??????/etc/nginx/sites-enabled????????????default??????,??????/etc/nginx/sites-available/default???/etc/nginx/sites-enabled,?????????????????????myproject.conf,??????uwsgi_params?????????????????????????????????

cp /etc/nginx/uwsgi_params /home/applex/myproject/

 

??????myproject.conf,??????:

server {

listen 80;

listen [::]:80;

 

server_name 127.0.0.1;

charset utf-8;

 
        # ??????url?????????uwsgi

        location / {

            include /home/applex/myproject/uwsgi_params;

            uwsgi_pass 127.0.0.1:8000;

            uwsgi_param UWSGI_CHDIR /home/applex/myproject;

            uwsgi_param UWSGI_SCRIPT main:app;

        }

 

        # ??????nginx??????????????????

        location /static {

            alias /home/applex/conda/envs/myproject/lib/python3.6/site-packages/myproject/static;

        }

}

??????

 

??????nginx??????

sudo service nginx start/stop/reload

 





以上是关于Ubuntu16.04?????????mysql + uwsgi + nginx????????????flask ??????的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu server 16.04 mysql的默认密码

ubuntu 16.04 和 windows 10系统安装mysql 允许远程访问 | mysql user guide on ubuntu 16.04 and windows 10

ubuntu16.04服务器配置mysql,并开启远程连接

在 ubuntu 16.04 上安装 mysql 服务器的问题

安装mysql到ubuntu

无法在 ubuntu 16.04 上安装 mysql