当前位置:网站首页>ClickHouse学习(五)集群操作
ClickHouse学习(五)集群操作
2022-07-29 05:09:00 【阳光里哭泣的狗】
副本
zookeeper配置
内部直接修改
直接将其改成自己的就行

外部文件形式
在/etc/clickhouse-server/config.d下创建metrika.xml文件
<?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>
分发给其他机器
在/etc/clickhouse-server/config.xml中添加以下信息:
<zookeeper incl="zookeeper-servers" optional="true" />
<include_from>/etc/clickhouse-server/config.d/metrika.xml</include_from>

分发集群
到此就配置完成了
测试
副本只能同步数据但是不能同步表结构数据
/clickhouse/table/01/t_order_rep 表示在zookeeper中的路径信息 其中01表示一个分片
rep_102 表示副本名称
分别在三台机子上创建表结构
spark01上创建:
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上创建:
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上创建:
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);
向spark01中插入数据
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');
能在spark02,03上查到
分片集群
分片就是将一张表的数据分布在不同的节点上,再通过 Distributed 表引擎把数据拼接起来一同使用。
Distributed 表引擎本身不存储数据只是用来管理其他分片
搭建
创建两个分片,第一个分片有一个副本
在config.d下创建metrika-shard.xml文件
<?xml version="1.0"?>
<yandex>
<remote_servers>
<clusters> <!-- 集群名称-->
<shard> <!--集群的第一个分片-->
<internal_replication>true</internal_replication>
<replica> <!--该分片的第一个副本-->
<host>spark01</host>
<port>9000</port>
</replica>
<replica> <!--该分片的第二个副本-->
<host>spark02</host>
<port>9000</port>
</replica>
</shard>
<shard> <!--集群的第二个分片-->
<internal_replication>true</internal_replication>
<replica> <!--该分片的第一个副本-->
<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> <!--不同机器放的分片数不一样-->
<replica>rep_1_1</replica> <!--不同机器放的副本数不一样-->
</macros>
</yandex>
分发给其他集群
将spark02上的文件进行修改
将spark03上的文件进行修改
在config.xml文件下将文件名进行修改
分发集群
每次配置完config.xml必须重启一次服务
测试
先创建分片表
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);

再创建 Distribute 分布式表
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 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');
第一个分片表
第一个分片表的副本
第二个分片表
边栏推荐
猜你喜欢

Complete ecological map of R & D Efficiency & selection of Devops tools

如视技术副总裁杨永林:当传统产业遇到“数字空间”

QML control: combobox

Come on! See how Clickhouse, which has risen 16 places a year, can be implemented in jd.com

全局components组件注册

实现简单的数据库查询(不完整)

Li Yan, CEO of parallel cloud: cloudxr, opens the channel to the metauniverse

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

JD cloud golden autumn cloud special offer is in progress! Code scanning participation activities

【C语言系列】—三种方法模拟实现strlen库函数的方法
随机推荐
Xiaolu Inn - Trailer
阿里云架构师细说游戏行业九大趋势
全局components组件注册
Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy
小程序中的DOM对象元素块动态排序
Common shortcut keys for Ad
Occt learning 001 - Introduction
阿里云张新涛:异构计算为数字经济提供澎湃动力
使用微信小程序扫码登录系统PC端web的功能
【C语言系列】—文件操作详解(上)
365 day challenge leetcode1000 question - distance between bus stops on day 038 + time-based key value storage + array closest to the target value after transforming the array and + maximum value at t
C语言 N皇后问题
利用Poi-tl在word模板表格单元格内一次插入多张图片和多行单元格相同数据自动合并的功能组件
【C语言系列】— 不创造第三个变量,实现两个数的交换
Yangyonglin, vice president of Rushi Technology: when traditional industries encounter "digital space"
365 day challenge leetcode 1000 questions - day 042 array sequence number conversion + relative ranking discretization processing
GPIO的输入输出详解
牛客网编程题—【WY22 Fibonacci数列】和【替换空格】详解
EXIT中断详解
省市区三级联动(简单又完美)