ClickHouse分布式集群搭建

1.在集群的所有机器上都安装ClickHouse服务端

使用RPM安装包进行安装,首先添加官方存储库

sudo yum install yum-utils
sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/stable/x86_64

执行安装命令

sudo yum install clickhouse-server clickhouse-client

注意:我这是三台机器都执行了上诉的步骤

2.在配置文件中设置集群的配置

(1)修改 /etc/clickhouse-server/config.xml 配置文件(注意:这里的配置不能分发,需要每台节点单独修改)

<!-- 将监听来自于IPv4和IPv6连接的通配打开 -->
<listen_host>::</listen_host>

(2)在 /etc 目录下面添加 metrika.xml 配置文件,并添加下面内容(分发到其它两台机器),
下面内容配置的是集群的配置与zookeeper服务的配置

<yandex>
<clickhouse_remote_servers>
    <bip_ck_cluster>
        <shard>
            <replica>
                <host>node1</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <replica>
                <host>node2</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <replica>
                <host>node3</host>
                <port>9000</port>
            </replica>
        </shard>
   </bip_ck_cluster>
</clickhouse_remote_servers>
<zookeeper-servers>
    <node index="1">
        <host>node1</host>
        <port>2181</port>
    </node>
    <node index="2">
        <host>node2</host>
        <port>2181</port>
    </node>
    <node index="3">
        <host>node3</host>
        <port>2181</port>
    </node>
</zookeeper-servers>
</yandex>

注意:<clickhouse_remote_servers>,标签必须与/etc/clickhouse-server/config.xml配置文件中标签引用名称一致,下面列出的就是config.xml配置文件内容

<zookeeper incl="zookeeper-servers" optional="true" />
<remote_servers incl="clickhouse_remote_servers" >

3.启动集群

启动服务器

/etc/init.d/clickhouse-server start

启动客户端

clickhouse-client -m

查询集群是否配置成功

select * from system.clusters;

结果如下


┌─cluster──────────────────────────────────────┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name───────┬─host_address────┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─estimated_recovery_time─┐
│ bip_ck_cluster                               │         111 │ node1           │ node1           │ 90001default │                  │            00 │
│ bip_ck_cluster                               │         211 │ node2           │ node2           │ 90000default │                  │            00 │
│ bip_ck_cluster                               │         311 │ node3           │ node3           │ 90000default │                  │            00 │
│ test_cluster_two_shards                      │         111127.0.0.1127.0.0.190001default │                  │            00 │
│ test_cluster_two_shards                      │         211127.0.0.2127.0.0.290000default │                  │            00 │
│ test_cluster_two_shards_internal_replication │         111127.0.0.1127.0.0.190001default │                  │            00 │
│ test_cluster_two_shards_internal_replication │         211127.0.0.2127.0.0.290000default │                  │            00 │
│ test_cluster_two_shards_localhost            │         111 │ localhost       │ ::190001default │                  │            00 │
│ test_cluster_two_shards_localhost            │         211 │ localhost       │ ::190001default │                  │            00 │
│ test_shard_localhost                         │         111 │ localhost       │ ::190001default │                  │            00 │
│ test_shard_localhost_secure                  │         111 │ localhost       │ ::194400default │                  │            00 │
│ test_unavailable_shard                       │         111 │ localhost       │ ::190001default │                  │            00 │
│ test_unavailable_shard                       │         211 │ localhost       │ ::110default │                  │            00 │
└──────────────────────────────────────────────┴───────────┴──────────────┴─────────────┴─────────────────┴─────────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────────────┘

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值