Quickstart with Docker-Compose

Requirement

Start HStream requires an operating system kernel version greater than at least Linux 4.14

Installation

Install docker

TIP

If you have already installed docker, you can skip this step.

See Install Docker EngineGetting Started - 图1 (opens new window), and install it for your operating system. Please carefully check that you have met all prerequisites.

Confirm that the Docker daemon is running:

  1. docker version

TIP

On Linux, Docker needs root privileges. You can also run Docker as a non-root user, see Post-installation steps for LinuxGetting Started - 图2 (opens new window).

Install docker compose

TIP

If you have already installed docker compose, you can skip this step.

See Install Docker ComposeGetting Started - 图3 (opens new window), and install it for your operating system. Please carefully check that you met all prerequisites.

  1. docker-compose version

Start HStreamDB Services

WARING

Do NOT use this configuration in your production environment!

Create a docker-compose.yaml file for docker compose, you can downloadGetting Started - 图4 (opens new window) or paste the following contents:

  1. # quick-start.yaml
  2. version: "3.5"
  3. services:
  4. hserver0:
  5. image: hstreamdb/hstream:v0.11.0
  6. depends_on:
  7. - zookeeper
  8. - hstore
  9. ports:
  10. - "127.0.0.1:6570:6570"
  11. expose:
  12. - 6570
  13. networks:
  14. - hstream-quickstart
  15. volumes:
  16. - /var/run/docker.sock:/var/run/docker.sock
  17. - /tmp:/tmp
  18. - data_store:/data/store
  19. command:
  20. - bash
  21. - "-c"
  22. - |
  23. set -e
  24. /usr/local/script/wait-for-storage.sh hstore 6440 zookeeper 2181 600 \
  25. /usr/local/bin/hstream-server \
  26. --bind-address 0.0.0.0 --port 6570 \
  27. --internal-port 6571 \
  28. --server-id 100 \
  29. --seed-nodes "$$(hostname -I | awk '{print $$1}'):6571,hserver1:6573" \
  30. --advertised-address $$(hostname -I | awk '{print $$1}') \
  31. --metastore-uri zk://zookeeper:2181 \
  32. --store-config /data/store/logdevice.conf \
  33. --store-admin-host hstore --store-admin-port 6440 \
  34. --io-tasks-path /tmp/io/tasks \
  35. --io-tasks-network hstream-quickstart
  36. hserver1:
  37. image: hstreamdb/hstream:v0.11.0
  38. depends_on:
  39. - zookeeper
  40. - hstore
  41. ports:
  42. - "127.0.0.1:6572:6572"
  43. expose:
  44. - 6572
  45. networks:
  46. - hstream-quickstart
  47. volumes:
  48. - /var/run/docker.sock:/var/run/docker.sock
  49. - /tmp:/tmp
  50. - data_store:/data/store
  51. command:
  52. - bash
  53. - "-c"
  54. - |
  55. set -e
  56. /usr/local/script/wait-for-storage.sh hstore 6440 zookeeper 2181 600 \
  57. /usr/local/bin/hstream-server \
  58. --bind-address 0.0.0.0 --port 6572 \
  59. --internal-port 6573 \
  60. --server-id 101 \
  61. --seed-nodes "hserver0:6571,$$(hostname -I | awk '{print $$1}'):6573" \
  62. --advertised-address $$(hostname -I | awk '{print $$1}') \
  63. --metastore-uri zk://zookeeper:2181 \
  64. --store-config /data/store/logdevice.conf \
  65. --store-admin-host hstore --store-admin-port 6440 \
  66. --io-tasks-path /tmp/io/tasks \
  67. --io-tasks-network hstream-quickstart
  68. hserver-init:
  69. image: hstreamdb/hstream:v0.11.0
  70. depends_on:
  71. - hserver0
  72. - hserver1
  73. networks:
  74. - hstream-quickstart
  75. command:
  76. - bash
  77. - "-c"
  78. - |
  79. timeout=120
  80. until ( \
  81. /usr/local/bin/hadmin server --host hserver0 --port 6570 status && \
  82. /usr/local/bin/hadmin server --host hserver1 --port 6572 status \
  83. ) >/dev/null 2>&1; do
  84. >&2 echo 'Waiting for servers ...'
  85. sleep 1
  86. timeout=$$((timeout - 1))
  87. [ $$timeout -le 0 ] && echo 'Timeout!' && exit 1;
  88. done; \
  89. /usr/local/bin/hadmin server --host hserver0 init
  90. hstore:
  91. image: hstreamdb/hstream:v0.11.0
  92. networks:
  93. - hstream-quickstart
  94. volumes:
  95. - data_store:/data/store
  96. command:
  97. - bash
  98. - "-c"
  99. - |
  100. set -ex
  101. /usr/local/bin/ld-dev-cluster --root /data/store \
  102. --use-tcp --tcp-host $$(hostname -I | awk '{print $$1}') \
  103. --user-admin-port 6440 \
  104. --no-interactive
  105. zookeeper:
  106. image: zookeeper
  107. expose:
  108. - 2181
  109. networks:
  110. - hstream-quickstart
  111. volumes:
  112. - data_zk_data:/data
  113. - data_zk_datalog:/datalog
  114. networks:
  115. hstream-quickstart:
  116. name: hstream-quickstart
  117. volumes:
  118. data_store:
  119. name: quickstart_data_store
  120. data_zk_data:
  121. name: quickstart_data_zk_data
  122. data_zk_datalog:
  123. name: quickstart_data_zk_datalog

then run:

  1. docker-compose -f quick-start.yaml up

If you see some thing like this, then you have a running hstream:

  1. hserver_1 | [INFO][2021-11-22T09:15:18+0000][app/server.hs:137:3][thread#67]************************
  2. hserver_1 | [INFO][2021-11-22T09:15:18+0000][app/server.hs:145:3][thread#67]Server started on port 6570
  3. hserver_1 | [INFO][2021-11-22T09:15:18+0000][app/server.hs:146:3][thread#67]*************************

TIP

You can also run in background.

  1. docker-compose -f quick-start.yaml up -d

And if you want to show logs of server, run:

  1. docker-compose -f quick-start.yaml logs -f hserver

Start HStreamDB’s interactive SQL CLI

  1. docker run -it --rm --name some-hstream-cli --network host hstreamdb/hstream:v0.11.0 hstream --port 6570 sql

If everything works fine, you will enter an interactive CLI and see help information like

  1. __ _________________ _________ __ ___
  2. / / / / ___/_ __/ __ \/ ____/ | / |/ /
  3. / /_/ /\__ \ / / / /_/ / __/ / /| | / /|_/ /
  4. / __ /___/ // / / _, _/ /___/ ___ |/ / / /
  5. /_/ /_//____//_/ /_/ |_/_____/_/ |_/_/ /_/
  6. Command
  7. :h To show these help info
  8. :q To exit command line interface
  9. :help [sql_operation] To show full usage of sql statement
  10. SQL STATEMENTS:
  11. To create a simplest stream:
  12. CREATE STREAM stream_name;
  13. To create a query select all fields from a stream:
  14. SELECT * FROM stream_name EMIT CHANGES;
  15. To insert values to a stream:
  16. INSERT INTO stream_name (field1, field2) VALUES (1, 2);
  17. >

Create a stream

What we are going to do first is create a stream by CREATE STREAM statement.

  1. CREATE STREAM demo;

Run a continuous query over the stream

Now we can run a continuous query over the stream we just created by SELECT query.

The query will output all records from the demo stream whose humidity is above 70 percent.

  1. SELECT * FROM demo WHERE humidity > 70 EMIT CHANGES;

It seems that nothing happened. But do not worry because there is no data in the stream now. Next, we will fill the stream with some data so the query can produce output we want.

Start another CLI session

Start another CLI session, this CLI will be used for inserting data into the stream.

  1. docker exec -it some-hstream-cli hstream --port 6570 sql

Insert data into the stream

Run each of the given INSERT statement in the new CLI session and keep an eye on the CLI session created in (2).

  1. INSERT INTO demo (temperature, humidity) VALUES (22, 80);
  2. INSERT INTO demo (temperature, humidity) VALUES (15, 20);
  3. INSERT INTO demo (temperature, humidity) VALUES (31, 76);
  4. INSERT INTO demo (temperature, humidity) VALUES ( 5, 45);
  5. INSERT INTO demo (temperature, humidity) VALUES (27, 82);
  6. INSERT INTO demo (temperature, humidity) VALUES (28, 86);

If everything works fine, the continuous query will output matching records in real time:

  1. {"temperature":22,"humidity":80}
  2. {"temperature":31,"humidity":76}
  3. {"temperature":27,"humidity":82}
  4. {"temperature":28,"humidity":86}