Clickhouse集群部署
Posted Demonson
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Clickhouse集群部署相关的知识,希望对你有一定的参考价值。
zookeeper集群部署
vim /etc/hosts
192.168.1.11 server1
192.168.1.12 server2
192.168.1.13 server3
解压部署zookeeper
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz -C /usr/local/
mv /usr/local/apache-zookeeper-3.8.0-bin /usr/local/zookeeper
cd /usr/local/zookeeper/conf/
cp zoo_sample.cfg zoo.cfg
修改配置文件zoo.cfg
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/datalog
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
server.1=server1:2888:3888
server.2=server2:2888:3888
server.3=server3:2888:3888
创建相应目录 mkdir /usr/local/zookeeper/data /usr/local/zookeeper/datalog/
复制当前/usr/local/zookeeper目录到其他节点
scp -P 10022 -rp /usr/local/zookeeper server2:/usr/local/
scp -P 10022 -rp /usr/local/zookeeper server3:/usr/local/
配置每一台的myid
server1:
echo 1 > /data/myid
server2:
echo 1 > /data/myid
server3:
echo 1 > /data/myid
进入到zookeeper的bin目录,分别启动zookeeper
./zkServer.sh start
./zkServer.sh status 验证。
2.部署clickhouse集群
各个几点上传CK软件,解压部署。
cd /home/clickhouse
tar -zxvf clickhouse-client-22.3.2.2.tgz
tar -zxvf clickhouse-common-static-22.3.2.2.tgz
tar -zxvf clickhouse-common-static-dbg-22.3.2.2.tgz
tar -zxvf clickhouse-server-22.3.2.2.tgz
rm -f *.tgz
--创建软连接将数据存储到/home下
ln -s /home/clickhouse/clickhouse /var/lib/clickhouse
sh clickhouse-common-static-dbg-22.3.2.2/install/doinst.sh
sh clickhouse-common-static-22.3.2.2/install/doinst.sh
sh clickhouse-server-22.3.2.2/install/doinst.sh --密码可以设设置为空
sh clickhouse-client-22.3.2.2/install/doinst.sh
修改配置文件
chmod 600 /etc/clickhouse-server/config.xml
vim /etc/clickhouse-server/config.xml
--添加:
<include_from>/etc/clickhouse-server/metrika.xml</include_from>
<remote_servers incl="clickhouse_remote_servers" />
<zookeeper incl="zookeeper-servers" optional="true" />
<macros incl="macros" optional="true" />
--将默认的<remote_servers>删除
修改:<listenhost>::</listenhost> 放开 不然远程客户端连不上
vim /etc/clickhouse-server/metrika.xml
<yandex>
<!-- 集群配置 -->
<clickhouse_remote_servers>
<!-- 3分片1备份 -->
<cluster_3shards_1replicas>
<!-- 数据分片1 -->
<shard>
<replica>
<internal_replication>true</internal_replication>
<host>server1</host>
<port>9000</port>
</replica>
</shard>
<!-- 数据分片2 -->
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>server2</host>
<port> 9000</port>
</replica>
</shard>
<!-- 数据分片3 -->
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>server3</host>
<port>9000</port>
</replica>
</shard>
</cluster_3shards_1replicas>
</clickhouse_remote_servers>
<!---zokeeper配置 -->
<zookeeper-servers>
<node>
<host>server1</host>
<port>2181</port>
</node>
<node>
<host>server2</host>
<port>2181</port>
</node>
<node>
<host>server3</host>
<port>2181</port>
</node>
</zookeeper-servers>
<!--副本名称-->
<macros>
<replica>server3</replica>
</macros>
<networks>
<ip>::/0</ip>
</networks>
</yandex>
将两个配置文件同步到其他节点
scp -P 10022 -rp config.xml server2:/etc/clickhouse-server/
scp -P 10022 -rp metrika.xml server2:/etc/clickhouse-server/
scp -P 10022 -rp config.xml server3:/etc/clickhouse-server/
scp -P 10022 -rp metrika.xml server3:/etc/clickhouse-server/
启动各个节点CK,验证
systemctl start clickhouse-server
clickhouse-client
select * from system.clusters;
create database testdb on cluster cluster_3shards_1replicas;
以上是关于Clickhouse集群部署的主要内容,如果未能解决你的问题,请参考以下文章