OLAP系列:三、clickhouse Docker集群部署指南(3分片1副本模式)

一、背景

一是为了学习容器,另外也是帮助一些同学解决机器资源紧缺,能够在一台是宿主机部署一套clickhouse集群服务。

本章内容适合开发测试环境使用,生产环境还需要更多细节的处理工作,只能作为参考。

二、部署准备

1、机器准备

172.25.16.108

2、创建容器网络

docker network create ckcluster

3、镜像准备

# 查看仓库镜像列表
curl -XGET https://nexus.***.com:8445/v2/_catalog | json_reformat
# 查看clickhouse镜像信息
curl -XGET https://nexus.***.com:8445/v2/yandex/clickhouse-server/tags/list | json_reformat
# 查看zookeeper镜像信息
curl -XGET https://nexus.***.com:8445/v2/zookeeper/tags/list | json_reformat

三、zookeeper单机安装(1节点)

1、下载镜像

docker pull nexus.***.com:8445/zookeeper:3.8.0

2、容器启动

docker run --restart always -d \
--name zookeeper \
--ulimit nofile=262144:262144 \
--hostname zookeeper \
--network ckcluster \
-p 2181:2181 \
nexus.***.com:8445/zookeeper:3.8.0

四、clickhouse集群安装(3分片1副本)

1、创建目录

cd /home
mkdir ckcluster
cd cluster
mkdir ck1
mkdir ck2
mkdir ck3

2、创建节点配置

# 启动ck1
docker run -d --name clickhouse-server-1 --ulimit nofile=262144:262144 -v /home/ckcluster/ck1/:/var/lib/clickhouse -p 18123:8123 nexus.***.com:8445/yandex/clickhouse-server:latest
# 拷贝容器内容的配置到/data/clickhouse/目录下
docker cp clickhouse-server-1:/etc/clickhouse-server/ /home/ckcluster/ck1/

# 启动ck2
docker run -d --name clickhouse-server-2 --ulimit nofile=262144:262144 -v /home/ckcluster/ck2/:/var/lib/clickhouse -p 28123:8123 nexus.***.com:8445/yandex/clickhouse-server:latest
# 拷贝容器内容的配置到/data/clickhouse/目录下
docker cp clickhouse-server-2:/etc/clickhouse-server/ /home/ckcluster/ck2/

# 启动ck3
docker run -d --name clickhouse-server-3 --ulimit nofile=262144:262144 -v /home/ckcluster/ck3/:/var/lib/clickhouse -p 38123:8123 nexus.***.com:8445/yandex/clickhouse-server:latest
# 拷贝容器内容的配置到/data/clickhouse/目录下
docker cp clickhouse-server-3:/etc/clickhouse-server/ /home/ckcluster/ck3/

3、清除临时容器

docker stop **

docker rm **

4、修改config.xml配置

vim /etc/clickhouse-server/config.xml
/etc/clickhouse-server/config.d/metrika.xml 

5、增加服务节点配置文件【metrika.xml】

cd /home/ckcluster/ck1/
cd clickhouse-server
vim config.d/metrika.xml

### 在metrika.xml中我们配置后期使用的clickhouse集群中创建分布式表时使用3个分片,每个分片有1个副本,配置如下:

    
        
            
                true
                
                    clickhouse-server01
                    19000
                
            
            
                true
                
                    clickhouse-server02
                    29000
                
            
            
                true
                
                    clickhouse-server03
                    39000
                
            
        
    
   
    
        
            zookeeper
            2181
        
    
    
        01 
        node1
    
    
        0.0.0.0/0
    
    
        
            10000000000
            0.01
            lz4
        
    

注意:需要在每台clickhouse节点上配置metrika.xml文件,并且修改每个节点的 macros配置名称。


    
        02 
        node2
    


    
        03 
        node3
    

6、启动服务

节点1

# clickhouse-server01
docker run --restart always -d \
--name clickhouse-server01 \
--ulimit nofile=262144:262144 \
--hostname clickhouse-server01 \
--network ckcluster \
-v /home/ckcluster/ck1/data/:/var/lib/clickhouse/ \
-v /home/ckcluster/ck1/clickhouse-server/:/etc/clickhouse-server/ \
-v /home/ckcluster/ck1/logs/:/var/log/clickhouse-server/ \
-p 19000:9000 -p 18123:8123 -p 19009:9009 \
nexus.***.com:8445/yandex/clickhouse-server:latest

节点2

# clickhouse-server02
docker run --restart always -d \
--name clickhouse-server02 \
--ulimit nofile=262144:262144 \
--hostname clickhouse-server02 \
--network ckcluster \
-v /home/ckcluster/ck2/data/:/var/lib/clickhouse/ \
-v /home/ckcluster/ck2/clickhouse-server/:/etc/clickhouse-server/ \
-v /home/ckcluster/ck2/logs/:/var/log/clickhouse-server/ \
-p 29000:9000 -p 28123:8123 -p 29009:9009 \
nexus.***.com:8445/yandex/clickhouse-server:latest

节点3

# clickhouse-server03
docker run --restart always -d \
--name clickhouse-server03 \
--ulimit nofile=262144:262144 \
--hostname clickhouse-server03 \
--network ckcluster \
-v /home/ckcluster/ck3/data/:/var/lib/clickhouse/ \
-v /home/ckcluster/ck3/clickhouse-server/:/etc/clickhouse-server/ \
-v /home/ckcluster/ck3/logs/:/var/log/clickhouse-server/ \
-p 39000:9000 -p 38123:8123 -p 39009:9009 \
nexus.***.com:8445/yandex/clickhouse-server:latest

7、验证

可以通过客户端工具DBeaver访问。

参考文章

Docker搭建Clickhouse集群_docker clickhouse_这学习真难的博客-CSDN博客

你可能感兴趣的:(docker,clickhouse,容器)