ClickHouse集群搭建(CENTOS7环境)
1. rpm包下载
下载的rpm包版本
-rw-r--r-- 1 root root 134254 5月 28 17:07 clickhouse-client-20.3.9.70-2.noarch.rpm
-rw-r--r-- 1 root root 116924361 5月 28 17:07 clickhouse-common-static-20.3.9.70-2.x86_64.rpm
-rw-r--r-- 1 root root 155513 5月 28 17:07 clickhouse-server-20.3.9.70-2.noarch.rpm
下载地址
2.rpm安装及授权
2.1 分别在各个节点上安装以上rpm包,安装命令``rpm -ivh clickhouse*
2.2 安装完成后,分别执行chmod +R 777 /etc/clickhouse-server
及chmod +R 777 /var/log/clickhouse-server
P.S:这一步主要是防止clickhouse用户无对应访问权限
2.3安装设置完成后,执行systemctl start clickhouse-server.service
启动服务
2.4执行clickhouse-client
,输入select 1查看是否有返回结果
3.集群设置
3.0 确认所有节点的安装及运行均无问题后,可进行集群设置
3.1 创建/etc/metrika.xml
文件,内容如下
<yandex>
<clickhouse_remote_servers>
<perftest_3shards_1replicas>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node01</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<internal_replication>true</internal_replication>
<host>node02</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node03</host>
<port>9000</port>
</replica>
</shard>
</perftest_3shards_1replicas>
</clickhouse_remote_servers>
<!--zookeeper相关配置-->
<zookeeper-servers>
<node index="1">
<host>node01</host>
<port>2181</port>
</node>
<node index="2">
<host>node02</host>
<port>2181</port>
</node>
<node index="3">
<host>node03</host>
<port>2181</port>
</node>
</zookeeper-servers>
<!--此处设置,若metrika.xml在node01则为node01-->
<macros>
<replica>node01</replica>
</macros>
<networks>
<ip>::/0</ip>
</networks>
<clickhouse_compression>
<case>
<min_part_size>10000000000</min_part_size>
<min_part_size_ratio>0.01</min_part_size_ratio>
<method>lz4</method>
</case>
</clickhouse_compression>
</yandex>
3.2 重启所有节点的clickhouse-server
3.3 运行clickhouse-client后,输入select cluster,host_name,host_address from system.clusters
,若返回结果如下,则说明集群设置成功
┌─cluster───────────────────────────┬─host_name─┬─host_address──┐
│ perftest_3shards_1replicas │ node01 │ 10.121.110.33 │
│ perftest_3shards_1replicas │ node02 │ 10.121.110.34 │
│ perftest_3shards_1replicas │ node03 │ 10.121.110.35 │
│ test_cluster_two_shards │ 127.0.0.1 │ 127.0.0.1 │
│ test_cluster_two_shards │ 127.0.0.2 │ 127.0.0.2 │
│ test_cluster_two_shards_localhost │ localhost │ ::1 │
│ test_cluster_two_shards_localhost │ localhost │ ::1 │
│ test_shard_localhost │ localhost │ ::1 │
│ test_shard_localhost_secure │ localhost │ ::1 │
│ test_unavailable_shard │ localhost │ ::1 │
│ test_unavailable_shard │ localhost │ ::1 │
└───────────────────────────────────┴───────────┴───────────────┘
host_name及host_address与各个节点对应
Q&A:
Q1:启动clickhouse-server抛异常,报filenotfoundexception
A1:需要使用chmod命令对/etc/clickhouse-server及/var/log/clickhouse-server/这两个目录赋权。因为clickhouse-server是以clickhouse这一用户启动的,默认情况下,无法读取/etc/clickhouse-server下的设置文件及写/var/log/clickhouse-server/目录下的日志