当前位置:网站首页>Clickhouse learning (V) cluster operation
Clickhouse learning (V) cluster operation
2022-07-29 05:33:00 【Crying dogs in the sun】
copy
zookeeper To configure
Internal direct modification
Just change it to your own

External file form
stay /etc/clickhouse-server/config.d Create metrika.xml file
<?xml version="1.0"?>
<yandex>
<zookeeper-servers>
<node index="1">
<host>spark01</host>
<port>2181</port>
</node>
<node index="2">
<host>spark02</host>
<port>2181</port>
</node>
<node index="3">
<host>spark03</host>
<port>2181</port>
</node>
</zookeeper-servers>
</yandex>
To other machines 
stay /etc/clickhouse-server/config.xml Add the following information to :
<zookeeper incl="zookeeper-servers" optional="true" />
<include_from>/etc/clickhouse-server/config.d/metrika.xml</include_from>

Distributed cluster 
This completes the configuration
test
Replicas can only synchronize data, but cannot synchronize table structure data
/clickhouse/table/01/t_order_rep It means that zookeeper Path information in among 01 Represents a fragment
rep_102 Indicates the name of the copy
Create table structures on three machines respectively
spark01 To create a :
create table t_order_rep2 (
id UInt32,
sku_id String,
total_amount Decimal(16,2),
create_time Datetime
) engine =ReplicatedMergeTree('/clickhouse/table/01/t_order_rep','rep_101')
partition by toYYYYMMDD(create_time)
primary key (id)
order by (id,sku_id);
spark02 To create a :
create table t_order_rep2 (
id UInt32,
sku_id String,
total_amount Decimal(16,2),
create_time Datetime
) engine =ReplicatedMergeTree('/clickhouse/table/01/t_order_rep','rep_102')
partition by toYYYYMMDD(create_time)
primary key (id)
order by (id,sku_id);
spark03 To create a :
create table t_order_rep2 (
id UInt32,
sku_id String,
total_amount Decimal(16,2),
create_time Datetime
) engine =ReplicatedMergeTree('/clickhouse/table/01/t_order_rep','rep_103')
partition by toYYYYMMDD(create_time)
primary key (id)
order by (id,sku_id);
towards spark01 Insert data
insert into t_order_rep2 values
(101,'sku_001',1000.00,'2020-06-01 12:00:00'),
(102,'sku_002',2000.00,'2020-06-01 12:00:00'),
(103,'sku_004',2500.00,'2020-06-01 12:00:00'),
(104,'sku_002',2000.00,'2020-06-01 12:00:00'),
(105,'sku_003',600.00,'2020-06-02 12:00:00');
Can be in spark02,03 It's on the Internet 
Fragmentation cluster
Sharding is to distribute the data of a table on different nodes , Re pass Distributed The table engine splices data together for use .
Distributed The table engine itself does not store data, but is only used to manage other partitions
build
Create two tiles , The first fragment has a copy
stay config.d Create metrika-shard.xml file
<?xml version="1.0"?>
<yandex>
<remote_servers>
<clusters> <!-- Cluster name -->
<shard> <!-- The first slice of the cluster -->
<internal_replication>true</internal_replication>
<replica> <!-- The first copy of the slice -->
<host>spark01</host>
<port>9000</port>
</replica>
<replica> <!-- The second copy of the slice -->
<host>spark02</host>
<port>9000</port>
</replica>
</shard>
<shard> <!-- The second slice of the cluster -->
<internal_replication>true</internal_replication>
<replica> <!-- The first copy of the slice -->
<host>spark03</host>
<port>9000</port>
</replica>
</shard>
</clusters>
</remote_servers>
<zookeeper-servers>
<node index="1">
<host>spark01</host>
<port>2181</port>
</node>
<node index="2">
<host>spark02</host>
<port>2181</port>
</node>
<node index="3">
<host>spark03</host>
<port>2181</port>
</node>
</zookeeper-servers>
<macros>
<shard>01</shard> <!-- Different machines put different pieces -->
<replica>rep_1_1</replica> <!-- The number of copies placed on different machines is different -->
</macros>
</yandex>
Distribute to other clusters 
take spark02 Modify the file on 
take spark03 Modify the file on 
stay config.xml Change the file name under the file 
Distributed cluster 
After each configuration config.xml The service must be restarted
test
First create a shard table
create table st_order_mt on cluster clusters (
id UInt32,
sku_id String,
total_amount Decimal(16,2),
create_time Datetime
) engine =ReplicatedMergeTree('/clickhouse/tables/{shard}/st_order_mt','{replica}')
partition by toYYYYMMDD(create_time)
primary key (id)
order by (id,sku_id);

To create a Distribute Distributed table
create table test2 on cluster clusters
(
id UInt32,
sku_id String,
total_amount Decimal(16,2),
create_time Datetime
)engine = Distributed(clusters,default, st_order_mt,hiveHash(sku_id));

Insert data into a distributed table
insert into test2 values
(201,'sku_001',1000.00,'2020-06-03 12:00:00') ;
(202,'sku_002',2000.00,'2020-06-01 12:00:00'),
(203,'sku_004',2500.00,'2020-06-01 12:00:00'),
(204,'sku_002',2000.00,'2020-06-01 12:00:00'),
(205,'sku_003',600.00,'2020-06-02 12:00:00');
The first partition table 
A copy of the first shard table 
The second partition table 
边栏推荐
- ClickHouse学习(十)监控运行指标
- js深拷贝-笔记
- C语言数组入门到精通(数组精讲)
- Complete ecological map of R & D Efficiency & selection of Devops tools
- 365天挑战LeetCode1000题——Day 035 每日一题 + 二分查找 13
- Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system
- C语言数组典型应用代码详细讲解—高手误入(逐步代码详解)
- 刷题狂魔—LeetCode之剑指offer58 - II. 左旋转字符串 详解
- 【C语言系列】— 不创造第三个变量,实现两个数的交换
- The function of using wechat applet to scan code to log in to the PC web of the system
猜你喜欢

三次握手四次挥手针对面试总结

During the appointment, the 2022 JD cloud industrial integration new product launch was launched online

阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署

重定向和文件

Thousands of databases, physical machines all over the country, JD logistics full volume cloud live record | interview with excellent technical team

MySQL的基础概念+数据库系统结构+拓展延申+基础命令学习

Day 1

One dimensional array exercise

浅谈范式

【活动预告】云上数字工厂与中小企业数字化转型创新论坛
随机推荐
科班同学真的了解未来的职业规划吗?
Application of Huffman tree and Huffman coding in file compression
【C语言系列】— 字符串+部分转义字符详解+注释小技巧
QML custom tabbar
Alibaba cloud architect Liang Xu: MES on cloud box helps customers quickly build digital factories
Live broadcast preview | how to improve enterprise immunity through "intelligent edge security"?
利用Poi-tl在word模板表格单元格内一次插入多张图片和多行单元格相同数据自动合并的功能组件
ClickHouse学习(九)clickhouse整合mysql
抽象类与接口
[event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises
B - identify floating point constant problems
C语言数组典型应用代码详细讲解—高手误入(逐步代码详解)
One dimensional array exercise
数据库操作 Day 6
Live broadcast preview | how to save 30% labor cost and shorten 80% trademark processing cycle?
ClickHouse学习(四)SQL操作
EXIT中断详解
ClickHouse学习(六)语法优化
Solution: find the position of the first and last element in a sorted array (personal notes)
Introduction to array learning simple question sum of two numbers