clickhouse搭建单机版和集群版本

news/2025/10/19 20:22:20/文章来源:https://www.cnblogs.com/lfxx/p/19151342

 

本次部署版本是25.7.8.71,github下载地址https://github.com/ClickHouse/ClickHouse/releases

一、单机版

采用tgz方式部署

cd /opt/clickhouse

1、下载clickhouse-common-static包,然后解压运行脚本

wget https://github.com/ClickHouse/ClickHouse/releases/download/v25.7.8.71-stable/clickhouse-common-static-25.7.8.71-amd64.tgz
tar zxvf clickhouse-common-static-25.7.8.71-amd64.tgz
clickhouse-common-static-25.7.8.71/install/doinst.sh

2、下载clickhouse-common-static-dbg包,然后解压运行脚本

wget https://github.com/ClickHouse/ClickHouse/releases/download/v25.7.8.71-stable/clickhouse-common-static-dbg-25.7.8.71-amd64.tgz
tar zxvf clickhouse-common-static-dbg-25.7.8.71-amd64.tgz
clickhouse-common-static-dbg-25.7.8.71/install/doinst.sh

3、下载clickhouse-server包,然后解压运行脚本,然后会提示输入默认账户default的密码,这里我输入密码是sykj1234

wget https://github.com/ClickHouse/ClickHouse/releases/download/v25.7.8.71-stable/clickhouse-server-25.7.8.71-amd64.tgz
tar zxvf clickhouse-server-25.7.8.71-amd64.tgz
clickhouse-server-25.7.8.71/install/doinst.sh

4、下载clickhouse-client包,然后解压运行脚本

wget https://github.com/ClickHouse/ClickHouse/releases/download/v25.7.8.71-stable/clickhouse-client-25.7.8.71-amd64.tgz
tar zxvf clickhouse-client-25.7.8.71-amd64.tgzclickhouse-client-25.7.8.71-amd64.tgz
clickhouse-client-25.7.8.71/install/doinst.sh

5、修改配置

vim /etc/clickhouse-server/config.xml
<!-- 找到<listen_host>配置修改监听IP --><listen_host>0.0.0.0</listen_host>

6、启动clickhouse-server

systemctl start clickhouse-server

 

二、集群版

本次部署为3节点3分片1副本,使用clickhouse-keeper代替zookeeper,服务器信息如下

服务器ip server_id    
192.168.18.12 1    
192.168.18.13 2    
192.168.18.14 3    

 

 

 

 

1、各点节点按照单机版部署clickhouse

 

2、在各个节点配置clickhouse-keeper,主要是修改server_id、listen_host和raft_configuration配置

 vim /etc/clickhouse-keeper/keeper_config.xml
    # 添加listen_host配置<listen_host>0.0.0.0</listen_host><keeper_server><tcp_port>9181</tcp_port><!-- Must be unique among all keeper serves -->
            <server_id>1</server_id><log_storage_path>/var/lib/clickhouse/coordination/logs</log_storage_path><snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path><coordination_settings><operation_timeout_ms>10000</operation_timeout_ms><min_session_timeout_ms>10000</min_session_timeout_ms><session_timeout_ms>100000</session_timeout_ms><raft_logs_level>information</raft_logs_level><compress_logs>false</compress_logs><!-- enable sanity hostname checks for cluster configuration (e.g. if localhost is used with remote endpoints) --><hostname_checks_enabled>true</hostname_checks_enabled>
            <raft_configuration><server><id>1</id><!-- Internal port and hostname --><hostname>192.168.18.12</hostname><port>9234</port></server><!-- Add more servers here --><server><id>2</id><!-- Internal port and hostname --><hostname>192.168.18.13</hostname><port>9234</port></server><server><id>3</id><!-- Internal port and hostname --><hostname>192.168.18.14</hostname><port>9234</port></server></raft_configuration></keeper_server>

 

3、在各个节点启动clickhouse-keeper

systemctl start clickhouse-keeper

 

4、在各个节点配置clickhouse-server

配置clickhouse-server指向clickhouse-keeper

vim /etc/clickhouse-server/config.xml 
#找到zookeeper字段并配置<zookeeper><node><host>192.168.18.12</host><port>9181</port></node><node><host>192.168.18.13</host><port>9181</port></node><node><host>192.168.18.14</host><port>9181</port></node></zookeeper>

 

5、配置remote_servers,其中my_cluster是自定义的集群名称

    <remote_servers><!-- Test only shard config for testing distributed storage --><my_cluster><!-- Inter-server per-cluster secret for Distributed queriesdefault: no secret (no authentication will be performed)If set, then Distributed queries will be validated on shards, so at least:- such cluster should exist on the shard,- such cluster should have the same secret.And also (and which is more important), the initial_user willbe used as current user for the query.Right now the protocol is pretty simple, and it only takes into account:- cluster name- queryAlso, it will be nice if the following will be implemented:- source hostname (see interserver_http_host), but then it will depend on DNS,it can use IP address instead, but then you need to get correct on the initiator node.- target hostname / ip address (same notes as for source hostname)- time-based security tokens--><!-- <secret></secret> --><shard><!-- Optional. Whether to write data to just one of the replicas. Default: false (write data to all replicas). --><!-- <internal_replication>false</internal_replication> --><!-- Optional. Shard weight when writing data. Default: 1. --><!-- <weight>1</weight> --><replica><host>192.168.18.12</host><port>9000</port><user>default</user><password>sykj1234</password><!-- Optional. Priority of the replica for load_balancing. Default: 1 (less value has more priority). --><!-- <priority>1</priority> --><!-- Use SSL? Default: no --><!-- <secure>0</secure> --><!-- Optional. Bind to specific host before connecting to use a specific network. --><!-- <bind_host>10.0.0.1</bind_host> --></replica></shard><shard><!-- Optional. Whether to write data to just one of the replicas. Default: false (write data to all replicas). --><!-- <internal_replication>false</internal_replication> --><!-- Optional. Shard weight when writing data. Default: 1. --><!-- <weight>1</weight> --><replica><host>192.168.18.13</host><port>9000</port><user>default</user><password>sykj1234</password><!-- Optional. Priority of the replica for load_balancing. Default: 1 (less value has more priority). --><!-- <priority>1</priority> --><!-- Use SSL? Default: no --><!-- <secure>0</secure> --><!-- Optional. Bind to specific host before connecting to use a specific network. --><!-- <bind_host>10.0.0.1</bind_host> --></replica></shard><shard><!-- Optional. Whether to write data to just one of the replicas. Default: false (write data to all replicas). --><!-- <internal_replication>false</internal_replication> --><!-- Optional. Shard weight when writing data. Default: 1. --><!-- <weight>1</weight> --><replica><host>192.168.18.14</host><port>9000</port><user>default</user><password>sykj1234</password><!-- Optional. Priority of the replica for load_balancing. Default: 1 (less value has more priority). --><!-- <priority>1</priority> --><!-- Use SSL? Default: no --><!-- <secure>0</secure> --><!-- Optional. Bind to specific host before connecting to use a specific network. --><!-- <bind_host>10.0.0.1</bind_host> --></replica></shard></my_cluster></remote_servers>

 

6、在各个节点启动clickhouse-server

systemctl start clickhouse-server

 

7、验证集群

在其中3个节点中的任意一个上执行

登录clickhouse

clickhouse-client

查看集群消息

show clusters;
select * from system.cluster

 

8、插入数据验证分片

在其中3个节点中的任意一个上执行

创建数据库

create database ruby_db01 on cluster my_cluster

创建存储表

create table ruby_db01.c_mgtree_l on cluster my_cluster (
id Int,
label String,
dt Date
)engine = MergeTree()
partition by toYYYYMMDD(dt)
order by id

创建分布式表

CREATE TABLE ruby_db01.c_mgtree_c ON CLUSTER my_cluster
(`id` Int,`label` String,`dt` Date
)ENGINE = Distributed('my_cluster', 'ruby_db01', 'c_mgtree_l', rand())

插入数据

INSERT INTO ruby_db01.c_mgtree_c (id, label, dt) VALUES (1, '苹果', '2025-10-19 17:42:01')INSERT INTO ruby_db01.c_mgtree_c (id, label, dt) VALUES (2, '香蕉', '2025-10-19 17:42:01')INSERT INTO ruby_db01.c_mgtree_c (id, label, dt) VALUES (3, '橙子', '2025-10-19 17:42:01')INSERT INTO ruby_db01.c_mgtree_c (id, label, dt) VALUES (4, '葡萄', '2025-10-19 17:42:01')INSERT INTO ruby_db01.c_mgtree_c (id, label, dt) VALUES (5, '西瓜', '2025-10-19 17:42:01')INSERT INTO ruby_db01.c_mgtree_c (id, label, dt) VALUES (6, '哈密瓜', '2025-10-19 17:42:01')INSERT INTO ruby_db01.c_mgtree_l (id, label, dt) VALUES (7, '番茄', '2025-10-19 17:42:01')

然后分别在3个节点上查看数据

#可以得到所有数据
select * from ruby_db01.c_mgtree_c#只得到部分数据
select * from ruby_db01.c_mgtree_l

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/940583.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

snr db是啥

snr db是啥📘 一、SNR 是什么 SNR 是 Signal-to-Noise Ratio 的缩写, 中文叫 信噪比。表示“信号的强度”和“噪声的强度”之间的比值。⚙️ 二、基本定义公式 以功率为例:SNR=PsignalPnoiseSNR = \frac{P_{signal…

零基础Linux快速上手02

零基础Linux快速上手02 好的,各位同学,欢迎来到《零基础Linux快速上手》第二章节! 在第一章节中,我们学会了在Linux的"房子"里自由行走和整理物品。现在,我们要学习更强大的技能:如何高效地处理文本信…

零基础Linux快速上手-01

零基础Linux快速上手-01好的,各位同学,大家好! 欢迎来到《零基础Linux快速上手》的第一章节。作为你们的讲师,我深知第一步的重要性。我们不求高深,但求扎实和有趣。今天,我们将通过五个经典的Linux场景实验,带…

securecrt linux版本安装

1.安装官网下载scrt-9.6.4-3695.ubuntu24-64.x86_64.debsudo dpkg -i scrt-9.6.4-3695.ubuntu24-64.x86_64.deb sudo apt install -f2.激活 2.1.脚本运行报错 root@ubuntu:/home/jianhua/Downloads# ./securecrt_linu…

P1896[SCOI2005]互不侵犯 解题笔记

由于答案可能会很大,不难想到使用状压dp解决。 考虑使用二进制来表示: \[100010_{(2)} = 34_{(10)} \]这种访问方式比数组寻址更加简单快速,如 \((1 << (k - 1)) \& s\) 可以询问状态 \(s\) 的第 \(k\) 位…

habse

为什么需要它? 简单来说,HBase是一个建立在Hadoop文件系统(HDFS)之上的、分布式的、可扩展的NoSQL数据库。 它的设计灵感来源于Google的Bigtable论文,旨在提供一个能可靠地存储和处理海量结构化或半结构化数据的解…

P2214 [USACO14MAR] Mooo Moo S 解题笔记

思路: 完全背包问题。 对每个牧场做类似于差分的操作,求出每个牧场自身需要达到多少的音量。然后再对每个牧场需要达到的音量进行完全背包的操作,将答案统计进变量cnt中,最后输出cnt即可。 中途出现的错误:完全背…

P1854 花店橱窗布置 解题笔记

思路: 我们用一个二维数组 \(dp[i][j]\) 来表示第 \(i\) 束花放不放在第 \(j\) 个花瓶中的最大值,此时,我们可以进行以下两个操作:不放,状态可以描述为:\(dp[i][j] = dp[i][j - 1]\)。 放,状态可以描述为:\(dp…

什么是 DAQ

什么是 DAQDAQ = Data Acquisition(数据采集) 它的任务是:把真实世界的物理信号(电压、电流、温度、压力、速度等)采集成计算机可处理的数字信号。在 LabVIEW 里,它通过 DAQ 硬件 + DAQ 驱动 + LabVIEW 程序 三者…

央企程序员AI创业一个月感受 ✨

一位央企程序员的摸鱼故事。6天写出第一版、7天完成商业化、14天尝试全网推广...这次创业之旅中有欢喜、有迷茫,更有对AI时代的深度思考!💭6月份的时候,写了一篇《我的开源十年》得到了很多朋友的支持,很是欣慰。…

微信小程序 在云函数本地调试时,总是提示node modules 未安装,立即安装。解决方法

首先确定本地npm node 已安装 cmd npm -v node -v没安装去安装nodejs cd到云函数目录,执行 npm install --save wx-server-sdk@latest

完整教程:C#开源项目:如何让100个贡献者比1个维护者更高效?

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

使用PySide6/PyQt6实现自定义窗口布局,实现类似FluentWindow效果

使用PySide6/PyQt6实现自定义窗口布局,实现类似FluentWindow效果现在在很多项目中,会比较喜欢FluentWindow效果,这种左侧类似于图标菜单或者树形结构的,右侧是是动态窗体或者组件的展示方式,一般不是多文档布局,…

读书日记1

今天怀着敬畏之心开始阅读这部被誉为"程序员圣经"的经典著作。《代码大全2》的开篇就给我带来了强烈的思想冲击,让我重新审视自己对软件开发的认知。 核心收获与深刻见解: 1.软件构建的核心地位:McConnel…

对拍教程(自用)

写在前面: 没有掌握对拍啊,每次都是上网贺别人的代码,写一份自己用吧。 对拍,是一个比较实用的工具。它能够非常方便地对于两个程序的输出文件进行比较,可以帮助我们实现一些自动化的比较输出结果的问题。 Step1:…

物理AI:智能自动化的下一个前沿

本文探讨了人工智能与物理系统融合的技术趋势,详细介绍了物理AI的能力层级、关键技术架构以及在制造业、医疗等领域的实际应用案例,展现了从基础自动化到完全自主系统的技术演进路径。物理AI:连接数字智能与物理现实…

Write To Spreadsheet labview这是什么

Write To Spreadsheet labview这是什么很好,这个问题问得很具体。你提到的:Write To Spreadsheet(LabVIEW) 是什么?✅ 简单一句话解释:“Write To Spreadsheet File.vi” 是 LabVIEW 里用来把数据写入文本文件(…

2025/10/19

2025/10/19学习算法

tryhackme-预安全-网络基础知识-局域网介绍-05

tryhackme-Pre Security-Pre Security-Network Fundamentals-Intro to LAN 房间地址:https://tryhackme.com/room/introtolan (该房间需要订阅,关于付费问题。咸鱼OSINT tryhackme即可。) 这是网络安全入门的基础模…

从众多知识汲取一星半点也能受益匪浅【day16(2025.10.18)】(加班但只加到四点半)

Q26.整理工作清单时遇到的问题现象:做了纯样式页面,准备整理清单补充功能逻辑时发现,没有一下子找出原本对照的页面在哪 原因:把对照页面的路径写在了其他地方,没有写在清单上方便对照查看寻找 解决:找到对照页面…