ClickHouse部署系列2: 使用docker部署ClickHouse集群

该文详细介绍了如何使用Docker在四台机器上部署一个ClickHouse集群,包括配置文件的修改、分片和副本的设定,以及启动和验证集群的步骤。集群采用2个分片,每个分片2个副本的配置,并提到了Zookeeper的使用来协调集群。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

准备工作

部署方案

Load Blancer + ReplicatedMergeTree + Distributed + zookeeper

2 shards 2 replicas

机器信息

主机名 IP 分片 副本
clickhouse1 192.168.0.13 shard1 replica1
clickhouse2 192.168.0.14 shard1 replica2
clickhouse3 192.168.0.15 shard2 replica1
clickhouse4 192.168.0.100 shard2 replica2

规划4个节点, 2个分片, 每个分片2个副本。 分片1的副本在主机clickhouse1和clickhouse2上, 2分片的副本在主机clickhouse3和clickhouse4上。

官方建议zookeeper集群与clickhouse集群分开部署,避免资源竞争导致服务异常。

这里我们将zookeeper汲取 部署到k8s上,部署教程为:

clickhouse集群我们采用docker部署

部署clickhouse集群

获取配置文件

  1. 按照官方教程,启动clickhouse-server
    docker run -d --name clickhouse-server --ulimit nofile=262144:262144 --volume=/data/clickhouse/:/var/lib/clickhouse yandex/clickhouse-server
    
  2. 容器启动之后,复制容器内的配置文件到本地
    mkdir -p /etc/clickhouse-server
    docker cp clickhouse-server:/etc/clickhouse-server/ /etc/
    

修改/etc/clickhouse-server/config.xml

  1. 找到下述配置,打开注释并进行修改

    <listen_host>::1</listen_host>
    <listen_host>0.0.0.0</listen_host>
    <listen_host>127.0.0.1</listen_host>
    
  2. 找到metrika.xml位置,修改include from节点为实际引用到的文件

     <!-- If element has 'incl' attribute, then for it's value will be used corresponding substitution from another file.
             By default, path to file with substitutions is /etc/metrika.xml. It could be changed in config in 'include_from' element.
             Values for substitutions are specified in /yandex/name_of_substitution elements in that file.
          -->
     <include_from>/etc/clickhouse-server/metrika.xml</include_from>
    
  3. 增加分片与副本信息

        <!-- Configuration of clusters that could be used in Distributed tables.
             https://clickhouse.com/docs/en/operations/table_engines/distributed/
          -->
        <remote_servers>
            <!-- Test only shard config for testing distributed storage -->
            <cluster_2s_2r>
                <!-- 数据分片1  -->
                <shard>
                    <internal_replication>true</internal_replication>
                    <replica>
                        <host>192.168.0.13</host>
                        <port>9000</port>
                        <user>default</user>
                        <password></password>
                    </replica>
                    <replica>
                        <host>192.168.0.14</host>
                        <port>9000</port>
                        <user>default</user>
                        <password></password>
                    </replica>
                </shard>
    
                <!-- 数据分片2  -->
                <shard>
                    <internal_replication>true</internal_replication>
                    <replica
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

godleft90

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值