请参考个人其它文章:Installing stable Python3.7.3 in CentOS7.5 --项目部署python
请参考个人其它文章:Installing the stable nginx-1.16.0 in CentOS7.5(source installation) --项目部署mysql
请参考个人其它文章:Installing and configuring MySql5.6 In CentOS7.5 --项目部署
安装完成后,将开发环境中的数据库文件导出:nginx
thanlon@thanlon-Ubuntu:~$ mysqldump -uroot -p blueflag>db.sql
上传到服务器中,sql
thanlon@thanlon-Ubuntu:~$ scp db5.15.sql root@106.12.115.123:/root/db_file/
建立和use数据库后,经过source指令导入到MySQL中,数据库
source db.sql
[root@instance-mtfsf05r ~]# mkdir flask
thanlon@thanlon-Ubuntu:~/pythonWeb$ scp -r blueflag root@106.12.115.136:/root/flask
[root@instance-mtfsf05r ~]# pip3 install virtualenv
[root@instance-mtfsf05r ~]# cd flask/blueflag [root@instance-mtfsf05r blueflag]# virtualenv blueflagvenv
[root@instance-mtfsf05r blueflag]# source blueflagvenv/bin/activate
激活后出现虚拟化环境文件目录名子:(blueflagvenv) [root@instance-mtfsf05r blueflag]#
,说明激活成功,当前正处于Python虚拟环境flask
根据项目的需求安装(在虚拟环境中安装),例如:个人这些库segmentfault
(blueflagvenv) [root@instance-mtfsf05r blueflag]# pip install flask (blueflagvenv) [root@instance-mtfsf05r blueflag]# pip install wtforms (blueflagvenv) [root@instance-mtfsf05r blueflag]# pip install flask_sqlalchemy (blueflagvenv) [root@instance-mtfsf05r blueflag]# pip install requests (blueflagvenv) [root@instance-mtfsf05r blueflag]# pip install pymysql (blueflagvenv) [root@instance-mtfsf05r blueflag]# pip install flask_script
还可使用:安全
thanlon@thanlon-Ubuntu:~$ pip3 freeze>blueflag.txt
导出依赖包,而后直接经过:服务器
(blueflagvenv) [root@instance-mtfsf05r blueflag]# pip install -r blueflag.txt
安装这些依赖包。网络
(blueflagvenv) [root@instance-mtfsf05r blueflag]# pip install uwsgi
(blueflagvenv) [root@instance-mtfsf05r blueflag]# touch uwsgiconf.ini
在uwsgiconf.ini文件中写入下面代码块的内容:(记得把注释所有删掉)
[uwsgi] socket = 127.0.0.1:8001#启动程序时所使用的地址和端口 chdir = /root/flask/blueflag/#项目目录 wsgi-file = manager.py#项目程序启动文件 callable = app#程序内启用的application变量名字 processes = 2#处理器的数量,个人是2个处理器 threads = 2 #线程数量 stats = 127.0.0.1:9191#获取uwsgi统计信息的服务地址 ~
这样安装和配置uWSGI就完成了
配置Nginx做为代理的目的是保证项目的安全和负载均衡。当存在网络请求时,Nginx先进行处理,而后再将请求交给uWSGI处理。
[root@instance-mtfsf05r ~]# vi /usr/local/nginx/conf/nginx.conf
server { listen 80; server_name 106.12.123.123; #charset koi8-r; #access_log logs/host.access.log main; access_log /root/flask/blueflag/logs/access.log;#服务器接收的请求日志 error_log /root/flask/blueflag/logs/error.log;#错误日志 locatior / { include uwsgi_params; #这里是导入的uwsgi配置 uwsgi_pass 127.0.0.1:8001;#须要和uwsgi的配置文件里socket项的地址 uwsgi_param UWSGI_PYHOME /root/flask/blueflag/blueflagvenv;#python的位置(虚拟环境下) uwsgi_param UWSGI_CHDIR /root/flask/blueflag;#项目根目录 uwsgi_param UWSGI_SCRIPT manager:app; }
[root@instance-mtfsf05r ~]# nginx
[root@instance-mtfsf05r blueflag]# cd /root/flask/blueflag/ [root@instance-mtfsf05r blueflag]# source blueflagvenv/bin/activate (blueflagvenv) [root@instance-mtfsf05r blueflag]# uwsgi uwsgiconf.ini
经过服务器IP地址访问你的项目,正常访问,则部署上线成功