以前有介绍过 aceql-http 一个不错的 database REST http 暴露, 充分利用了 tomcat 的好多特性, 以下是基于 docker 运行的学习
环境准备
- dockerfile
- FROM dalongrong/openjdk11:stretch-jvm-tools
- LABEL AUTHOR="rongfengliang"
- LABEL EMAIL="[email protected]"
- ENV VERSION=4.0
- ENV ACEQL_HTTP_HOST=localhost
- WORKDIR /App
- RUN wget https://www.aceql.com/rest/soft/${
- VERSION
- }/download/aceql-http-${
- VERSION
- }.run \
- && chmod +x aceql-http-${
- VERSION
- }.run \
- && sh aceql-http-${
- VERSION
- }.run \
- && rm -rf aceql-http-${
- VERSION
- }.run
- ENV PATH=$PATH:/App/aceql-http-${
- VERSION
- }/bin
- ENV ACEQL_HOME=/App/aceql-http-${
- VERSION
- }
- COPY aceql-server.properties /App/aceql-http-${
- VERSION
- }/conf/aceql-server.properties
- COPY entrypoint.sh /entrypoint.sh
- RUN chmod +x /entrypoint.sh
- EXPOSE 9090
- ENTRYPOINT [ "/entrypoint.sh" ]
简单说明: 基础镜像使用了 openjdk11, 此镜像集成了一些 jvm 性能监控工具, 因为 aceql-http 使用了 makeself
直接执行就可以解压安装包内容了
entrypoint.sh: 入口
- #!/bin/sh
- aceql-server -start -host ${
- ACEQL_HTTP_HOST
- } -port 9090
aceql-server.properties 数据库连接, 这个比较简单, 为了方便修改为了 pg 的 (使用 docker-compose 的服务)
此文件没有配置用户认证的, 如果查看说明以及源码会发现, 不配置使用默认, 实际上是裸奔的, login 方法直接
返回 true, 所以如果需要认证, 可以使用文档介绍的 jwt, 具体参考文档
- # Database names separated by commas
- databases = postgres
- ?
- # Mandatory JDBC properties:
- ?
- # PostgreSQL example
- postgres.driverClassName = org.PostgreSQL.Driver
- postgres.url= jdbc:PostgreSQL://postgres:5432/postgres
- postgres.username= postgres
- postgres.password= dalong
docker-compose 服务
- version: "3"
- services:
- postgres:
- image: postgres:9.5-alpine
- ports:
- - "5432:5432"
- environment:
- - "POSTGRES_PASSWORD:dalong"
- aceql-http:
- build: ./
- volumes:
- - "./flame:/app/arthas-output"
- ports:
- - "9090:9090"
启动 && 测试
构建镜像
docker-compose build
初始化数据库
- CREATE TABLE appdemos (
- id SERIAL PRIMARY KEY,
- appname text
- );
- CREATE TABLE user_login
- (
- username varchar(255) not null,
- hash_password varchar(40) not null,
- PRIMARY KEY (username)
- );
- insert into user_login values ('username', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8');
- insert into user_login values ('MyUsername', 'eabbec6f31804eb968e2faeaaef150546a595fc3');
请求 sessionid
说明, 此处任何的用户账户都可以, 因为使用的默认认证, 永远返回 true, 直接看官方文档可能还会迷惑
- curl --data-urlencode "password=MySecret" \
- http://localhost:9090/aceql/database/postgres/username/MyUsername/connect
返回内容
insert 数据
curl --data-urlencode "sql=insert into appdemos values (1,'dalongdemo')" http://localhost:9090/aceql/session/ra6x1jbw463x5svw32thonn4l7/execute_update
返回内容
查询数据
curl --data-urlencode "sql=select * from appdemos" --data "pretty_printing=true" http://localhost:9090/aceql/session/ra6x1jbw463x5svw32thonn4l7/execute_query
返回内容
说明
以上就是关于 aceql-http docker 运行的一些学习, 后续可以在学习下 jwt 以及自定义认证的
参考资料
- https://github.com/rongfengliang/aceql-http-docker
- https://github.com/kawansoft/aceql-http
来源: http://www.bubuko.com/infodetail-3396698.html