一、更新系统
yum update
二、安装python3.11
查看python和pip版本
ls -al /usr/bin | grep -E 'python|pip'
lrwxrwxrwx. 1 root root 6 Nov 7 2020 pip2.7 -> ./pip2
-rwxr-xr-x 1 root root 209 Aug 2 16:14 pip3.6
-rwxr-xr-x. 1 root root 21816 Nov 7 2020 python2.7
lrwxrwxrwx. 1 root root 31 Nov 3 2020 python3.6 -> /usr/libexec/platform-python3.6
安装成功(见安装文档)
-rwxr-xr-x 1 root root 30678904 Jan 5 10:15 python3.11
-rwxr-xr-x 1 root root 230 Jan 5 10:25 pip3.11
更新pip(确保使用pip3.11)
pip3 install --upgrade pip
三、git拉代码
安装git
yum install git
初始化git
mkdir -p /www/uns/source
cd /www/uns/source/
git init
让git记住账号密码
.git文件夹下的config文件,添加:
vi .git/config
[credential]
helper = store
拉代码
git remote add origin https://gitee.com/xsourcecc/uns.git
git pull origin master
安装项目依赖的包(确保使用pip3.11)
pip install flask
pip install flask_sqlalchemy
pip install flask_migrate
pip install wtforms
pip install pymysql
pip install cryptography
pip install flask_restful
pip install flask_marshmallow
pip install marshmallow-sqlalchemy
pip install marshmallow
pip install pyOpenSSL
pip install requests
2023.3.25
安装flask_sqlalchemy时,会自动安装SQLAlchemy==2.0,但是我最初开发时,是基于1.4的,所以要重新安装旧的SQLAlchemy。有空再研究怎么升级到2.0。
pip uninstall SQLAlchemy
pip install SQLAlchemy==1.4.46
2023.9.21 同理
pip uninstall Flask-SQLAlchemy
pip install flask-SQLAlchemy==3.0.2
四、安装mysql并创建数据库
安装文档 by 阿里云
创建mysql账号
密码不要带@,否则sqlalchemy报错
create user 'admin'@'%' identified by '密码';
grant all privileges on *.* to 'admin'@'%' with grant option;
flush privileges;
CREATE DATABASE `uns` CHARACTER SET 'utf8mb4'; --这一步最好用客户端来创建
用flask建库
先把migrations文件夹删了(如果有)
flask db init
flask db migrate
flask db upgrade
然后,导入数据库初始静态数据
五、安装uwsgi服务器
pip install uwsgi
创建配置文件
cd /source/crm
vi uwsgi.ini
[uwsgi]
# 源码目录
chdir=/www/specialtime/source
static-map = /static=/www/specialtime/source/static
module=app
callable=app
# 启动配置
http=0.0.0.0:5002
socket=/www/specialtime/uwsgi/uwsgi.sock
pidfile=/www/specialtime/uwsgi/uwsgi.pid
daemonize=/www/specialtime/uwsgi/uwsgi.log
chmod-socket=777
logfile-chmod=644
# 性能配置
master=true
processes=2
threads=2
buffer-size=65535
# apscheduler相关
enable-threads=true
preload=true
lazy-apps=true
简易使用
前台启动(配置pidfile后就会自动变成后台启动)
uwsgi --ini uwsgi.ini
后台启动
nohup uwsgi --ini uwsgi.ini
关闭
uwsgi --stop uwsgi.pid
关闭防火墙(实际不需要关)
systemctl stop firewalld