接口文档RAP2 环境搭建(正常搭建成功)

RAP2 是采用先后端分离的形式,所以搭建完整的 RAP2 须要 服务端:rap2-delos客户端:rap2-dolores 同时部署html

部署 RAP2 须要亲具备 Node+Linux+MySQL 的运维知识,若是亲对此不是很了解,建议用 http://rap2.taobao.org 线上版本就能够前端

因为 客户端:rap2-dolores 是创建在 服务端:rap2-delos 基础上,所以先搭建服务端应用node

  • 截至到 2018-08-01 delos 并无发布 Tag 版本,应该还处于功能开发前期阶段吧。本教程是在 CentOS 机器上实战部署
  • 然而安装部署并非顺利,所以记录踩过的坑(别问我为啥不用 Docker,由于我司分配的机器没法知足 Docker 的最低内核版本),安装环境介绍:Redis,delos,dolores 均在一台服务器,MySQL 使用已存在的服务

安装基本工具

  • Git
  • Node 8.9.4+
  • Redis 4.0+
  • MySQL 5.7+

以上基本工具请根据自身须要,下载对应系统安装包,请自行解决安装配置等问题,这里不作过多说明mysql

Redis 安装可参考 Linux 经常使用应用安装
Redis 最好用非安全模式启动
linux

服务端 delos 环境搭建

构建项目

构建项目前,请确认 Node,Redis,MySQL 服务均能正常使用nginx

1
git clone https://github.com/thx/rap2-delos.git

环境配置

建立数据库

  • Mac or Linuxgit

    1
    mysql -e 'CREATE DATABASE IF NOT EXISTS RAP2_DELOS_APP DEFAULT CHARSET utf8 COLLATE utf8_general_ci';
  • Windows 环境github

    进入 mysql 命令后执行redis

    1
    CREATE DATABASE IF NOT EXISTS RAP2_DELOS_APP DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

配置文件

目录:rap2-delos/src/config
文件:config.dev.ts; 其中 dev,表示开发环境,其余同理
修改:config.dev.ts文件中db对象中usernamepassword参数与本地或者开发环境的数据库信息匹配sql

import { IConfigOptions } from "../types";

let config: IConfigOptions = {

version: '2.3',

serve: {

   port: 8888 //你本身设置的端口,我是设置的8888

}, keys: ['some secret hurr'],

session: {

   key: 'rap2:sess'

},

db: {

  dialect: 'mysql',

  host: 'localhost', //mysql服务器的ip,这里我是用的本地的mysql

  port: 3306,

  username: 'root', //mysql用户名

  password: 'root', //mysql密码

  database: 'RAP2_DELOS_APP', //rap2的后台数据库名

pool: {

  max: 5, 

  min: 0,

  idle: 10000

},

logging: false

},

redis:{

  host: 'localhost',

  port: 6379

 }

}

export default config

启动项目

安装项目依赖包

项目根目录下执行

1
2
3
4
# 安装项目所需依赖
npm install
# 全局安装PM2
npm install -g pm2

安装 TypeScript 编译包

1
npm install typescript -g

若是下载缓慢,请使用淘宝 npm 镜像

初始化数据库(必需要执行的,生成数据库初始化数据)

项目根目录下执行 (该过程比较慢,耐心等待初始化完成)

1
npm run create-db

编译启动项目(可执行,也能够不执行,知识作代码检查)

执行 mocha 测试用例和 js 代码规范检查

1
npm run check

 

  • 开发模式
    启动开发模式的服务器 监视并在发生代码变动时自动重启 (第一次运行比较慢,请耐心等待)

    1
    npm run dev
  • 生产模式
    启动生产模式服务器

    1
    npm start

看到浏览器中以下提示,表示服务端 delos 已经部署成功

RAP2 后端服务已启动,请从前端服务 (rap2-dolores) 访问。 RAP2 back-end server is started, please visit via front-end service (rap2-dolores).

或者在程序控制台出现以下 Log,表示服务端 delos 已经部署成功
delos

常见问题

部署问题

      1. Windows 下执行npm run build,提示'rm' 不是内部或外部命令,也不是可运行的程序或批处理文件

        缘由:rm 是 Linux 下命令,
        解决方法:Windows 系统可以使用 git bash 打开该项目,执行该命令

      2. 执行npm run create-db命令,提示Unable to connect to the database:{ SequelizeAccessDeniedError: Access denied for user 'root'@'localhost' (using password:NO)}

        缘由:未修改rap2-delos/src/config目录下数据库配置文件,或者是与文件中的数据库信息与之链接的数据库信息不匹配
        解决方法:修改config.dev.ts文件数据库配置信息

        若是修改正确无误后,执行npm run create-db依旧出错,那么查看该项目中是否已经存在dist目录,若是有,请按照如上修改对应的数据库配置信息

      3. 执行npm run dev命令,提示Error: listen EADDRINUSE :::8080
        缘由:8080 端口被占用
        解决方法:杀掉占用 8080 端口的应用
      4. 执行npm install 命令,提示hiredis 编译没法经过
        缘由:无权限操做rap2-delos/node_modules/hiredis路径
        解决方法:sudo npm install

        若是提示sudo: npm: command not found,请参考 stackoverflow-npm,stackoverflow-node

      5. 执行npm run dev能够正常启动,npm start命令没法正常启动服务
        缘由:请使用pm2 logs查看日志具体定位
        示例:因为 Redis 的安全模式,不能正常使用

        1
        2
        3
        4
        5
        6
        7
        ReplyError: Ready check failed: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 

        1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.
        2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server.
        3) If you started the server manually just for testing, restart it with the '--protected-mode no' option.
        4) Setup a bind address or an authentication password.
        NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

        解决方法: 使用--protected-mode no方式启动

      6. 执行npm run create-db时,ts编译出错,提示ctx上下问出错,那么在项目根目录中找到tsconfig.js,修改noImplicitAny的值为false便可(注意:默认是true,npm run create-db时就会报错)
      7. redis 清除缓存
      8. 运行redis-cli     执行flushall命令清空缓存
        八、若是出现 is not allowed to connect to this mysql server的解决办法

                                  use mysql;

                                 select host from user where user='root';

                                 update user set host = '%' where user ='root'

客户端 dolores 环境搭建

构建项目

获取源代码

1
git clone https://github.com/thx/rap2-dolores.git

环境配置

配置文件

目录:rap2-dolores/src/config
文件:config.dev.ts; 其中 dev,表示开发环境,其余同理
修改:config.dev.ts文件,serve地址是 服务端 rap2-delos 部署成功后的地址,默认:'http://localhost:8080'

在苹果系统下:sudo npm install   在install node-sass时存在权限问题,须要执行:sudo npm install  --unsafe-perm=true --allow-root 才能够进行安装

启动项目

安装项目依赖包

项目根目录下执行

1
npm install

若是下载缓慢,请使用淘宝 npm 镜像

编译启动项目

  • 开发模式
    自动监视改变后从新编译

    1
    npm run dev

    备注:测试用例

    1
    npm run test
  • 生产模式
    编译 React 生产包

    1
    npm run build

    用 serve 命令或 nginx 服务器路由到编译产出的 build 文件夹做为静态服务器便可

    1
    serve -s ./build -p 80

看到浏览器中出现登陆页面,表示部署成功
dolores

常见问题

部署问题

  1. 执行npm run dev,提示

    1
    2
    3
    return process.dlopen(module,path._makeLong(filename))
    ...
    ...node_modules\node-sass\vendor\win32-x64-57\binding.node is not a valid Win32 application...

    缘由:项目依赖包node-sass没有安装彻底
    解决方法:npm install node-sass

  2. 项目运行起来,但一直停留在加载动画那里

    浏览器控制台输出:
    GET http://127.0.0.1:8080/account/info ==>> Failed to load http://127.0.0.1:8080/account/info

    缘由:未修改rap2-delos/src/config目录下服务端链接地址, 或者修改结果与 rap2-dolores实际提供服务地址不匹配
    解决方法:修改config.dev.ts文件 serve 配置信息

    若是 Windows 系统修改正确无误后,依旧出错,那么查看 hosts(路径:C:\Windows\System32\drivers\etc) 中 127.0.0.1 的 IP 前是否有#,若是有请取消注释

其余

MySQL 运行问题

  • 错误一
    mysql
    缘由:MySQL 集成命令没有加入系统的环境变量
    解决方法:将安装的 MySQL Service 路径加入系统变量
    path
  • 错误二
    create
    缘由:没有数据库连接权限
    解决方法:先登陆用 root 数据库,密码具体看本身数据库当时设置的密码

如何获取更新

目前请选择master分支源码,后续其余分支请看相应分支说明文档。在开发环境中 git pull 来获取最新的源码更新,每一期更新都会有对应的 update.md 请关注并按照上面的指示进行升级工做。

附录

相关文章
相关标签/搜索