当前位置:网站首页>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 
边栏推荐
- 携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”
- Pyqt5: Chapter 1, Section 1: creating a user interface using QT components - Introduction
- 365天挑战LeetCode1000题——Day 035 每日一题 + 二分查找 13
- 【活动预告】云上数字工厂与中小企业数字化转型创新论坛
- ClickHouse学习(七)表查询优化
- Cryengine Technology
- NVIDIA Zhou Xijian: the last mile from design to digital marketing
- Allocate memory: malloc() and free()
- 副作用和序列点
- 365 day challenge leetcode 1000 questions - day 037 elements and the maximum side length of squares less than or equal to the threshold + the number of subsequences that meet the conditions
猜你喜欢

ClickHouse学习(四)SQL操作

365 day challenge leetcode 1000 questions - day 039 full binary tree inserter + find peak II + snapshot array

365 day challenge leetcode 1000 questions - day 040 design jump table + avoid flooding + find the latest grouping with size M + color ball with reduced sales value

Day 5

刷题狂魔—LeetCode之剑指offer58 - II. 左旋转字符串 详解

Detailed explanation of GPIO input and output

Together with digital people, digital space and XR platform, Alibaba cloud and its partners jointly build a "new vision"

365天挑战LeetCode1000题——Day 035 每日一题 + 二分查找 13

阿里云张新涛:异构计算为数字经济提供澎湃动力

Li Kou 994: rotten orange (BFS)
随机推荐
365 day challenge leetcode 1000 questions - day 040 design jump table + avoid flooding + find the latest grouping with size M + color ball with reduced sales value
PyQt5:第一章第1节:使用Qt组件创建一个用户界面-介绍
Occt learning 003 - MFC single document project
365 day challenge leetcode 1000 questions - day 039 full binary tree inserter + find peak II + snapshot array
Bubble sort c language
ClickHouse学习(八)物化视图
C语言数组典型应用代码详细讲解—高手误入(逐步代码详解)
【C语言系列】—文件操作详解(上)
Live broadcast Preview: integration of JD cloud Devops and jfrog product library
The road to success in R & D efficiency of 1000 person Internet companies
510000 prize pool invites you to fight! The second Alibaba cloud ECS cloudbuild developer competition is coming
Allocate memory: malloc() and free()
实现简单的数据库查询(不完整)
Terminal shell common commands
More than 200 ISVs have settled in! The first anniversary of Alibaba cloud computing nest
整数溢出和打印
全局components组件注册
Pointer
刷题狂魔—LeetCode之剑指offer58 - II. 左旋转字符串 详解
Side effects and sequence points