CentOS7 部署flask和paddleX
1、官网下载anaconda,部署python环境
#权限
chmod +x Anaconda3-2020.11-Linux-x86_64.sh
#安装anaconda
bash Anaconda3-2020.11-Linux-x86_64.sh
#生效启动conda
source ~/.bashrc
#创建虚拟环境
conda create -n web_dev python=3.7
#激活虚拟环境 web_dev
conda activate web_dev
#退出虚拟环境
conda deactivate
#conda配置国内镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
#pip设置国内镜像
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
2、部署 flask
#在虚拟环境内
#安装pip
pip install flask
#或采用requirements.txt文件部署
pip install pipreqs
pipreqs ./
pip install -r requirements.txt
3、部署paddleX
#在虚拟环境内
#安装paddlepaddle 安装1.3paddleX 需1.8.5版本paddelpaddle
pip install paddlepaddle==1.8.5 -i https://mirror.baidu.com/pypi/simple
#安装其他依赖
pip install common dual tight data prox -i https://mirror.baidu.com/pypi/simple
#安装paddle
pip install paddle -i https://mirror.baidu.com/pypi/simple
#安装paddleX
pip install paddlex -i https://mirror.baidu.com/pypi/simple
#安装依赖库
yum install libSM-1.2.2-2.el7.x86_64 --setopt=protected_multilib=false
yum install libSM.x86_64
yum install libXext.x86_64
yum install libXrender.x86_64
#后台启动
nohup gunicorn -w 2 -b 0.0.0.0:8081 app:app &
4、部署nginx
#安裝epel-release
yum install epel-release
#安裝nginx
yum install nginx
#启动
systemctl start nginx
#停止
systemctl stop nginx
#重载conf
systemctl reload nginx
配置nginx.conf(文件默认在/etc/nginx)
server {
listen *端口号*;
server_name localhost;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#跨域
location / {
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
add_header 'Access-Control-Allow-Headers' 'Authorization,authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Requested-With';
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}