1 Star 0 Fork 6

ryvius_key / baoai

forked from 源宝网络 / baoai 
Clone or download
deploy.md
Copy Edit Web IDE Raw Normal History
源宝网络   BaoAI初始化 2020-03-10
建议部署在Linux环境## BaoAI Front前端部署- nginx 做为 Web前端服务器- 反向代理,用户无需访问后端API服务地址如:原API服务地址:localhost:8000/api反向代理:localhost:3000/api 代替 localhost:8000/api- URL地址采用HTML5Mode模式如正常模式: http://www.baoai.co/#/web/main HTML5Mode模式:http://www.baoai.co/web/main CentOS 7 例子:```# 显示中文export LANG=zh_CN.GB2312# 添加CentOS 7 EPEL仓库yum install epel-release```1.构建生产代码:```# BaoAIFront项目根目录gulp build```将dist目录下的文件复制到centos的/baoai/BaoAIFront目录2.安装nginx```# 现在Nginx存储库已经安装在您的服务器上,使用以下yum命令安装Nginxyun install -y nginx# 启动Nginxsystemctl start nginx# 如果想在系统启动时启用Nginxsystemctl enable nginx```3.修改配置文件nginx.confnginx.conf默认在 /etc/nginx/nginx.conf```  upstream node {      server 127.0.0.1:8000;  }  server {    listen 80;    server_name _;    access_log /data/wwwlogs/access_nginx.log combined;    root /baoai/BaoAIFront;    index index.html index.htm index.php;        if ($request_uri ~ ^/(static|login|register|password|app|api)) {                set $cookie_nocache 1;        }        location / {            index  index.html index.htm index.php;            try_files $uri $uri/ /index.html =404;            # proxy_cache cache;            # proxy_cache_valid   200 304 12h;            # proxy_cache_valid   any 10m;            # add_header  Nginx-Cache "$upstream_cache_status";            # proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;            # proxy_no_cache $cookie_nocache $arg_nocache $arg_comment;            # proxy_no_cache $http_pargma $http_authorization;        }        location ^~ /static/ {            proxy_pass http://node;            proxy_set_header Host $http_host;            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;            # proxy_cache cache;            # proxy_cache_valid   200 304 12h;            # proxy_cache_valid   any 10m;            # add_header  Nginx-Cache "$upstream_cache_status";            # proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;            # proxy_no_cache $cookie_nocache $arg_nocache $arg_comment;            # proxy_no_cache $http_pargma $http_authorization;        }        location ^~ /api/             proxy_pass http://node;            proxy_set_header Host $host;            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                      # proxy_cache cache;            # proxy_cache_valid   200 304 12h;            # proxy_cache_valid   any 10m;            # add_header  Nginx-Cache "$upstream_cache_status";            # proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;            # proxy_no_cache $cookie_nocache $arg_nocache $arg_comment;            # proxy_no_cache $http_pargma $http_authorization;        }    #error_page 404 /404.html;    #error_page 502 /502.html;    location /nginx_status {      stub_status on;      access_log off;      allow 127.0.0.1;      deny all;    }    # location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {    #   expires 30d;    #   access_log off;    # }    # location ~ .*\.(js|css)?$ {    #   expires 7d;    #   access_log off;    # }    location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {      deny all;    }  }  ```4.重启nginxsystemctl restart nginx## BaoAI Back后端部署- 复制源码至服务器- 安装mariadb【mysql】数据库- 安装Python环境   + 安装 Python3.6.5   + 创建虚拟环境 venv   + 虚拟环境中安装依赖包- gunicorn 做为 wsgi服务器- supervisor 做为管理和守护程序CentOS 7 例子:```# 显示中文export LANG=zh_CN.GB2312# 添加CentOS 7 EPEL仓库yum install epel-release```1.将BaoAIBack源码复制到/baoai/BaoAIBack2.安装mariadb【mysql】注:MariaDB 数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用 GPL 授权许可。开发这个分支的原因之一是:甲骨文公司收购了 MySQL 后,有将 MySQL 闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB完全兼容mysql,使用方法也是一样的```# 安装mariadb-serveryum install mariadb-server# MariaDB服务开启,并设置为开机启动systemctl start mariadb  # 开启服务systemctl enable mariadb  # 设置为开机自启动服务# 数据库的配置mysql_secure_installationEnter current password for root (enter for none):  # 输入数据库超级管理员root的密码(注意不是系统root的密码),第一次进入还没有设置密码则直接回车Set root password? [Y/n]  # 设置密码,yNew password:  # 新密码Re-enter new password:  # 再次输入密码Remove anonymous users? [Y/n]  # 移除匿名用户, yDisallow root login remotely? [Y/n]  # 拒绝root远程登录,n,不管y/n,都会拒绝root远程登录Remove test database and access to it? [Y/n]  # 删除test数据库,y:删除。n:不删除,数据库中会有一个test数据库,一般不需要Reload privilege tables now? [Y/n]  # 重新加载权限表,y。或者重启服务也可# 登录MariaDB [mysql][root@mini ~]# mysql -u root -pEnter password:Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 8Server version: 5.5.60-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]># 创建数据库MariaDB [(none)]>create database baoai;# 进入数据库MariaDB [(none)]>use baoai;# 导入脚本MariaDB [(none)]>source /baoai/BaoAIBack/db/baoai.sql;3.安装Python 3.6yum install -y python36 python36-devel# 查看版本python3 -Vpip3 -V```4.创建虚拟环境```# 进入项目目录cd /baoai/BaoAIBack/mkdir venvcd venvpython3 -m venv .运行source /baoai/BaoAIBack/venv/bin/activate# 查看版本python -V# 升级pippip3 install --upgrade pip```5.依赖包导入```pip install  -r requirements.txt# 如果速度慢,可以使用国内镜像pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt```6.测试运行(venv) /baoai/BaoAIBack>python manage.py runserver --threaded5.gunicorn运行项目./run_baoai.sh6.安装supervisor```# systemctl enable supervisord # 开机自启动# systemctl start supervisord # 启动supervisord服务# systemctl status supervisord # 查看supervisord服务状态# ps -ef|grep supervisord # 查看是否存在supervisord进程```7.加入baoai程序```cp /baoai/BaoAIBack/deploy/baoai.ini /etc/supervisord.d/重启supervisorsupervisorctl restart all 或 supervisorctl restart baoai查看状态supervisorctl status停止应用supervisorctl stop all 或 supervisorctl stop baoai```8.关闭所有python应用```./kill_python.sh```
Python
1
https://gitee.com/ryvius_key/baoai.git
git@gitee.com:ryvius_key/baoai.git
ryvius_key
baoai
baoai
master

Search