From fc27206708986938a776d1fd98e72c72b130dd0a Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 11 Dec 2023 22:31:52 +0100 Subject: [PATCH] feat: with real time streaming Signed-off-by: kjuulh --- .../clickhouse/docker/00_create_nats_table.sh | 23 +++++++ config/clickhouse/server/config.d/config.xml | 48 +++++++++++++++ config/clickhouse/server/users.d/users.xml | 37 +++++++++++ docker-compose.yml | 61 +++++++++++++++++++ 4 files changed, 169 insertions(+) create mode 100755 config/clickhouse/docker/00_create_nats_table.sh create mode 100644 config/clickhouse/server/config.d/config.xml create mode 100644 config/clickhouse/server/users.d/users.xml create mode 100644 docker-compose.yml diff --git a/config/clickhouse/docker/00_create_nats_table.sh b/config/clickhouse/docker/00_create_nats_table.sh new file mode 100755 index 0000000..86193e5 --- /dev/null +++ b/config/clickhouse/docker/00_create_nats_table.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +clickhouse client -n <<-EOSQL +CREATE TABLE nats ( + key String, +) ENGINE = NATS + SETTINGS nats_url = 'nats:4222', + nats_username = 'natsadmin', + nats_password = 'natsadmin', + nats_subjects = 'cli.demo', + nats_format = 'JSONEachRow', + date_time_input_format = 'best_effort'; + +CREATE TABLE daily (key String) + ENGINE = MergeTree() ORDER BY key; + +CREATE MATERIALIZED VIEW consumer TO daily + AS SELECT key FROM nats; + +SELECT key FROM daily ORDER BY key; +EOSQL diff --git a/config/clickhouse/server/config.d/config.xml b/config/clickhouse/server/config.d/config.xml new file mode 100644 index 0000000..d87aa3a --- /dev/null +++ b/config/clickhouse/server/config.d/config.xml @@ -0,0 +1,48 @@ + + + debug + /var/log/clickhouse-server/clickhouse-server.log + /var/log/clickhouse-server/clickhouse-server.err.log + 1000M + 3 + + ch_minio_s3 + 0.0.0.0 + 8123 + 9000 + + + users.xml + + + /var/lib/clickhouse/access/ + + + + + + s3 + http://minio:10000/clickhouse// + minioadmin + minioadminpassword + + /var/lib/clickhouse/disks/s3/ + + + cache + s3 + /var/lib/clickhouse/disks/s3_cache/ + 10Gi + + + + + + + s3 + + + + + + diff --git a/config/clickhouse/server/users.d/users.xml b/config/clickhouse/server/users.d/users.xml new file mode 100644 index 0000000..0f32c64 --- /dev/null +++ b/config/clickhouse/server/users.d/users.xml @@ -0,0 +1,37 @@ + + + + + 10000000000 + 0 + in_order + 1 + + + + + 1 + default + + ::/0 + + default + 1 + 1 + 1 + 1 + + + + + + 3600 + 0 + 0 + 0 + 0 + 0 + + + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a4d785a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,61 @@ +version: '3.8' +services: + clickhouse: + image: clickhouse/clickhouse-server + user: '101:101' + container_name: clickhouse + hostname: clickhouse + volumes: + - ${PWD}/config/clickhouse/server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml + - ${PWD}/config/clickhouse/server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml + - ${PWD}/config/clickhouse/docker/:/docker-entrypoint-initdb.d + ports: + - '127.0.0.1:8123:8123' + - '127.0.0.1:9000:9000' + depends_on: + - minio + - createbuckets + - nats + minio: + image: quay.io/minio/minio + container_name: minio + hostname: minio + command: server --address 0.0.0.0:10000 --console-address 0.0.0.0:10001 /data + ports: + - '127.0.0.1:10000:10000' + - '127.0.0.1:10001:10001' + environment: + - MINIO_ROOT_USER=minioadmin + - MINIO_ROOT_PASSWORD=minioadminpassword + + createbuckets: + image: minio/mc + depends_on: + - minio + entrypoint: > + /bin/sh -c " + /usr/bin/mc alias set myminio http://minio:10000 minioadmin minioadminpassword; + /usr/bin/mc admin info myminio; + /usr/bin/mc mb myminio/clickhouse; + /usr/bin/mc policy set public myminio/clickhouse; + exit 0; + " + nats: + container_name: nats + hostname: nats + image: 'bitnami/nats:latest' + ports: + - 127.0.0.1:4222:4222 + - 127.0.0.1:6222:6222 + - 127.0.0.1:8222:8222 + environment: + - NATS_ENABLE_AUTH=yes + - NATS_USERNAME=natsadmin + - NATS_PASSWORD=natsadmin + #- NATS_TOKEN=natsadmin + # healthcheck: + # test: ["CMD", "curl", "-f", "http://localhost:4222"] + # interval: 1m30s + # timeout: 10s + # retries: 3 + # start_period: 2m