ClickHouse集群版部署

==作者:YB-Chi==

[toc]

部署结构

3节点3实例3分片2副本

配置文件

/etc/clickhouse-server/metrika.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0"?>
<clickhouse>
<clickhouse_remote_servers>
<cyb_cluster>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node1</host>
<port>9000</port>
</replica>
<replica>
<host>node2</host>
<port>9002</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node2</host>
<port>9000</port>
</replica>
<replica>
<host>node3</host>
<port>9002</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node3</host>
<port>9000</port>
</replica>
<replica>
<host>node1</host>
<port>9002</port>
</replica>
</shard>
</cyb_cluster>
</clickhouse_remote_servers>
<macros>
<layer>ckcluster_3shard_2replica</layer>
<!--根据前面shard的配置,例子中总共3个shard-->
<shard>shard01</shard>
<!--每个节点配置本地主机名即可,或者唯一的数字id-->
<replica>node1</replica>
</macros>
<networks>
<ip>::/0</ip>
</networks>
<!-- 数据压缩算法 -->
<clickhouse_compression>
<case>
<min_part_size>10000000000</min_part_size>
<min_part_size_ratio>0.01</min_part_size_ratio>
<method>lz4</method>
</case>
</clickhouse_compression>
</clickhouse>

其他节点差异化的参数就俩 <shard>shard01</shard> <replica>node1</replica>

config.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<remote_servers incl="clickhouse_remote_servers" />
<include_from>/etc/clickhouse-server/metrika.xml</include_from>
<macros incl="macros" optional="true"/>
<zookeeper>
<node>
<host>node1</host>
<port>2181</port>
</node>
<node>
<host>node2</host>
<port>2181</port>
</node>
<node>
<host>node3</host>
<port>2181</port>
</node>
</zookeeper>

后续

1
2
3
4
5
6
chown clickhouse:clickhouse /etc/clickhouse-server/metrika.xml
#3节点需要每个节点起俩实例,需要修改端口,这里不做演示了,可以参考`12实例15node多实例集群部署方案`
#启动
systemctl start clickhouse-server
#开机自启
systemctl enable clickhouse-server
文章作者: CYBSKY
文章链接: https://cybsky.top/2022/10/28/cyb-mds/database/ClickHouse/ClickHouse集群3S2R方案/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 CYBSKY