Clickhouse keeper方式搭建集群(不再依赖zookeeper)

打印 上一主题 下一主题

主题 550|帖子 550|积分 1650

下面是怎样在三个节点(192.168.250.140, 192.168.250.146, 192.168.250.147)上摆设 ClickHouse 集群,并使用 ClickHouse Keeper 作为分布式和谐服务的详细步调。
Step 1: 安装 ClickHouse

首先,在每个节点上安装 ClickHouse。以下下令实用于 Debian 系统。
  1. wget -O clickhouse-client_24.4.3.25_amd64.deb https://github.com/ClickHouse/ClickHouse/releases/download/v24.4.3.25-stable/clickhouse-client_24.4.3.25_amd64.deb
  2. wget -O clickhouse-common-static_24.4.3.25_amd64.deb https://github.com/ClickHouse/ClickHouse/releases/download/v24.4.3.25-stable/clickhouse-common-static_24.4.3.25_amd64.deb
  3. wget -O clickhouse-server_24.4.3.25_amd64.deb https://github.com/ClickHouse/ClickHouse/releases/download/v24.4.3.25-stable/clickhouse-server_24.4.3.25_amd64.deb
  4. sudo dpkg -i clickhouse-common-static_24.4.3.25_amd64.deb
  5. sudo dpkg -i clickhouse-client_24.4.3.25_amd64.deb
  6. sudo dpkg -i clickhouse-server_24.4.3.25_amd64.deb
  7. dpkg -l | grep clickhouse  --是否安装成功
复制代码
Step 2: 配置 ClickHouse Keeper

在每个节点上配置 ClickHouse Keeper。编辑 /etc/clickhouse-server/config.xml 文件,添加 ClickHouse Keeper 的配置。
在每个节点上,添加以下配置:
  1. <clickhouse>
  2.       <keeper_server>
  3.         <tcp_port>9181</tcp_port>
  4.         <server_id>1</server_id>
  5.         <log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
  6.         <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>
  7.         <coordination_settings>
  8.             <operation_timeout_ms>10000</operation_timeout_ms>
  9.             <session_timeout_ms>30000</session_timeout_ms>
  10.             <raft_logs_level>trace</raft_logs_level>
  11.         </coordination_settings>
  12.         <raft_configuration>
  13.             <server>
  14.                 <id>1</id>
  15.                 <hostname>192.168.252.140</hostname>
  16.                 <port>9234</port>
  17.             </server>
  18.             <server>
  19.                 <id>2</id>
  20.                 <hostname>192.168.252.146</hostname>
  21.                 <port>9234</port>
  22.             </server>
  23.             <server>
  24.                 <id>3</id>
  25.                 <hostname>192.168.252.147</hostname>
  26.                 <port>9234</port>
  27.             </server>
  28.         </raft_configuration>
  29.     </keeper_server>
  30. </clickhouse>
复制代码
注意:在每个节点上,server_id 应该是唯一的。比方:
● 192.168.250.140 上的 server_id 为 1
● 192.168.250.146 上的 server_id 为 2
● 192.168.250.147 上的 server_id 为 3
Step 3: 配置分片和副本

在每个节点上,编辑 /etc/clickhouse-server/config.d/clusters.xml 文件,配置分片和副本。
  1. <clickhouse>
  2.     <remote_servers>
  3.         <log_cluster> <!-- 使用了自定义的集群名称 -->
  4.             <shard>
  5.                 <replica>
  6.                     <host>192.168.250.140</host>
  7.                     <port>9000</port>
  8.                 </replica>
  9.                 <replica>
  10.                     <host>192.168.250.146</host>
  11.                     <port>9000</port>
  12.                 </replica>
  13.             </shard>
  14.             <shard>
  15.                 <replica>
  16.                     <host>192.168.250.147</host>
  17.                     <port>9000</port>
  18.                 </replica>
  19.                 <replica>
  20.                     <host>192.168.250.140</host>
  21.                     <port>9000</port>
  22.                 </replica>
  23.             </shard>
  24.         </log_cluster>
  25.     </remote_servers>
  26. </clickhouse>
复制代码
Step 4: 配置宏

在对应的节点上参加宏
  1. //在192.168.250.140加入这个宏
  2. <macros>
  3.     <shard>01</shard>
  4.     <replica>192.168.250.140</replica>
  5. </macros>
  6. //在192.168.250.146加入这个宏
  7. <macros>
  8.     <shard>02</shard>
  9.     <replica>192.168.250.146</replica>
  10. </macros>
  11. //在192.168.250.147加入这个宏
  12. <macros>
  13.     <shard>03</shard>
  14.     <replica>192.168.250.147</replica>
  15. </macros>
复制代码
Step 5: 启动 ClickHouse 服务

我使用的所有配置都在/etc/clickhouse-server/config.xml里面
以是解释掉keeper_config.xml里面的 <keeper_server>标签及 <keeper_server>内的内容
Step 6: 启动 ClickHouse 服务
在每个节点上启动 ClickHouse 服务:
  1. sudo systemctl start clickhouse-server
复制代码
并确保服务已启动:
  1. sudo systemctl status clickhouse-server
复制代码
如果启动不能完成初始化如下,不妨删除旧数据
  1. 2024.06.26 21:03:29.159411 [ 94688 ] {} <Information> KeeperDispatcher: Server still not initialized, will not apply configuration until initialization finished
  2. 2024.06.26 21:03:34.159564 [ 94688 ] {} <Information> KeeperDispatcher: Server still not initialized, will not apply configuration until initialization finished
  3. 2024.06.26 21:03:39.159754 [ 94688 ] {} <Information> KeeperDispatcher: Server still not initialized, will not apply configuration until initialization finished
  4. 2024.06.26 21:03:44.159931 [ 94688 ] {} <Information> KeeperDispatcher: Server still not initialized, will not apply configuration until initialization finished
  5. 2024.06.26 21:03:49.160159 [ 94688 ] {} <Information> KeeperDispatcher: Server still not initialized, will not apply configuration until initialization finished
复制代码
  1.   sudo rm -rf /var/lib/clickhouse/coordination/log/*
  2.   sudo rm -rf /var/lib/clickhouse/coordination/snapshots/*
复制代码
Step 6: 创建分布式表

使用 ClickHouse 客户端连接到恣意一个节点,创建分布式表。
clickhouse-client -h 192.168.250.140
  1. -- 创建数据库
  2. CREATE DATABASE IF NOT EXISTS test;
  3. -- 创建本地表
  4. CREATE TABLE test.local_table ON CLUSTER log_cluster (
  5.     id UInt32,
  6.     name String
  7. ) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/test/local_table', '{replica}')
  8. ORDER BY id;
  9. -- 创建分布式表
  10. CREATE TABLE test.distributed_table ON CLUSTER your_cluster_name AS test.local_table
  11. ENGINE = Distributed(log_cluster, test, local_table, rand());
复制代码
配置总结

  1. <listen_host>0.0.0.0</listen_host>
  2.        <log_cluster>
  3.             <shard>
  4.                 <replica>
  5.                     <host>192.168.250.140</host>
  6.                     <port>9000</port>
  7.                 </replica>
  8.             </shard>
  9.             <shard>
  10.                 <replica>
  11.                     <host>192.168.250.146</host>
  12.                     <port>9000</port>
  13.                 </replica>
  14.             </shard>
  15.             <shard>
  16.                 <replica>
  17.                     <host>192.168.250.147</host>
  18.                     <port>9000</port>
  19.                 </replica>
  20.             </shard>
  21.         </log_cluster>
  22.        <keeper_server>
  23.         <tcp_port>9181</tcp_port>
  24.         <server_id>1</server_id>
  25.         <log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
  26.         <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>
  27.         <coordination_settings>
  28.             <operation_timeout_ms>10000</operation_timeout_ms>
  29.             <session_timeout_ms>30000</session_timeout_ms>
  30.             <raft_logs_level>trace</raft_logs_level>
  31.         </coordination_settings>
  32.         <raft_configuration>
  33.             <server>
  34.                 <id>1</id>
  35.                 <hostname>192.168.252.140</hostname>
  36.                 <port>9234</port>
  37.             </server>
  38.             <server>
  39.                 <id>2</id>
  40.                 <hostname>192.168.252.146</hostname>
  41.                 <port>9234</port>
  42.             </server>
  43.             <server>
  44.                 <id>3</id>
  45.                 <hostname>192.168.252.147</hostname>
  46.                 <port>9234</port>
  47.             </server>
  48.         </raft_configuration>
  49.     </keeper_server>
  50. <macros>
  51.     <shard>shardNum</shard>
  52.     <replica>192.168.250.140</replica>
  53. </macros>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

守听

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表