clickhouse集群搭建详细步骤

news/2024/11/24 11:29:34/

搭建说明

Clickhouse集群依赖Zookeeper集群。因此需要先搭建zk集群。
请先参考 【记录】zookeeper集群搭建详细步骤 完成zookeeper集群搭建。

如果zookeeper集群已成功搭建完成,下面开始搭建Clickhouse集群。

需要环境:

实例1实例2实例3
IP192.168.11.11192.168.11.12192.168.11.13
OScentos7.9centos7.9centos7.9
zkzookeeper-3.8.0zookeeper-3.8.0zookeeper-3.8.0
clickhouse22.2.2.1-222.2.2.1-222.2.2.1-2
javaJDK8JDK8JDK8

1.rpm安装

# 下载
cd /usr/local/clickhouse
wget https://mirrors.tuna.tsinghua.edu.cn/clickhouse/rpm/stable/x86_64/clickhouse-client-22.2.2.1-2.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/clickhouse/rpm/stable/x86_64/clickhouse-common-static-22.2.2.1-2.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/clickhouse/rpm/stable/x86_64/clickhouse-server-22.2.2.1-2.noarch.rpm
# 安装命令
rpm -ivh clickhouse-common-static-22.2.2.1-2.x86_64.rpm clickhouse-client-22.2.2.1-2.noarch.rpm clickhouse-server-22.2.2.1-2.noarch.rpm

在三台实例上重复上述操作

2.配置修改

cd /etc/clickhouse-server

config.xml

vim config.xml
<listen_host>0.0.0.0</listen_host><remote_servers><enic_cluster><shard><replica><host>192.168.11.11</host><port>9000</port></replica></shard><shard><replica><host>192.168.11.12</host><port>9000</port></replica></shard><shard><replica><host>192.168.11.13</host><port>9000</port></replica></shard></enic_cluster>
</remote_servers>

users.xml

vim users.xml
<enic><password>12345678</password><networks incl="networks" replace="replace"><ip>::/0</ip></networks><profile>default</profile><quota>default</quota>
</enic>

metrika.xml

cd /etc/clickhouse-server
vim metrika.xml
<yandex><zookeeper-servers><node index="1"><host>192.168.11.11</host><port>2181</port></node><node index="2"><host>192.168.11.12</host><port>2181</port></node><node index="3"><host>192.168.11.13</host><port>2181</port></node></zookeeper-servers>
</yandex>

重启clickhouse-server

systemctl restart clickhouse-server

查看clickhouse-server状态

systemctl status clickhouse-server
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)Loaded: loaded (/etc/systemd/system/clickhouse-server.service; enabled; vendor preset: disabled)Active: active (running) since Fri 2022-04-29 11:38:43 CST; 2h 49min agoMain PID: 30158 (clckhouse-watch)Tasks: 203 (limit: 22997)Memory: 437.8MCGroup: /system.slice/clickhouse-server.service├─30158 clickhouse-watchdog --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid└─30159 /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-serve>

在三台实例上重复上述操作

其它操作

启动clickhouse-server

systemctl start clickhouse-server

关闭clickhouse-server

systemctl stop clickhouse-server

查看clickhouse-server状态

systemctl status clickhouse-server

3.查看集群状态

clickhouse-client --host="127.0.0.1" --port="9000" --user="enic" --password="12345678"
select * from system.clusters where cluster = 'enic_cluster';
SELECT *
FROM system.clusters
WHERE cluster = 'enic_cluster'Query id: eb2064de-92f3-41b0-ac74-6b025d5082a1┌─cluster──────┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name─────┬─host_address──┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─slowdowns_count─┬─estimated_recovery_time─┐
│ enic_cluster │         111192.168.11.11192.168.11.1190000default │                  │            000 │
│ enic_cluster │         211192.168.11.12192.168.11.1290001default │                  │            000 │
│ enic_cluster │         311192.168.11.13192.168.11.1390000default │                  │            000 │
└──────────────┴───────────┴──────────────┴─────────────┴───────────────┴───────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────┴─────────────────────────┘3 rows in set. Elapsed: 0.002 sec. 

4.集群操作

创建本地表

CREATE TABLE enic_test_local ON CLUSTER enic_cluster (
id Int16,
name String,
birth Date
)ENGINE = MergeTree()
PARTITION BY toYYYYMM(birth)
ORDER BY id;
insert into enic_test_local values(1, 'test1', '2022-02-01'), (2, 'test2', '2022-03-01'), (3, 'test3', '2022-04-01');
select * from enic_test_local;

创建分布式表

CREATE TABLE default.enic_test ON CLUSTER enic_cluster as enic_test_local engine = Distributed(enic_cluster, default, enic_test_local,rand());
CREATE TABLE default.enic_test ON CLUSTER enic_cluster AS enic_test_local
ENGINE = Distributed(enic_cluster, default, enic_test_local, rand())Query id: 22bc54a5-a615-4756-9132-a76b65bc5664┌─host──────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ 192.168.11.1390000 │       │                   20 │
│ 192.168.11.1290000 │       │                   10 │
│ 192.168.11.1190000 │       │                   00 │
└───────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘3 rows in set. Elapsed: 0.128 sec. 
insert into enic_test values(1, 'test1', '2022-02-01'), (2, 'test2', '2022-03-01'), (3, 'test3', '2022-04-01');
INSERT INTO enic_test FORMAT ValuesQuery id: efd75f9f-c101-4d7f-91ae-448bea1a3aa9Ok.3 rows in set. Elapsed: 0.005 sec.

其他节点查询

select * from enic_test;

SELECT *
FROM enic_testQuery id: 2e74c5b6-b16f-41ef-888d-ea2e6047d6a9┌─id─┬─name──┬──────birth─┐
│  1 │ test1 │ 2022-02-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  2 │ test2 │ 2022-03-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  3 │ test3 │ 2022-04-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  1 │ test1 │ 2022-02-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  3 │ test3 │ 2022-04-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  2 │ test2 │ 2022-03-01 │
└────┴───────┴────────────┘6 rows in set. Elapsed: 0.007 sec. 

以上,完成clickhouse 3shard1replica集群部署。


http://www.ppmy.cn/news/132104.html

相关文章

安装arcgis destop后启动不了,几种处理方法

托尔斯泰《安娜卡列尼娜》中说&#xff1a;“幸福的家庭都是相似的&#xff0c;不幸的家庭各有各的不幸。”对于很多初次接触arcgis destop的人而言&#xff0c;安装arcgis destop不成功是件非常恼人的事情。别人常常一步搞定&#xff0c;偏偏自己各种搜索、卸载、重装都无济于…

AP6181固件

注&#xff1a;有需要其它正基型号固件或正基技术问题可下方留言 完整文件地址&#xff1a;AP6181固件 驱动地址&#xff1a;正基通用驱动 #AP6181_NVRAM_V1.1_01152013 #adjuest PA parameter for g/n mode manfid0x2d0 prodid0x492 vendid0x14e4 devid0x4343 boardtype0x0598…

ARC155A

arc155A 题目传送门&#xff1a; ATC lg 题意&#xff1a; 给你一个长度为 n n n 的字符串 s s s&#xff0c;问你是否存在一个长度为 k k k 的字符串 s ′ s s′ 使得 s s ′ s s ss′ 和 s ′ s s s s′s 都是回文串。 solution&#xff1a; 我们分讨一下。 …

高通子系统subsystem基础知识

翻译了高通相关文档部分内容&#xff0c;结合sm4350平台项目做的总结&#xff1a; 1&#xff0c;基本概念 Subsystem The system on chip (SoC) consists of a main APSS processor and additional processors that run on their own software. For example, on QTI SoCs, ot…

高通子系统介绍

翻译了高通相关文档部分内容&#xff0c;结合sm4350平台项目做的总结&#xff1a; 一、基本概念 Subsystem The system on chip (SoC) consists of a main APSS processor and additional processors that run on their own software. For example, on QTI SoCs, other proces…

DC(数码相机) 产品名词解析

产品类型&#xff1a;单反相机&#xff0c;卡片相机&#xff0c;长焦相机&#xff0c;家用相机&#xff0c;和旁轴相机卡片相机 在业界内没有明确的概念&#xff0c;仅指那些小巧的外形、相对较轻的机身以及超薄时尚的设计是衡量此类数码相机的主要标准。缺点&#xff1a;手动功…

一双皮鞋

天还没有亮&#xff0c;老婆便????起了床&#xff0c;和尚在睡梦中的我耳语了几句便出门了。被老婆出门时的关门声惊醒&#xff0c;我睡不着了&#xff0c;只能用羡慕的眼光望一望我身边睡得正酣的儿子和女儿&#xff0c;便翻身起床。 其实&#xff0c;很早老婆就嚷嚷要丢下…

win10 查看笔记本电池循环次数

win10下运行命令行工具&#xff08;winr&#xff0c;输入cmd&#xff09;&#xff0c;执行 Powercfg /batteryreport 生成电池报告&#xff0c;命令行会提示报告的位置。 打开报告文件&#xff0c;找到Installed batteries章节&#xff0c;里面有个CYCLE COUNT&#xff0c;后面…