使用 PostgreSQL 部署

duic 支持使用 PostgreSQL 存储配置数据。

前提

  • Java >= 1.8

  • PostgreSQL >= 9.5

创建数据库

  1. CREATE DATABASE duic;

启动配置

application.yml

  1. spring:
  2. datasource:
  3. url: jdbc:postgresql://127.0.0.1:5432/duic
  4. username: postgres
  5. password: postgres
参数详细解释


-
spring.datasource 数据源


-
url PostgreSQL 连接地址

-
username PostgreSQL 连接用户

-
password PostgreSQL 连接用户密码


docker 部署

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

  • 启动镜像
  1. $ docker run -d -p 7777:7777 -e DUIC_OPTS=-Dspring.profiles.active=postgresql -v $(pwd)/config:/app/config zhudyos/duic

Tip

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

  • 通过 DUIC_OPTS 环境变量设置数据库类型

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

传统 java 方式部署

  • 确认 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)
  5. Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
  • 创建 duic 目录
  1. $ mkdir /opt/duic
  • 进入 duic 目录
  1. $ cd /opt/duic
  • GitHub Releases 页面获取 duic-[version].jar 并放置在 /opt/duic 目录中
  1. $ wget https://github.com/zhudyos/duic/releases/download/[version]/duic-[version].jar -O duic.jar

Tip

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

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

Tip

确保 config/opt/duic 的子目录

  • 进入配置文件目录
  1. $ cd config
  • 创建启动配置文件/并将数据库连接配置写入文件
  1. $ touch application.yml
  • 启动 duic
  1. $ java -Dspring.profiles.active=postgresql -jar duic.jar

Tip

spring.profiles.active

  • postgresql 使用 PostgreSQL 存储配置数据时该参数必须增加

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

  1. ______ _ ______
  2. |_ _ `. (_) .' ___ |
  3. | | `. \ __ _ __ / .' \_|
  4. | | | |[ | | | [ || |
  5. _| |_.' / | \_/ |, | |\ `.___.'\
  6. |______.' '.__.'_/[___]`.____ .'
  7. :: duic ::
  8.  
  9. 2018-05-31 13:48:19,330 INFO i.z.d.server.Application$Companion - Starting Application.Companion on USER-20170412BX with PID 6936 (D:\work\projects\duic\out\production\classes started by Administrator in D:\work\projects\duic)
  10. 2018-05-31 13:48:19,342 INFO i.z.d.server.Application$Companion - The following profiles are active: postgresql
  11. 2018-05-31 13:48:19,420 INFO o.s.b.w.r.c.AnnotationConfigReactiveWebServerApplicationContext - Refreshing org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@5cbe877d: startup date [Thu May 31 13:48:19 CST 2018]; root of context hierarchy
  12. 2018-05-31 13:48:21,317 INFO o.s.w.r.f.s.s.RouterFunctionMapping - Mapped /api/v1 => {
  13. (GET && /ssc/{name}/{profile}) -> org.springframework.web.reactive.function.server.RouterFunctionDsl$GET$1@41ad373
  14. /apps => {
  15. (GET && /states/{name}/{profile}) -> org.springframework.web.reactive.function.server.RouterFunctionDsl$GET$1@6801b414
  16. (GET && /watches/{name}/{profile}) -> org.springframework.web.reactive.function.server.RouterFunctionDsl$GET$1@177c41d7
  17. (GET && /{name}/{profile}) -> org.springframework.web.reactive.function.server.RouterFunctionDsl$GET$1@4f327096
  18. (GET && /{name}/{profile}/{key}) -> org.springframework.web.reactive.function.server.RouterFunctionDsl$GET$1@1d61a348
  19. }
  20. }
  21. /servers => {
  22. (POST && /apps/refresh) -> org.springframework.web.reactive.function.server.RouterFunctionDsl$POST$1@78a515e4
  23. (GET && /last-data-time) -> org.springframework.web.reactive.function.server.RouterFunctionDsl$GET$1@d2291de
  24. }
  25. 2018-05-31 13:48:21,317 INFO o.s.w.r.f.s.s.RouterFunctionMapping - Mapped org.springframework.web.reactive.function.server.RouterFunctions$FilteredRouterFunction@28f4f300
  26. 2018-05-31 13:48:21,329 INFO o.s.w.r.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.reactive.resource.ResourceWebHandler]
  27. 2018-05-31 13:48:21,364 INFO o.s.w.r.r.m.a.ControllerMethodResolver - Looking for @ControllerAdvice: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@5cbe877d: startup date [Thu May 31 13:48:19 CST 2018]; root of context hierarchy
  28. 2018-05-31 13:48:21,750 INFO o.f.c.internal.util.VersionPrinter - Flyway Community Edition 5.0.7 by Boxfuse
  29. 2018-05-31 13:48:21,752 INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
  30. 2018-05-31 13:48:21,820 INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
  31. 2018-05-31 13:48:21,825 INFO o.f.c.i.database.DatabaseFactory - Database: jdbc:postgresql://192.168.31.164:5432/duic (PostgreSQL 10.4)
  32. 2018-05-31 13:48:21,876 INFO o.f.c.internal.command.DbValidate - Successfully validated 4 migrations (execution time 00:00.021s)
  33. 2018-05-31 13:48:21,900 INFO o.f.core.internal.command.DbMigrate - Current version of schema "public": 1.8.0.3
  34. 2018-05-31 13:48:21,901 INFO o.f.core.internal.command.DbMigrate - Schema "public" is up to date. No migration necessary.
  35. 2018-05-31 13:48:21,997 INFO o.s.j.e.a.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
  36. 2018-05-31 13:48:21,998 INFO o.s.j.e.a.AnnotationMBeanExporter - Bean with name 'dataSource' has been autodetected for JMX exposure
  37. 2018-05-31 13:48:22,003 INFO o.s.j.e.a.AnnotationMBeanExporter - Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
  38. 2018-05-31 13:48:22,011 INFO o.s.s.a.ScheduledAnnotationBeanPostProcessor - No TaskScheduler/ScheduledExecutorService bean found for scheduled processing
  39. 2018-05-31 13:48:22,178 INFO r.i.netty.tcp.BlockingNettyContext - Started HttpServer on /0:0:0:0:0:0:0:0:7777
  40. 2018-05-31 13:48:22,178 INFO o.s.b.w.e.netty.NettyWebServer - Netty started on port(s): 7777
  41. 2018-05-31 13:48:22,183 INFO i.z.d.server.Application$Companion - Started Application.Companion in 3.497 seconds (JVM running for 4.756)
  • 测试
  1. $ curl http://localhost:7777/index.html

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