|NO.Z.00026|——————————|BigDataEnd|——|Hadoop&OLAP_ClickHouse.V07|——|ClickHouse.v07|ClickHouse:ClickHouse副本分片|分片|
一、分片
### --- 修改配置参数文件:
~~~ # 修改配置文件参数
[root@hadoop01 ~]# vim /etc/clickhouse-server/config.d/metrika.xml
~~~ 下列为分片机制配置参数
<yandex>
<!-- 修改remote-servers集群配置节点信息 -->
<clickhouse_remote_servers>
<perftest_3shards_1replicas>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>hadoop01</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<internal_replication>true</internal_replication>
<host>hadoop02</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>hadoop03</host>
<port>9000</port>
</replica>
</shard>
</perftest_3shards_1replicas>
</clickhouse_remote_servers>
<!--zookeeper集群配置信息 -->
<zookeeper-servers>
<node index="1">
<host>hadoop01</host>
<port>2181</port>
</node>
<node index="2">
<host>hadoop02</host>
<port>2181</port>
</node>
<node index="3">
<host>hadoop03</host>
<port>2181</port>
</node>
</zookeeper-servers>
<!--副本存放地址:不同主机配置不同主机名 -->
<macros>
<shard>01</shard>
<replica>hadoop01</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>
</yandex>
### --- 注意修改其它两台主机副本存放
~~~ # 修改其它两台主机的副本存放地址
[root@hadoop02 ~]# vim /etc/clickhouse-server/config.d/metrika.xml
<!--副本存放地址:不同主机配置不同主机名 -->
<macros>
<shard>02</shard>
<replica>hadoop02</replica>
[root@hadoop03 ~]# vim /etc/clickhouse-server/config.d/metrika.xml
</macros>
<!--副本存放地址:不同主机配置不同主机名 -->
<macros>
<shard>03</shard>
<replica>hadoop03</replica>
</macros>
### --- 修改config.xml
[root@hadoop01 ~]# vim /etc/clickhouse-server/config.xml
<include_from>/etc/clickhouse-server/config.d/metrika.xml</include_from>
<zookeeper incl="zookeeper-servers" optional="true" />
二、分片机制参数说明
### --- 查看表中分片机制的参数
hadoop01 :) select * from system.macros;
┌─macro───┬─substitution─┐
│ replica │ hadoop01 │
│ shard │ 01 │
└─────────┴──────────────┘
hadoop02 :) select * from system.macros;
┌─macro───┬─substitution─┐
│ replica │ hadoop02 │
│ shard │ 02 │
└─────────┴──────────────┘
hadoop03 :) select * from system.macros;
┌─macro───┬─substitution─┐
│ replica │ hadoop03 │
│ shard │ 03 │
└─────────┴──────────────┘
#---OR
hadoop01 :) select * from remote ('hahoop01:9000','system','macros','default');
三、在集群上创建表
### --- 创建表
hadoop01 :) create table clutable
on cluster perftest_3shards_1replicas(id UInt64)
engine = ReplicatedMergeTree('/clickhouse/tables/{shard}/clutable','{replica}')
order by id;
~~~输出参数
┌─host─────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ hadoop02 │ 9000 │ 0 │ │ 2 │ 1 │
└──────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
┌─host─────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ hadoop01 │ 9000 │ 0 │ │ 1 │ 0 │
└──────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
┌─host─────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ hadoop03 │ 9000 │ 0 │ │ 0 │ 0 │
└──────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
### --- 查看创建的表
~~~ # 查看分布式表
hadoop01 :) show tables;
┌─name─────┐
│ clutable │
└──────────┘
hadoop02 :) show tables;
┌─name─────┐
│ clutable │
└──────────┘
hadoop03 :) show tables;
┌─name─────┐
│ clutable │
└──────────┘
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通