项目比较赶,来了一次快速开发,
环境 nginx+gunicorn+python3.6.6+flask
开发环境nodejs+vue+flask+python3.6.6
1.安装python3.6.6
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 gcc gcc-c++ 下载 wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz 解压缩 tar -zxf Python-3.6.6.tgz cd Python-3.6.6 配置 ./configure --prefix=/usr/bin/python3.6.6 yum install -y gcc 安装 make && make install 配置软链接 ln -s /usr/bin/python3.6.6/bin/python3 /usr/bin/python3 python3 -V 配置pip cp /usr/bin/python3.6.6/bin/pip3 /usr/bin/ cp /usr/bin/python3.6.6/bin/pip3.6 /usr/bin/ 更新yum包 yum update 安装包依赖 yum install python-devel yum install mysql-devel pip3 install -r requirements.txt
安装mysqlclient失败
版本问题,win环境开发的用的mysql是1.4版本这里做下调整,安装1.3.1版本
pip install mysqlclient==1.3.1
2.nginx 安装及配置
安装
常用命令
nginx 启动nginx
nginx -s stop 关闭nginx
ps aux | grep nginx
ps -autx|grep gunicorn
配置
vi /usr/local/nginx/conf/nginx.conf 在http节点下配置 使用了三个站点 upstream flask { server 10.1.1.96:5000; server 10.1.1.96:5001; server 10.1.1.96:5002; } server { listen 80; server_name 0.0.0.0; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://flask; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
使用screen 保持会话
解决关闭会话无法工作 yum install screen 查看后台所有的screen进程 screen -ls 进入screen 模式 screen -S gunicorn1 恢复现有的进程 screen -r 3846.es
启动脚本命令
cd /var/wsdd gunicorn -w 4 -b 10.1.1.96:5000 manage:app –preload gunicorn -w 4 -b 10.1.1.96:5001 manage:app –preload gunicorn -w 4 -b 10.1.1.96:5002 manage:app –preload