linux--项目部署

vue+drf的前后端分离部署笔记

前端部署过程

端口划分:

vue+nginx的端口 是81 

vue向后台发请求,首先发给的是代理服务器,这里模拟是nginx的 9000 

drf后台运行在  9005端口上

1.获取前端代码

新建vue_env的文件夹
根目录先执行:mkdir /vue_env
cd /vue_env

执行:wget https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip

2.解压缩,准备编译前端代码
unzip 07-luffy_project_01.zip

3.下载node源码,配置nodejs编译环境
wget https://nodejs.org/download/release/v8.6.0/node-v8.6.0-linux-x64.tar.gz

4.配置nodejs的环境变量

    tar -zxvf node-v8.6.0-linux-x64.tar.gz

    cd到解压缩后的文件夹,执行pwd,查看当前工作目录,将该目录添加到环境变量中
    [root@localhost bin]# vim  /etc/profile
    加入PATH中
        PATH="/opt/python367/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/vue_env/node-v8.6.0-        linux-x64/bin"

[root@localhost bin]# source /etc/profile

5.安装vue代码所需的模块

    进入前端代码的目录,找到package.json文件,里面定义了前端所需要的模块信息
    [root@my_linux 07-luffy_project_01]# pwd
    /vuedrf/07-luffy_project_01

6.修改vue的数据提交地址,修改如下配置文件

    /vuedrf/07-luffy_project_01/src/restful/api.js 

    批量替换ip地址信息
    sed -i  's/192.168.16.85:9000/192.168.200.134:9000/g'  src/restful/api.js  

7.执行安装模块的命令

    npm install 
    始编译前端代码,生成dist静态文件夹,前端所有代码,都打包编译生成了一个dist
    npm run build 

8.生成了dist静态文件夹之后,丢给nginx去处理即可

vim /etc/nginx/nginx.conf
	#返回路飞首页的静态文件服务器
	server {
	listen 81;
	server_name _;
	#最低级url匹配,所有请求都走到了这里
	location / {
	root  /vuedrf/07-luffy_project_01/dist;
	index  index.html;
	}

	}
	#反向代理虚拟主机,vue的请求转发给drf
	server {
	listen 9000;
	server_name _;
	location / {
	uwsgi_pass 0.0.0.0:9005;
	include uwsgi_params;
	}

	}

重启nginx 
	nginx -s reload 

	访问192.168.200.134:81 #页面出来了,点击其他功能模块时,不行,页面空白

后端部署过程
1.整一个新的路飞虚拟环境,然后下载后端代码
mkvirtualenv luffy_env
cd /etc/vue_env

2.下载后端代码
wget https://files.cnblogs.com/files/pyyu/luffy.zip
解压:unzip luffy.zip

cd  到解压后的文件夹

3.解决drf运行的模块问题(最好使用requirements.txt文件去处理模块问题)

	[root@web02 opt]# cat requirements.txt
	certifi==2018.11.29
	chardet==3.0.4
	crypto==1.4.1
	Django==2.1.4
	django-redis==4.10.0
	django-rest-framework==0.1.0
	djangorestframework==3.9.0
	idna==2.8
	Naked==0.1.31
	pycrypto==2.6.1
	pytz==2018.7
	PyYAML==3.13
	redis==3.0.1
	requests==2.21.0
	shellescape==3.4.1
	urllib3==1.24.1
	uWSGI==2.0.17.1
手动解决办法如下
 1099  pip3 install -i https://pypi.douban.com/simple django==2.1.4
 1100  python3 manage.py runserver
 1101  pip3 install -i https://pypi.douban.com/simple django-restframework
 1102  python3 manage.py runserv
 1103  pip3 install -i https://pypi.douban.com/simple djangorestframework
 1104  python3 manage.py runserv
 1105  python3 manage.py runserver
 1106  pip3 install -i https://pypi.douban.com/simple requests
 1107  python3 manage.py runserver
 1108  pip3 install -i https://pypi.douban.com/simple django_redis
 1109  python3 manage.py runserver
 1110  pip3 install -i https://pypi.douban.com/simple Crypto
 1111  python3 manage.py runserver
 1112  pip3 install -i https://pypi.douban.com/simple pycrypto

4.用uwsgi去启动drf后台
创建uwsgi.ini文件,写入如下参数

[uwsgi]
# Django-related settings
# the base directory (full path)
# 填写项目的完整绝对路径,第一层
chdir           = /vue_env/luffy
# Django's wsgi file
#指定django的wsgi文件路径,填写相对路径
module          = luffy.wsgi  
# the virtualenv (full path)
#填写虚拟环境的绝对路径
home            = /root/Envs/luffy_env
# process-related settings
# master
master          = true
# maximum number of worker processes
#定义程序的多进程数量的,以cpu核数的2倍+1数量填写   2n+1 数量 
processes       = 3
# the socket (use the full path to be safe
#把uwsgi启动在socket协议上,的8000端口

socket          = 0.0.0.0:9005


#指定http协议的话,用户是可以直接访问到的,不安全的,因此使用socket协议
#http =0.0.0.0:8000

# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true

5.使用supervisor进程管理工具,同管理crm和路飞的进程
[program:mycrm]
command=/root/Envs/mycrm/bin/uwsgi --ini /myfuxi/IGnb/uwsgi.ini ; 程序启动命令
autostart=true ; 在supervisord启动的时候也自动启动
stopasgroup=true ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
killasgroup=true ;默认为false,向进程组发送kill信号,包括子进程

[program:vue_env]
command=/root/Envs/luffy_env/bin/uwsgi --ini /vue_env/luffy/uwsgi.ini    ; 程序启动命令
autostart=true       ; 在supervisord启动的时候也自动启动
stopasgroup=true     ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
killasgroup=true     ;默认为false,向进程组发送kill信号,包括子进程

6.启动路飞后台
目前,先干掉所有的crm和supervisor,干掉前三思
pkill -9 uwsgi
pkill -9 supervisor

然后重启supervisor
(myluffy) [root@my_linux luffy]# supervisord -c /etc/supervisord.conf 
Unlinking stale socket /var/run/supervisor/supervisor.sock
(myluffy) [root@my_linux luffy]# 
(myluffy) [root@my_linux luffy]# 
(myluffy) [root@my_linux luffy]# supervisorctl -c /etc/supervisord.conf 
mycrm                           RUNNING   pid 42172, uptime 0:00:04
myluffy                         RUNNING   pid 42173, uptime 0:00:04

7.还得启动redis数据库,才能够访问购物车功能

1.安装redis
 yum install redis -y 
 2.启动redis
 systemctl start redis
 
 3.检查redis是否正常

8.访问路飞的课程列表,以及添加购物车数据

posted @ 2019-12-23 21:18  corei5tj  阅读(21)  评论(0编辑  收藏  举报