当前位置: 首页 > 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.zskr.cn/news/24610.html

相关文章:

  • 零基础Linux快速上手-01
  • securecrt linux版本安装
  • P1896[SCOI2005]互不侵犯 解题笔记
  • 央企程序员AI创业一个月感受 ✨
  • Write To Spreadsheet labview这是什么
  • 从众多知识汲取一星半点也能受益匪浅【day16(2025.10.18)】(加班但只加到四点半)
  • 模拟赛T4 分析
  • 十月阅读笔记
  • #20232408 2025-2026-1 《网络与系统攻防技术》实验二实验报告 - 20232408
  • 关于我的博客密码
  • 如何选择合适的SAP实施公司?3步锁定靠谱的SAP服务商
  • 25秋周总结5
  • apisix升级完整流程
  • 程序员做视频难在哪?可能是文案这一关
  • 题解:P12003 在小小的奶龙山里面挖呀挖呀挖(加强版)
  • 如何生成逼真的合成表格数据:独立采样与关联建模方法对比
  • Why dont Japanese people reply to messages
  • 关于从使用blender编辑ue动画的设置
  • Python 潮流周刊#73:让我们对 PyPI 温柔一点,好吗?
  • React+Three.js 实现 Apple 2025 热成像 logo
  • 完整教程:【无人机】无人机群在三维环境中的碰撞和静态避障仿真(Matlab代码实现)
  • 数据采集与融合作业1
  • 运算符与自增自减
  • with关键字
  • 2025 年电磁流量计最新推荐榜,聚焦企业技术实力与市场口碑深度解析
  • 练习篇:从零开始了解网络空间安全(网导1)
  • 2025 年超声波流量计最新推荐榜,技术实力与市场口碑深度解析!
  • 2025年安装厂家权威推荐榜单:管道/电气/生物医药工厂机电/暖通空调/空压系统/纯水系统/厂房通风/车间配电/机械设备/工业设备安装公司精选
  • 嵌入式实验3串口通信---任务一串口传输文件实验
  • Spring Cloud RabbitMQ 详解:从基础概念到秒杀实战 - 详解