Giter Club home page Giter Club logo

clickhouse-cluster's Introduction

Clickhouse Cluster

Clickhouse cluster with 2 shards and 2 replicas built with docker-compose.

Not for production use.

Run

Run single command, and it will copy configs for each node and run clickhouse cluster company_cluster with docker-compose

make config up

Containers will be available in docker network 172.23.0.0/24

Container Address
zookeeper 172.23.0.10
clickhouse01 172.23.0.11
clickhouse02 172.23.0.12
clickhouse03 172.23.0.13
clickhouse04 172.23.0.14

Profiles

  • default - no password
  • admin - password 123

Test it

Login to clickhouse01 console (first node's ports are mapped to localhost)

clickhouse-client -h localhost

Or open clickhouse-client inside any container

docker exec -it clickhouse01 clickhouse-client -h localhost

Create a test database and table (sharded and replicated)

CREATE DATABASE company_db ON CLUSTER 'company_cluster';

CREATE TABLE company_db.events ON CLUSTER 'company_cluster' (
    time DateTime,
    uid  Int64,
    type LowCardinality(String)
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{cluster}/{shard}/events', '{replica}')
PARTITION BY toDate(time)
ORDER BY (uid);

CREATE TABLE company_db.events_distr ON CLUSTER 'company_cluster' AS company_db.events
ENGINE = Distributed('company_cluster', company_db, events, uid);

Load some data

INSERT INTO company_db.events_distr VALUES
    ('2020-01-01 10:00:00', 100, 'view'),
    ('2020-01-01 10:05:00', 101, 'view'),
    ('2020-01-01 11:00:00', 100, 'contact'),
    ('2020-01-01 12:10:00', 101, 'view'),
    ('2020-01-02 08:10:00', 100, 'view'),
    ('2020-01-03 13:00:00', 103, 'view');

Check data from the current shard

SELECT * FROM company_db.events;

Check data from all cluster

SELECT * FROM company_db.events_distr;

Add more nodes

If you need more Clickhouse nodes, add them like this:

  1. Add replicas/shards to config.xml to the block company/remote_servers/company_cluster.
  2. Add nodes to docker-compose.yml.
  3. Add nodes in Makefile in config target.

Start, stop

Start/stop the cluster without removing containers

make start
make stop

Teardown

Stop and remove containers

make down

clickhouse-cluster's People

Contributors

douqq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

clickhouse-cluster's Issues

change replicas count

is it enough to change config.xml by just adding

<replica>
                    <host>clickhouse05</host>
                    <port>9000</port>
</replica>

and so on for every shard for adding new replica?

Multiple zookeepers?

I realize this is a simple example, but for HA, wouldn't you want multiple zookeeper instances? What would that look like here? Thanks!

Zookeeper stuck at 'Starting'

Specs:

  1. MacBook Pro - 2.6 GHz 6-Core Intel Core i7
  2. Docker DeskTop

After running make config and make up, my zookeeper is stuck at Starting status. I have run docker system prune -f to ensure all there are no resource constraints.
Screenshot 2023-07-31 at 12 38 57 AM

Connection refused (localhost:9000)

Hi there!

I'm not able to connect with the clickhouse-client - I've tried connecting with localhost, 127.0.0.1, and both the users - admin and default.

What's weird is I am able to connect via the http endpoint via port 8123 - so the cluster is definitely up and working.

Any suggestions?

Permission denied on config.xml when starting up clickhouse-server

I tried to start the clickhouse cluster following the steps on README.
When I run make config up, everything seems to be fine. However, when I try docker ps, only zookeeper container is running, all the clickhouse-server containers are gone.

Then I run docker compose up to find out what's going on and I notice there's permission denied error message that leads to all the clickhouse-server fail to start:

std::exception. Code: 1001, type: std::__1::__fs::filesystem::filesystem_error, e.what() = filesystem error: in posix_stat: failed to determine attributes for the specified path: Permission denied ["/etc/clickhouse-server/config.xml"], Stack trace (when copying this message, always include the lines below):

I checked the permission of the config files under clickhouse0*, here is the output:

drwxr-x--- 2 liuhaolin liuhaolin   41 Apr 23 17:10 .
drwxr-x--- 7 liuhaolin liuhaolin  210 Apr 23 17:10 ..
-rw-r----- 1 liuhaolin liuhaolin 2.3K Apr 23 17:10 config.xml
-rw-r----- 1 liuhaolin liuhaolin 1.2K Apr 23 17:10 users.xml

I add rx permission for group and other user, rerun docker compose up, then everything works fine.

Maybe it's better to add permission when copying config files in the Makefile to avoid this case.

Bro , U R Great

it worked for me after a long time of searching
u saved my life

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.