【Clickhouse】CLICKHOUSE容器化相关对每自定义节点数量进行1次分片

前言

将clickhouse容器化后,该脚本将对每2节点进行1次分片。每增加2节点只需要再该容器的中的环境变量中增加新节点即可。
自定义节点数量可以参考该脚本内容SHARD_LIST_STR=${SHARD_LIST:-"localhost:9000,localhost1:9000|localhost2:9000,localhost3:9000"}

dockerfile CMD脚本命令截取

#!/bin/sh
set -ex
SHARD_LIST_STR=${SHARD_LIST:-"localhost:9000,localhost1:9000|localhost2:9000,localhost3:9000"}
ZK_SERVER=${ZK_SERVER:-"localhost:9000,localhost1:9000"}
LOG_LEVEL=${LOG_LEVEL:-"trace"}
CH_USER=${CH_USER:-"default"}
CH_AUTH=${CH_AUTH:-"default"}
CURRENT_NODE=${CURRENT_NODE:-"localhost"}
TARGET_FILE=/etc/metrika.xml
SHARD_NODE=${SHARD_NODE:-"shard"}

cp -r /etc/clickhouse_bak/metrika.xml  /etc/
cp -r /etc/clickhouse_bak/config.xml /etc/clickhouse-server/
cp -r /etc/clickhouse_bak/users.xml /etc/clickhouse-server/

sed -i "s/CURRENT_NODE/${CURRENT_NODE}/g" ${TARGET_FILE} 
sed -i "s/SHARD_NODE/${SHARD_NODE}/g" ${TARGET_FILE} 
sed -i "s/CH_USER/${CH_USER}/g" /etc/clickhouse-server/users.xml
sed -i "s/CH_AUTH/${CH_AUTH}/g" /etc/clickhouse-server/users.xml
sed -i "s/SYS:LOG_LEVEL/$LOG_LEVEL/g" /etc/clickhouse-server/config.xml


SHARD_LIST=${SHARD_LIST_STR//|/ }
counts=0
for SHARD in $SHARD_LIST
do
    echo  SHARD $SHARD
    shard="<shard>\n<internal_replication>true</internal_replication>\n"
    REPLICA=${SHARD//,/ }
    for IP_PORT_STR in $REPLICA
    do
        let counts+=1
        shard=$shard"<replica>\n"
        IP_PORT_STR=(${IP_PORT_STR//:/ })
        shard=$shard"<host>${IP_PORT_STR[0]}<\/host>\n<port>${IP_PORT_STR[1]}<\/port>\n<user>${CH_USER}</user>\n<password>${CH_AUTH}</password>\n<\/replica>\n"
    done
    shard=$shard"<\/shard>\n"
    shard_2=$(echo $shard |sed 's/<internal_replication>true<\/internal_replication>//g')

    #if [ ${counts} -ge  1 ] ; then
    #shard=$shard"\n$shard_2"
    #shard=$shard"$shard"
    #fi 
    sed -i "/<\/ch_cluster>/i$shard" $TARGET_FILE
done


ZK_SERVER_LIST=${ZK_SERVERS//,/ }
ind=0
for ZK_SERVER_STR in $ZK_SERVER_LIST
do  
    let ind+=1
    node="<node index=\"${ind}\">"
    ZK_SERVER_A=(${ZK_SERVER_STR//:/ })
    node=$node"<host>${ZK_SERVER_A[0]}<\/host><port>${ZK_SERVER_A[1]}<\/port><\/node>"
    sed -i "/<\/zookeeper-servers>/i$node" $TARGET_FILE
done

#/etc/init.d/clickhouse-server start
#/usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/config.xml >/dev/null
/usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/config.xml 
    res_code=$?
    if [ $res_code -ne 0 ]; then
        echo "start failed pls less +F /var/log/clickhouse-server/clickhouse-server.log"
        exit 404
    else
        echo "start success pls less +F /var/log/clickhouse-server/clickhouse-server.log"
    fi

Docker-compose clickhouse node 1 shard1 env截取

      environment:
          - CH_USER=root
          - CH_AUTH=root
          - SHARD_NODE=01
          - CURRENT_NODE=ch.1
          - SHARD_LIST=ch.1:9000,ch.2:9000|ch.3:9000,ch.4:9000
          - ZK_SERVERS=zk.1:12181,zk.2:12181,zk.3:12181

Docker-compose clickhouse node 3 shard2 env截取

      environment:
          - CH_USER=root
          - CH_AUTH=root
          - SHARD_NODE=02
          - CURRENT_NODE=ch.3
          - SHARD_LIST=ch.1:9000,ch.2:9000|ch.3:9000,ch.4:9000
          - ZK_SERVERS=zk.1:12181,zk.2:12181,zk.3:12181

新增node 5 6 shard 3 env 截取

新增的情况下,原节点的env也都需要添加新增的节点

      environment:
          - CH_USER=root
          - CH_AUTH=root
          - SHARD_NODE=03
          - CURRENT_NODE=ch.5
          - SHARD_LIST=ch.1:9000,ch.2:9000|ch.3:9000,ch.4:9000|ch.5:9000,ch.6:9000
          - ZK_SERVERS=zk.1:12181,zk.2:12181,zk.3:12181
      environment:
          - CH_USER=root
          - CH_AUTH=root
          - SHARD_NODE=03
          - CURRENT_NODE=ch.6
          - SHARD_LIST=ch.1:9000,ch.2:9000|ch.3:9000,ch.4:9000|ch.5:9000,ch.6:9000
          - ZK_SERVERS=zk.1:12181,zk.2:12181,zk.3:12181
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大锅霍皮久

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值