zk集群和clickhouse集群搭建

第一步搭建zk集群
stack.xml

version: '3.1'

services:
  zoo1:
    image: zookeeper
    restart: always
    hostname: zoo1
    ports:
      - 2191:2181
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181

  zoo2:
    image: zookeeper
    restart: always
    hostname: zoo2
    ports:
      - 2192:2181
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181

  zoo3:
    image: zookeeper
    restart: always
    hostname: zoo3
    ports:
      - 2193:2181
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181

docker-compose -f stack.yml up 开启服务
docker inspect zoo1 |grep ‘“IPAddress”’ 查看ip
docker exec -it myNginx /bin/bash 进入容器 再执行 zkServer.sh status 查看zk的状态
执行zkCli.sh 进入客户端【有时会出现没有正常启动的情况error】

第二步搭建clickhouse集群

 docker run -d --name ch-server1 --ulimit nofile=262144:262144 yandex/clickhouse-server

 docker run -d --name ch-server2 --ulimit nofile=262144:262144 yandex/clickhouse-server

 docker run -d --name ch-server3 --ulimit nofile=262144:262144 yandex/clickhouse-server

copy出里面的文件 本地修改 再上传过去

docker cp ch-server1:/etc/clickhouse-server/ ./etc/clickhouse-server/
docker cp ./etc/clickhouse-server/clickhouse-server/ ch-server1:/etc/
docker cp ./etc/clickhouse-server/clickhouse-server/ ch-server2:/etc/
docker cp ./etc/clickhouse-server/clickhouse-server/ ch-server3:/etc/

总配置config.xml




    
        
        trace
        /var/log/clickhouse-server/clickhouse-server.log
        /var/log/clickhouse-server/clickhouse-server.err.log
        1000M
        10
         
    
     
    8123
    9000

    
    

    
    
         
            
            /etc/clickhouse-server/server.crt
            /etc/clickhouse-server/server.key
            
            /etc/clickhouse-server/dhparam.pem
            none
            true
            true
            sslv2,sslv3
            true
        

         
            true
            true
            sslv2,sslv3
            true
            
            
                
                RejectCertificateHandler
            
        
    

    
    

    
    9009

    
    

    
    
    
    

    
    
    
    

    
    

    

    4096
    3

    
    100

    
    

    
    8589934592

    
    5368709120


    
    /var/lib/clickhouse/

    
    /var/lib/clickhouse/tmp/

    
    /var/lib/clickhouse/user_files/

    
    users.xml

    
    default

    
    

    
    default

    
    

    
    

    
    false

    
    
        

       

    


    

    
    


    
    

    Asia/Shanghai
    
    3600


    
    3600

    
    60

    
    
    


    
    
        
        system
        query_log
toYYYYMM(event_date) 7500
system query_thread_log
toYYYYMM(event_date) 7500
*_dictionary.xml /clickhouse/task_queue/ddl click_cost any 0 3600 86400 60 max 0 60 3600 300 86400 3600 /var/lib/clickhouse/format_schemas/ /etc/clickhouse-server/metrika.xml

集群配置metrika.xml



    
    
        

            
            
                true
                
                    172.17.0.3
                    9000
                    default
                    
                
                
                    172.17.0.4
                    9000
                    default
                    
                
                
                    172.17.0.5
                    9000
                    default
                    
                

            

            
           
                    9000
                    default
                    
                
            
             
                true
                
                    172.17.0.5
                    9000
                    default
                    
                
            -->


        
    


    
        172.17.0.5 
    


    
    
        
            172.16.9.139
            2191
        
        
            172.16.9.139   
            2192
        
         
            172.16.9.139   
            2193
        
    

    
        ::/0
    

    
    
        
            10000000000
            0.01
            lz4
        
    



进入容器 ch-server2

docker run -it \
--rm \
--add-host ch-server1:172.17.0.3 \
--add-host ch-server2:172.17.0.4 \
--add-host ch-server3:172.17.0.5 \
yandex/clickhouse-client \
--host ch-server2 \
--port 9000

查看集群状态

select * from system.clusters

zk集群和clickhouse集群搭建_第1张图片
创建表且插入数据


CREATE TABLE t_product
(
    `EventDate` DateTime,
    `CounterID` UInt32,
    `UserID` UInt32
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/t_product', '{replica}')
PARTITION BY toYYYYMM(EventDate)
ORDER BY (CounterID, EventDate, intHash32(UserID))
SAMPLE BY intHash32(UserID);

CREATE TABLE t_product_all AS t_product ENGINE = Distributed(cluster_1s_3r, default, t_product, rand());

insert into default.t_product (EventDate,CounterID,UserID)values('2002-10-01 00:00:00',1,1);
 
insert into default.t_product (EventDate,CounterID,UserID)values('2002-10-01 00:00:00',2,1);
insert into default.t_product (EventDate,CounterID,UserID)values('2002-10-01 00:00:00',3,1);


insert into default.t_product (EventDate,CounterID,UserID)values('2002-10-01 00:00:00',1,2);
insert into default.t_product (EventDate,CounterID,UserID)values('2002-10-01 00:00:00',1,3);

表2

CREATE TABLE default.image_label
(
    `label_id` UInt32,
    `label_name` String,
    `insert_time` Date
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/image_label', '{replica}', insert_time, (label_id, insert_time), 8192);

CREATE TABLE image_label_all AS image_label ENGINE = Distributed(cluster_1s_3r, default, image_label, rand());

insert into default.image_label (label_id,label_name,insert_time)values(1,'lable-1','2002-10-12');

insert into default.image_label (label_id,label_name,insert_time)values(2,'lable-2','2002-10-12');
insert into default.image_label (label_id,label_name,insert_time)values(3,'lable-3','2002-10-12');

insert into default.image_label (label_id,label_name,insert_time)values(8,'lable-8','2002-10-12');
insert into default.image_label (label_id,label_name,insert_time)values(9,'lable-9','2002-10-12');

最后查看 zk中的znode
zk集群和clickhouse集群搭建_第2张图片

你可能感兴趣的:(算法)