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 │ 1 │ 1 │ 1 │ node1 │ node1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ bip_ck_cluster │ 2 │ 1 │ 1 │ node2 │ node2 │ 9000 │ 0 │ default │ │ 0 │ 0 │
│ bip_ck_cluster │ 3 │ 1 │ 1 │ node3 │ node3 │ 9000 │ 0 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards │ 1 │ 1 │ 1 │ 127.0.0.1 │ 127.0.0.1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards │ 2 │ 1 │ 1 │ 127.0.0.2 │ 127.0.0.2 │ 9000 │ 0 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards_internal_replication │ 1 │ 1 │ 1 │ 127.0.0.1 │ 127.0.0.1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards_internal_replication │ 2 │ 1 │ 1 │ 127.0.0.2 │ 127.0.0.2 │ 9000 │ 0 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards_localhost │ 1 │ 1 │ 1 │ localhost │ ::1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards_localhost │ 2 │ 1 │ 1 │ localhost │ ::1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_shard_localhost │ 1 │ 1 │ 1 │ localhost │ ::1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_shard_localhost_secure │ 1 │ 1 │ 1 │ localhost │ ::1 │ 9440 │ 0 │ default │ │ 0 │ 0 │
│ test_unavailable_shard │ 1 │ 1 │ 1 │ localhost │ ::1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_unavailable_shard │ 2 │ 1 │ 1 │ localhost │ ::1 │ 1 │ 0 │ default │ │ 0 │ 0 │
└──────────────────────────────────────────────┴───────────┴──────────────┴─────────────┴─────────────────┴─────────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────────────┘