2019-07-22

Python flask项目部署

1、安装python3依赖包(以centos7为参考)

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

2、下载python3源代码到/usr/local/src

wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz -O /usr/local/src

3、解压源码包

tar -xzf Python-3.6.8.tgz

4、进入解压后的文件夹

cd Python-3.6.8

5、设置python3编译安装的参数,这里设置安装路径

./configure --prefix=/usr/local/python3.6

6、编译,然后编译安装

make && make install

7、安装完成,设置软连接到/usr/local/bin下

ln -s /usr/local/python3.6/bin/python3.6 /usr/local/bin/python3.6

ln -s /usr/local/python3.6/bin/pip3.6 /usr/local/bin/pip3.6

8、安装和配置 nginx

a.yum install nginx

b.nginx根目录下,配置nginx.conf文件(这里使用的是gunicorn运行脚本)

server {

    listen 80;

    server_name example.org; # 这是HOST机器的外部域名,用地址也行

    location / {

        proxy_pass http://127.0.0.1:8080; # 这里是指向 gunicorn host 的服务地址

        proxy_set_header Host $host;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    }

  }

c.flask项目通过ProxyFix运行

2019-07-22_第1张图片

d.最后在nginx根目录下重启nginx:nginx -s reload

9、安装运行python的虚拟环境venv: yum install python-virtualenv

10、创建虚拟环境 virtualen venv

11、进入虚拟环境 source ./bin/activate

12、安装部署flask项目的程序:pip3 install gunicorn

a.运行:cd到flask根目录下 gunicorn -w 4 -b 127.0.0.1:8080 app:app

b.退出:deactivate

13、查看进程:pstree -ap | grep nginx / ps -ef|grep nginx 结束进程:kill -9 ...

14、安装mysql5.7,本地连接服务器mysql:

a、云服务器安全组 - 配置规则 - 添加安全组规则,端口为3306,授权对象0.0.0.0/0 

b、授权:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

c、刷新授权列表:flush privileges;(刷新后还是不行,重启mysql)

你可能感兴趣的:(2019-07-22)