clickhouse集群搭建

准备三台机器,192.168.20.7,192.168.20.8,192.168.20.10用于搭建clickhouse集群。本次搭建的集群,为三副本的,即一份数据会在三台机器上分别存储,搭建集群只是为了容灾。

1. 在192.168.20.7上操作

在clickhouse config.d目录下新建cluster.xml,内容如下

<clickhouse>

<keeper_server>

<tcp_port>9181</tcp_port>

<server_id>1</server_id>

<log_storage_path>/data/clickhouse/coordination/log</log_storage_path> <snapshot_storage_path>/data/clickhouse/coordination/snapshots</snapshot_storage_path>

<coordination_settings>

<operation_timeout_ms>10000</operation_timeout_ms>

<session_timeout_ms>30000</session_timeout_ms>

<raft_logs_level>trace</raft_logs_level>

</coordination_settings>

<raft_configuration>

<server>

<id>1</id>

<hostname>192.168.20.7</hostname>

<port>9234</port>

</server>

<server>

<id>2</id>

<hostname>192.168.20.8</hostname>

<port>9234</port>

</server>

<server>

<id>3</id>

<hostname>192.168.20.10</hostname>

<port>9234</port>

</server>

</raft_configuration>

</keeper_server>

<remote_servers>

<default>

<shard>

<internal_replication>1</internal_replication>

<replica>

<host>192.168.20.7</host>

<port>8124</port>

</replica>

<replica>

<host>192.168.20.8</host>

<port>8124</port>

</replica>

<replica>

<host>192.168.20.10</host>

<port>8124</port>

</replica>

</shard>

</default>

</remote_servers>

<macros>

<shard>1</shard>

<replica>192.168.20.7</replica>

</macros>

<interserver_http_host>192.168.20.7</interserver_http_host>

</clickhouse>

2. 在192.168.20.8上操作

<clickhouse>

<keeper_server>

<tcp_port>9181</tcp_port>

<server_id>2</server_id>

<log_storage_path>/data/clickhouse/coordination/log</log_storage_path> <snapshot_storage_path>/data/clickhouse/coordination/snapshots</snapshot_storage_path>

<coordination_settings>

<operation_timeout_ms>10000</operation_timeout_ms>

<session_timeout_ms>30000</session_timeout_ms>

<raft_logs_level>trace</raft_logs_level>

</coordination_settings>

<raft_configuration>

<server>

<id>1</id>

<hostname>192.168.20.7</hostname>

<port>9234</port>

</server>

<server>

<id>2</id>

<hostname>192.168.20.8</hostname>

<port>9234</port>

</server>

<server>

<id>3</id>

<hostname>192.168.20.10</hostname>

<port>9234</port>

</server>

</raft_configuration>

</keeper_server>

<remote_servers>

<default>

<shard>

<internal_replication>1</internal_replication>

<replica>

<host>192.168.20.7</host>

<port>8124</port>

</replica>

<replica>

<host>192.168.20.8</host>

<port>8124</port>

</replica>

<replica>

<host>192.168.20.10</host>

<port>8124</port>

</replica>

</shard>

</default>

</remote_servers>

<macros>

<shard>1</shard>

<replica>192.168.20.8</replica>

</macros>

<interserver_http_host>192.168.20.8</interserver_http_host>

</clickhouse>

修改了server_id,macros.replica、interserver_http_host三个配置项

3. 在192.168.20.10上操作

<clickhouse>

<keeper_server>

<tcp_port>9181</tcp_port>

<server_id>3</server_id>

<log_storage_path>/data/clickhouse/coordination/log</log_storage_path>

<snapshot_storage_path>/data/clickhouse/coordination/snapshots</snapshot_storage_path>

<coordination_settings>

<operation_timeout_ms>10000</operation_timeout_ms>

<session_timeout_ms>30000</session_timeout_ms>

<raft_logs_level>trace</raft_logs_level>

</coordination_settings>

<raft_configuration>

<server>

<id>1</id>

<hostname>192.168.20.7</hostname>

<port>9234</port>

</server>

<server>

<id>2</id>

<hostname>192.168.20.8</hostname>

<port>9234</port>

</server>

<server>

<id>3</id>

<hostname>192.168.20.10</hostname>

<port>9234</port>

</server>

</raft_configuration>

</keeper_server>

<remote_servers>

<default>

<shard>

<internal_replication>1</internal_replication>

<replica>

<host>192.168.20.7</host>

<port>8124</port>

</replica>

<replica>

<host>192.168.20.8</host>

<port>8124</port>

</replica>

<replica>

<host>192.168.20.10</host>

<port>8124</port>

</replica>

</shard>

</default>

</remote_servers>

<macros>

<shard>1</shard>

<replica>192.168.20.10</replica>

</macros>

<interserver_http_host>192.168.20.10</interserver_http_host>

</clickhouse>

修改了server_id,macros.replica、interserver_http_host三个配置项

4. 启动

在三台机器上分别执行systemctl start clickhouse-server,启动clickhouse服务

启动成功之后,登录clickhouse执行语句,select * from system.clusters;可以看到三个节点,代表集群建立成功。

5.建表

clickhouse集群,需要在每个节点上分别建表,表结构如下所示

CREATE TABLE test.test1

(

`id` Int64

)

ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/test/test1', '{replica}')

ORDER BY id

SETTINGS index_granularity = 8192;

表建好之后,在其中一台节点执行insert后,在其它节点都可以看到该条数据。

相关推荐
皓月盈江21 分钟前
Linux电脑本机使用小皮面板集成环境开发调试WEB项目
linux·php·web开发·phpstudy·小皮面板·集成环境·www.xp.cn
深井冰水26 分钟前
mac M2能安装的虚拟机和linux系统系统
linux·macos
leoufung1 小时前
内核内存锁定机制与用户空间内存锁定的交互分析
linux·kernel
菜菜why2 小时前
AutoDL租用服务器教程
服务器
IT专业服务商2 小时前
联想 SR550 服务器,配置 RAID 5教程!
运维·服务器·windows·microsoft·硬件架构
忧虑的乌龟蛋2 小时前
嵌入式Linux I2C驱动开发详解
linux·驱动开发·嵌入式·iic·i2c·读数据·写数据
I_Scholar3 小时前
OPENSSL-1.1.1的使用及注意事项
linux·ssl
Johny_Zhao3 小时前
K8S+nginx+MYSQL+TOMCAT高可用架构企业自建网站
linux·网络·mysql·nginx·网络安全·信息安全·tomcat·云计算·shell·yum源·系统运维·itsm
稳联技术4 小时前
Ethercat转Profinet网关如何用“协议翻译术“打通自动化产线任督二脉
linux·服务器·网络
烟雨迷4 小时前
Linux环境基础开发工具的使用(yum、vim、gcc、g++、gdb、make/Makefile)
linux·服务器·学习·编辑器·vim