dockerer-compose搭建单机clickhouse集群,工作中最新亲测能用,超详细
作为一名菜鸟Java工程师,公司这几天让我搭建clickhouse集群,对于搭建过的人来说十分简单,对zookeeper不太熟悉的人来说还是有一定难度的,这一周我在公司的角色更像是运维人员搭建集群和服务,一个字干,另外kafka搭建点击这篇,zookeeper集群搭建点击这篇。对于集群搭建来说使用docker来搭建更加方便,这里使用docker-compose来搭建clickhouse集群。由于我
·
公司这几天让我搭建clickhouse集群,这一周我在公司的角色更像是运维人员搭建集群和服务,一个字干,另外kafka搭建点击这篇,zookeeper集群搭建点击这篇。
对于集群搭建来说使用docker来搭建更加方便,这里使用docker-compose来搭建clickhouse集群。
由于我自己就一台服务器,那就在一台搭个三分片三副本的集群,这里分二个阶段:准备阶段、搭建阶段。
1、准备阶段:连接客户端的话,一定要去服务器看看有没有配置安全组,否则连不上。
等搭建阶段运行端口起来后可以执行telnet命令,没有的话yum安装一个,用起来方便。
yum list telnet* #列出telnet相关的安装包
yum install telnet-server #安装telnet服务
yum install telnet.* #安装telnet客户端
telnet 你的ip 2181
#修改host文件
vim /etc/hosts
你自己的服务器ip server01
你自己的服务器ip server02
你自己的服务器ip server03
2、搭建阶段:安装docker和docker-compose、创建文件夹、修改配置、运行容器、查看状态
#更新yum
sudo yum update
#安装docker
sudo yum install docker-ce
#安装docker-compose,利用它编排和运行docker容器更方便
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#设置可执行权限
sudo chmod +x /usr/local/bin/docker-compose
#查看安装成功
docker-compose --version
#创建目录
mkdir /home/clickhouse
#先启动一个clickhouse-server容器,获取clickhouse-server的配置文件,操作完可以删除该容器
docker run -d --name clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server
#复制容器内的配置文件到宿主机,这里拷贝到/etc目录下
docker cp clickhouse-server:/etc/clickhouse-server/ /etc/
#准备clickhouse集群的配置目录
cp -rf /etc/clickhouse-server/ /etc/clickhouse-server01-01/
cp -rf /etc/clickhouse-server/ /etc/clickhouse-server01-02/
cp -rf /etc/clickhouse-server/ /etc/clickhouse-server02-01/
cp -rf /etc/clickhouse-server/ /etc/clickhouse-server02-02/
cp -rf /etc/clickhouse-server/ /etc/clickhouse-server03-01/
cp -rf /etc/clickhouse-server/ /etc/clickhouse-server03-02/
修改配置以clickhouse-01-01为例,其他的也要配置,修改include form节点为metrika.xml
vim /etc/clickhouse-server01-01/config.xml
<!-- If element has 'incl' attribute, then for it's value will be used corresponding substitution from another file.
By default, path to file with substitutions is /etc/metrika.xml. It could be changed in config in 'include_from' element.
Values for substitutions are specified in /yandex/name_of_substitution elements in that file.
-->
<include_from>/etc/clickhouse-server/metrika.xml</include_from>
<listen_host>0.0.0.0</listen_host>
<listen_host>127.0.0.1</listen_host>
修改metrika.xml,其他的也做类似修改
vim /etc/clickhouse-server01-01/metrika.xml
<!--所有实例均使用这个集群配置,不用个性化 -->
<yandex>
<!-- 集群配置 -->
<!-- clickhouse_remote_servers所有实例配置都一样 -->
<!-- 集群配置 -->
<clickhouse_remote_servers>
<cluster_3s_1r>
<!-- 数据分片1 -->
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>server01</host>
<port>9000</port>
<user>default</user>
<password></password>
</replica>
<replica>
<host>server03</host>
<port>9001</port>
<user>default</user>
<password></password>
</replica>
</shard>
<!-- 数据分片2 -->
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>server02</host>
<port>9002</port>
<user>default</user>
<password></password>
</replica>
<replica>
<host>server01</host>
<port>9001</port>
<user>default</user>
<password></password>
</replica>
</shard>
<!-- 数据分片3 -->
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>server03</host>
<port>9004</port>
<user>default</user>
<password></password>
</replica>
<replica>
<host>server02</host>
<port>9003</port>
<user>default</user>
<password></password>
</replica>
</shard>
</cluster_3s_1r>
</clickhouse_remote_servers>
<!-- ZK -->
<!-- zookeeper_servers所有实例配置都一样, 这里zookeeper根据你自己情况更改-->
<zookeeper-servers>
<node index="1">
<host>你zookeeper的ip</host>
<port>2181</port>
</node>
<node index="2">
<host>你zookeeper的ip</host>
<port>2182</port>
</node>
<node index="3">
<host>你zookeeper的ip</host>
<port>2183</port>
</node>
</zookeeper-servers>
<!-- marcos每个实例配置不一样 分片1, 副本1 -->
<macros>
<layer>01</layer>
<shard>01</shard>
<replica>cluster01-01-1</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>
运行集群
#启动clickhouse集群,进入创建的数据挂载目录
cd /home/clickhouse
#上传编排文件
rz docker-compose.yml
#启动
docker-compose up -d
#查看日志
docker-compose logs
docker-compoes.yml
version: '3.1'
services:
cs01-01:
image: yandex/clickhouse-server
restart: always
container_name: cs01-01
ports:
- 8000:9000
- 8123:8123
- 9009:9009
volumes:
- /home/clickhouse01-01/:/var/lib/clickhouse
- /etc/clickhouse-server01-01/:/etc/clickhouse-server/
extra_hosts:
- "server01:你自己的ip"
- "server02:你自己的ip"
- "server03:你自己的ip"
hostname: server01
cs01-02:
image: yandex/clickhouse-server
restart: always
container_name: cs01-02
ports:
- 9001:9000
- 8124:8123
- 9010:9009
volumes:
- /home/clickhouse01-02/:/var/lib/clickhouse
- /etc/clickhouse-server01-02/:/etc/clickhouse-server/
extra_hosts:
- "server01:你自己的ip"
- "server02:你自己的ip"
- "server03:你自己的ip"
hostname: server01
cs02-01:
image: yandex/clickhouse-server
restart: always
container_name: cs02-01
ports:
- 9002:9000
- 8125:8123
- 9011:9009
volumes:
- /home/clickhouse02-01/:/var/lib/clickhouse
- /etc/clickhouse-server02-01/:/etc/clickhouse-server/
extra_hosts:
- "server01:你自己的ip"
- "server02:你自己的ip"
- "server03:你自己的ip"
hostname: server02
cs02-02:
image: yandex/clickhouse-server
restart: always
container_name: cs02-02
ports:
- 9003:9000
- 8126:8123
- 9012:9009
volumes:
- /home/clickhouse02-02/:/var/lib/clickhouse
- /etc/clickhouse-server02-02/:/etc/clickhouse-server/
extra_hosts:
- "server01:你自己的ip"
- "server02:你自己的ip"
- "server03:你自己的ip"
hostname: server02
cs03-01:
image: yandex/clickhouse-server
restart: always
container_name: cs03-01
ports:
- 9004:9000
- 8127:8123
- 9013:9009
volumes:
- /home/clickhouse03-01/:/var/lib/clickhouse
- /etc/clickhouse-server03-01/:/etc/clickhouse-server/
extra_hosts:
- "server01:你自己的ip"
- "server02:你自己的ip"
- "server03:你自己的ip"
hostname: server02
cs03-02:
image: yandex/clickhouse-server
restart: always
container_name: cs03-02
ports:
- 9005:9000
- 8128:8123
- 9014:9009
volumes:
- /home/clickhouse03-02/:/var/lib/clickhouse
- /etc/clickhouse-server03-02/:/etc/clickhouse-server/
extra_hosts:
- "server01:你自己的ip"
- "server02:你自己的ip"
- "server03:你自己的ip"
hostname: server03
恭喜你搭建成功,记得一键三连哦!
有些事总值得尝试,永不轻言放弃,前方总有希望在等待。
更多推荐
已为社区贡献1条内容
所有评论(0)