当前位置: 首页 > news >正文

clickhouse搭建单机版和集群版本

 

本次部署版本是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.jsqmd.com/news/16876/

相关文章:

  • snr db是啥
  • 零基础Linux快速上手02
  • 零基础Linux快速上手-01
  • securecrt linux版本安装
  • P1896[SCOI2005]互不侵犯 解题笔记
  • habse
  • P2214 [USACO14MAR] Mooo Moo S 解题笔记
  • P1854 花店橱窗布置 解题笔记
  • 什么是 DAQ
  • 央企程序员AI创业一个月感受 ✨
  • 微信小程序 在云函数本地调试时,总是提示node modules 未安装,立即安装。解决方法
  • 完整教程:C#开源项目:如何让100个贡献者比1个维护者更高效?
  • 使用PySide6/PyQt6实现自定义窗口布局,实现类似FluentWindow效果
  • 读书日记1
  • 对拍教程(自用)
  • 物理AI:智能自动化的下一个前沿
  • Write To Spreadsheet labview这是什么
  • 2025/10/19
  • tryhackme-预安全-网络基础知识-局域网介绍-05
  • 从众多知识汲取一星半点也能受益匪浅【day16(2025.10.18)】(加班但只加到四点半)
  • (个人思考)游戏技能的实现
  • 模拟赛T4 分析
  • UUT = Unit Under Test
  • ubuntu系统中containerd的cni网络配置
  • 十月阅读笔记
  • #20232408 2025-2026-1 《网络与系统攻防技术》实验二实验报告 - 20232408
  • 关于我的博客密码
  • UML图与数据流图
  • 题解:P2672 [NOIP 2015 普及组] 推销员
  • 如何选择合适的SAP实施公司?3步锁定靠谱的SAP服务商