项目部署

centos

需求:安装mysql数据库, redis服务

1.正式环境使用nginx+uwsgi部署django项目

在根目录环境下,/home文件里创建新文件夹/code 、/conf 、/env
将代码文件复制到/code文件下


代码文件.png
1.1安装Python3.7

centos默认只有Python2.7版本, 而项目使用Python3.7版本

a) 安装Python3.7依赖包

yum -y groupinstall "Development tools"

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

yum install libffi-devel -y

b)下载安装Python3.7

wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz

解压压缩包,安装Python3
tar -xvJf Python-3.7.4.tar.xz
cd Python-3.7.4
./configure --prefix=/usr/local/python3
make && make instal


python安装包.png

c)创建软链接

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

1.2安装环境

a) 安装virtualenv

yum install python-virtualenv

b)创建虚拟环境

在env文件下:python3 -m venv axfenv
激活虚拟环境:source bin/activate

c)使用绝对路径安装包

/home/env/axfenv/bin/pip3 install -r /home/code/axf/requirement.txt

此项目所需安装包

django==2.0.7
pymysql
djangorestframework
django-filter
django-cors-headers
django-redis

2.1安装nginx

a)settings.py的修改

修改settings.py配置文件中的DEBUG=False模式,修改ALLOEWD_HOST=['*']

b) 添加nginx存储库

yum install epel-release

c) 安装nginx

yum install nginx

d)nginx命令

启动nginx: systemctl start nginx
查看nginx状态:systemctl status nginx
重启nginx:systemctl restart nginx

e)修改配置文件

vim /etc/nginx/nginx.conf
在36行下面加入:include /home/conf/*.conf;
并重启nginx


修改配置文件.png

2.部署uwsgi

启动redis服务,启动nginx,服务器打开8000端口

后台服务.png
2.1配置文件

WebStorm打开项目, 命令行输入

npm run build

创建dist文件夹,将dist文件复制放入/code文件夹下


dist.png

修改main.js中的baseURL为服务器的ip地址

2.2部署uwsgi

a)安装uwsgi
在虚拟环境中安装uwsgi,假设虚拟环境安装在/home/env/axfenv中

/home/env/axfeng/bin/python3/pip3 install uwsgi

b)创建conf配置文件
创建nginx配置文件axfnginx.conf并重启nginx:

  server {
          listen 80;
          server_name <服务器ip>;
  
          root /home/code/dist;
          index index.html;
  
          location /api {
                  include uwsgi_params;
                  uwsgi_pass 127.0.0.1:8080;
          }
  } 

创建uwsgi配置文件axfuwsgi.ini:

  [uwsgi]
  master=true
  chdir=/home/code/axf
  pythonpath=/home/env/axfenv/bin/python3
  module=axf.wsgi
  socket=127.0.0.1:8080
  logto=/home/logs/uwsgi.log

c)启动uwsgi

/home/env/axfenv/bin/uwsgi --ini axfuwsgi.ini

同时WebStorm启动服务

npm run dev

你可能感兴趣的:(项目部署)