clickhouse集群模式配置
1、分布式集群常见方案方案特点方案一:MergeTree + Distributed1、无副本。2、无需zk。3、只能写本地表方案二:MergeTree + Distributed+集群复制1、写集群表。2、利用集群复制机制解决副本问题。3、无需使用zk方案三:ReplicatedMergeTree + Distributed1、写本地表,通过zk做副本分发。2、写本地表,读集群表。3、高度依赖z
·
1、分布式集群常见方案
方案 | 特点 |
---|---|
方案一:MergeTree + Distributed | 1、无副本。2、无需zk。3、只能写本地表 |
方案二:MergeTree + Distributed+集群复制 | 1、写集群表。2、利用集群复制机制解决副本问题。3、无需使用zk |
方案三:ReplicatedMergeTree + Distributed | 1、写本地表,通过zk做副本分发。2、写本地表,读集群表。3、高度依赖zk |
我这里因为数据是从hive表导入的,所以无需副本,所以选择方案一
2、独立配置文件
clickhouse可以通过substitutions来将部分配置项单独写在一个文件中。这样的好处是方便管理,不需要每次都维护config.xml
3、配置文件
1)users.xml
因为是写本地表,所以可以配置新增一个分布式表专用的只读账号,用于分布式表读取,在<users>标签中添加一下配置,注意password_sha256_hex 需要自己创建密码 。方法为:echo -n '123456' | sha256sum | tr -d '-'
<clst_read>
<password_sha256_hex>8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92</password_sha256_hex>
<networks>
<ip>::/0</ip>
</networks>
<!-- Settings profile for user. -->
<profile>readonly</profile>
<!-- Quota for user. -->
<quota>default</quota>
</clst_read>
2)config.xml
添加include_from标签,和incl属性
1、在<yandex>标签下添加一下配置,表示引入一个额外的配置文件/etc/clickhouse-server/metrika.xml
<include_from>/etc/clickhouse-server/metrika.xml</include_from> <!-- 设置集群配置文件 -->
2、修改<remote_servers>标签,添加incl属性,表示用ck_remote_servers标签 替换 remote_servers标签(在metrika.xml中配置)
<remote_servers incl="ck_remote_servers"> <!-- 指定incl -->
3)metrika.xml
创建分布式表配置文件,以下是一个完整的配置文件
<yandex>
<ck_remote_servers> <!--标签名,用于替换 config.xml中的remote_servers标签-->
<dw_cluster> <!--集群名称 -->
<shard>
<replica>
<host>ip</host>
<port>9100</port>
<user>clst_read</user> <!-- 专门配置的一个集群只读账号 -->
<password>123456</password>
</replica>
</shard>
<shard>
<replica>
<host>ip</host>
<port>9100</port>
<user>clst_read</user>
<password>123456</password>
</replica>
</shard>
</dw_cluster>
</ck_remote_servers>
</yandex>
4)创建分布式表
重启服务后,创建分布式表:
-- 创建本地表,多个节点都需要创建
create table dw_local.hits(p Date, i Int32) ENGINE =MergeTree order by p;
-- 插入本地表数据,节点1
insert into dw_local.hits(p,i) values('2021-01-01',1),('2021-01-01',2),('2021-01-02',3),('2021-01-02',4);
-- 插入本地表数据,节点2
insert into dw_local.hits(p,i) values('2021-01-01',5),('2021-01-01',6),('2021-01-02',7),('2021-01-02',8);
-- 创建分布式表:
-- dw.hits :分布式表名
-- dw_cluster:集群名称
-- dw_local:本地表的库名
-- hits:本地表名
CREATE TABLE IF NOT EXISTS dw.hits (p Date, i Int32) ENGINE = Distributed(dw_cluster, dw_local, hits);
-- 查询分布式表
select * from dw.hits t limit 10;
-- 查询本地表
select * from dw_local.hits t limit 10;
更多推荐
已为社区贡献1条内容
所有评论(0)