记录一次python flask api部署踩坑
周末看了点python的东西 简单的写了个api做散点拟合成线的工具。本地运行好好的 不料部署到linux全是坑。最终成果:https://www.manghaa.com/#/
1、python安装
服务器上原本有python2.7,而且很多服务依赖于它。所以安装的时候不要动原来的,不然就有麻烦了。
yum -y groupinstall "Development tools" yum install libffi-devel -y yum -y install zlib* wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz tar -xvf Python-3.7.4.tgz cd Python-3.7.4 ./configure --prefix=/usr/local/python3 ./configure --enable-optimizations make && make install ln -s /usr/local/bin/python3 /usr/bin/python3 ln -s /usr/local/bin/pip3 /usr/bin/pip3
2、安装依赖包,使用pip3安装,版本遇到坑,改用阿里镜像。
vim ~/.pip/pip.conf [global] index-url=http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com
wq
#然后是安装依赖包
pip3 install pymysql numpy pandas matplotlib scipy flask xlrd
3、正当我以为大功告成之时,matplotlib绘图中文出现乱码,字体问题,下载字体并清除matplotlib缓存
cd /usr/local/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf mv /root/SimHei.ttf ./ cd ~/.cache/ rm -rf matplotlib/
4、安装supervisord作为守护进程,增加配置。
yum install supervisor /etc/supervisord.d/learn_api.ini #这是配置文件内容 [program:api.learn.manghaa.com] ;后台运行 nodaemon=true command=python3 main.py directory=/root/learn_api autorestart=true stderr_logfile=/root/learn_api/error.log stdout_logfile=/root/learn_api/std.log environment=ASPNETCORE_ENVIRONMENT=Production user=root stopsignal=INT #配置文件内容结束 systemctl start supervisord supervisordctl start all
5、安装mariadb
yum install mariadb mariadb-server mysql_secure_installation systemctl start mariadb