clickhose集群搭建

搭建说明

Clickhouse集群依赖Zookeeper集群。因此需要先搭建zk集群。

请先参考 【记录】zookeeper集群搭建详细步骤 完成zookeeper集群搭建。

如果zookeeper集群已成功搭建完成,下面开始搭建Clickhouse集群。

需要环境:centos7.9+zookeeper+JDK8+clickhouse 22.2.2.1-2

机器:hdp01 hdp02 hdp03

1、rpm安装

# 下载
cd /opt/soft/clickhouse

wget https://mirrors.tuna.tsinghua.edu.cn/clickhouse/rpm/stable/x86_64/clickhouse-client-22.2.2.1-2.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/clickhouse/rpm/stable/x86_64/clickhouse-common-static-22.2.2.1-2.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/clickhouse/rpm/stable/x86_64/clickhouse-server-22.2.2.1-2.noarch.rpm


# 安装命令
rpm -ivh clickhouse-common-static-22.2.2.1-2.x86_64.rpm clickhouse-client-22.2.2.1-2.noarch.rpm clickhouse-server-22.2.2.1-2.no

在三台实例上重复上述操作

2、配置修改

9000端口已经被占用,改用5566端口

cd /etc/clickhouse-server
vim config.xml
config.xml:

<listen_host>0.0.0.0</listen_host>

<tcp_port>5566</tcp_port>

<remote_servers>
        <enic_cluster>
            <shard>
                <replica>
                    <host>192.168.11.11</host>
                    <port>5566</port>
                </replica>
            </shard>
            <shard>
                <replica>
                    <host>192.168.11.12</host>
                    <port>5566</port>
                </replica>
            </shard>
            <shard>
                <replica>
                    <host>192.168.11.13</host>
                    <port>5566</port>
                </replica>
            </shard>
        </enic_cluster>
</remote_servers>
vim users.xml
users.xml:

<enic>
    <password>autoai123</password>
    <networks incl="networks" replace="replace">
        <ip>::/0</ip>
    </networks>
    <profile>default</profile>
    <quota>default</quota>
</enic>
vim metrika.xml

3、启动

#重启clickhouse-server
systemctl restart clickhouse-server
1
#查看clickhouse-server状态
systemctl status clickhouse-server

在三台实例上重复上述操作

4、其它操作

#启动clickhouse-server
systemctl start clickhouse-server

#关闭clickhouse-server
systemctl stop clickhouse-server

#查看clickhouse-server状态
systemctl status clickhouse-server

#查看集群状态
clickhouse-client --host="127.0.0.1" --port="5566" --user="enic" --password="autoai123"

select * from system.clusters where cluster = 'enic_cluster';

SELECT *
FROM system.clusters
WHERE cluster = 'enic_cluster'

5、集群操作

创建本地表

CREATE TABLE enic_test_local ON CLUSTER enic_cluster (
id Int16,
name String,
birth Date
)ENGINE = MergeTree()
PARTITION BY toYYYYMM(birth)
ORDER BY id;


insert into enic_test_local values(1, 'test1', '2022-02-01'), (2, 'test2', '2022-03-01'), (3, 'test3', '2022-04-01');
1
select * from enic_test_local;

创建分布式表

CREATE TABLE default.enic_test ON CLUSTER enic_cluster as enic_test_local engine = Distributed(enic_cluster, default, enic_test_local,rand());

CREATE TABLE default.enic_test ON CLUSTER enic_cluster AS enic_test_local
ENGINE = Distributed(enic_cluster, default, enic_test_local, rand())

Query id: 22bc54a5-a615-4756-9132-a76b65bc5664
┌─host──────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
│ 192.168.11.13 │ 9000 │      0 │       │                   2 │                0 │
│ 192.168.11.12 │ 9000 │      0 │       │                   1 │                0 │
│ 192.168.11.11 │ 9000 │      0 │       │                   0 │                0 │
└───────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
3 rows in set. Elapsed: 0.128 sec. 

insert into enic_test values(1, 'test1', '2022-02-01'), (2, 'test2', '2022-03-01'), (3, 'test3', '2022-04-01');

INSERT INTO enic_test FORMAT Values
Query id: efd75f9f-c101-4d7f-91ae-448bea1a3aa9
Ok.
3 rows in set. Elapsed: 0.005 sec.

其他节点查询

SELECT *
FROM enic_test
Query id: 2e74c5b6-b16f-41ef-888d-ea2e6047d6a9
┌─id─┬─name──┬──────birth─┐
│  1 │ test1 │ 2022-02-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  2 │ test2 │ 2022-03-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  3 │ test3 │ 2022-04-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  1 │ test1 │ 2022-02-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  3 │ test3 │ 2022-04-01 │
└────┴───────┴────────────┘
┌─id─┬─name──┬──────birth─┐
│  2 │ test2 │ 2022-03-01 │
└────┴───────┴────────────┘
6 rows in set. Elapsed: 0.007 sec. 

以上,完成clickhouse 3shard1replica集群部署。

优化遗留:

使用的是默认存储位置,查看稍微麻烦,如有必须可以更改

参考链接:https://blog.csdn.net/qq_32212587/article/details/124457415

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值