部署

    • java >= 1.8

    • mongodb >= 2.6

    启动配置文件默认采用 格式,你可以根据自己的喜好使用其它配置 spring-boot 支持的文件格式。

    ** 配置文件路径

    • 当前目录的 /config 子目录
    • 当前目录
    • CLASSPATH /config 包目录
    • CLASSPATH 根目录

    该列表按优先顺序排列(在列表中较高的位置定义的属性会覆盖在较低位置定义的属性)。

    application.yaml

    一般在部署时只需要将 spring.data.mongodb.uri 配置参数修改为指定的 mongodb 连接地址,即可正常启动 duic。

    • server.port 服务端口(默认为 7777
    • spring.reactor.stacktrace-mode.enabled 启用 reactor 调用堆栈(默认为 true),设置为 false 可提高性能,但是不建议修改该配置项。更详细的解释请参考 reactor 官方文档
    • spring.data.mongodb.uri mongodb 数据库连接 uri
    • 应用程序基础配置
      • root-email ROOT 用户邮箱,如果用户不存在则会直接创建他
      • root-password ROOT 用户密码,初始创建时默认设置的密码
      • jwt 配置管理控制台登录安全信息,JWT 使用 HmacSHA256 算法生成
        • secret JWT 签名字符串
        • expires-in JWT 过期时间(单位:秒)
      • app.watch.updated.fixed-delay 监控数据库配置更新时间间隔周期默认为 5 秒扫描一次数据库,将更新的配置加载至内存中(单位:毫秒)
      • app.watch.deleted.fixed-delay 监控数据库配置删除时间音阶周期默认为 10 分钟挚友一次数据库,将删除的配置从内存中移除释放内存(单位:毫秒)

    更详细的解释请参考 spring-boot 官方文档 Application Property Files

    • 确认 java 环境至少是 1.8 或以上的版本
    1. $ java -version
    2.  
    3. java version "1.8.0_151"
    4. Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
    • 确认 mongo 环境至少是 2.6 或以上的版本并且服务已经启动
    1. $ mongo -version
    2.  
    3. MongoDB shell version: 2.6.3
    • 创建 duic 目录
    1. $ mkdir /opt/duic
    • 进入 duic 目录
    1. $ cd /opt/duic
    • 在 页面获取 duic-[version].jar 并放置在 /opt/duic 目录中
    1. $ wget https://github.com/zhudyos/duic/releases/download/1.4.1/duic-1.4.1.jar -O duic.jar

    Tip

    在部署时需要将 url 中的版本替换为你需要的版本号,最好从 GitHub Releases 找到合适的版本后复制下载地址

    • 创建配置文件目录
    1. $ mkdir config

    Tip

    确保当前目录是在 目录中

    • 进入配置文件目录
    • 创建启动配置文件
    1. $ touch application.yml
    • spring.data.mongodb.uri 写入 config/application.yml 配置文件
    1. spring:
    2. data:
    3. mongodb:
    4. uri: mongodb://127.0.0.1:27017/duic

    Tip

    确保 spring.data.mongodb.uri 正确可连接至数据库

    • 启动 duic
    1. $ java -Dspring.profiles.active=prod -jar duic.jar

    Tip

    在控制台看见如下日志输出即启动成功

    1. ______ _ ______
    2. |_ _ `. (_) .' ___ |
    3. | | `. \ __ _ __ / .' \_|
    4. | | | |[ | | | [ || |
    5. _| |_.' / | \_/ |, | |\ `.___.'\
    6. :: duic :: (v1.5.0-beta)
    7.  
    8. 2018-04-17 13:33:34,495 INFO i.z.d.server.Application$Companion - Starting Application.Companion v1.5.0-beta on bd29aece4869 with PID 5 (/app/duic.jar started by root in /app)
    9. 2018-04-17 13:33:34,516 INFO i.z.d.server.Application$Companion - The following profiles are active: prod
    10. 2018-04-17 13:33:42,835 INFO r.i.netty.tcp.BlockingNettyContext - Started HttpServer on /0.0.0.0:7777
    11. 2018-04-17 13:33:42,839 INFO o.s.b.w.e.netty.NettyWebServer - Netty started on port(s): 7777
    12. 2018-04-17 13:33:42,845 INFO i.z.d.server.Application$Companion - Started Application.Companion in 10.39 seconds (JVM running for 13.063)
    • 测试
    1. $ curl http://localhost:7777/index.html

    镜像已经同步至 docker 官方镜像仓库 https://hub.docker.com/r/zhudyos/duic

    • 拉取镜像
    1. $ docker pull zhudyos/duic
    • 确认 mongo 环境至少是 2.6 或以上的版本并且服务已经启动
    • 创建配置文件目录
    1. $ mkdir config
    • 进入配置文件目录
    1. $ cd config
    • 创建启动配置文件
    1. $ touch application.yml
    • spring.data.mongodb.uri 写入 config/application.yml 配置文件
    1. spring:
    2. data:
    3. mongodb:
    4. uri: mongodb://127.0.0.1:27017/duic

    Tip

    确保 spring.data.mongodb.uri 正确可连接至数据库

    • 启动镜像
    1. $ docker run -d -p 7777:7777 -v $(pwd)/config:/app/config zhudyos/duic

    Tip

    application.yml 配置文件所在目录挂载到容器的 目录中

    • 测试
    1. $ curl http://localhost:7777/index.html

    原文: https://github.com/zhudyos/duic/wiki/deployment