栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

tendisplus01-创建集群脚本

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

tendisplus01-创建集群脚本

tendisplus集群是腾讯开源的kv存储中间件,很好用,就是创建集群时需要一步步创建,下面的这个脚本就是解决了我们在创建集群时繁琐的执行步骤

1.创建6个tendisplus节点

127.0.0.1:6379
127.0.0.2:6379
127.0.0.3:6379
127.0.0.4:6379
127.0.0.5:6379
127.0.0.6:6379

2. ./tendisplus-build.sh "127.0.0.1:3679 127.0.0.2:3679 127.0.0.3:6379" "127.0.0.4:6379 127.0.0.5:6379 127.0.0.6:6379" a12345 3即可创建三主三从集群

3.参数含义
第一个参数为主节点
第二个参数为从节点
第三个参数为密码
第4个参数为集群大小

#/bin/sh
#usage: ./tendis-build.sh "127.0.0.1:30000 127.0.0.1:30001 127.0.0.1:30002" "127.0.0.1:30003 127.0.0.1:30004 127.0.0.1:3005" a12345 3
#The shell create one tendis cluster of one replica
#MASTERS=(127.0.0.1:30000 127.0.0.1:30001 127.0.0.1:30002)
#SLAVES=(127.0.0.1:30003 127.0.0.1:30004 127.0.0.1:30005)
#PASSWORD=aaaa
#SIZE=3
MASTERS=($1)
SLAVES=($2)
PASSWORD=$3
SIZE=$4
slot_num=$((16384 / ${SIZE}))
first_instance=${MASTERS[0]}
first_instance_arr=(${first_instance//:/ })
first_ip=${first_instance_arr[0]}
first_port=${first_instance_arr[1]}

#meet each other
for value in ${MASTERS[@]};do 
     value_arr=(${value//:/ })
     ip=${value_arr[0]}
     port=${value_arr[1]}
     redis-cli -h ${first_ip} -p ${first_port} -a ${PASSWORD} cluster meet ${ip} ${port}
done
for value in ${SLAVES[@]};do 
     value_arr=(${value//:/ })
     ip=${value_arr[0]}
     port=${value_arr[1]}
     redis-cli -h ${first_ip} -p ${first_port} -a ${PASSWORD} cluster meet ${ip} ${port}
done
echo "cluster meet done......"
sleep 2
#add slots
for (( i = 0; i < ${SIZE}; i++ )); do
        instance=${MASTERS[${i}]}
        instance_arr=(${instance//:/ })
        ip=${instance_arr[0]}
        port=${instance_arr[1]}
        redis-cli -h ${ip} -p ${port} -a ${PASSWORD} cluster addslots {$((${i}*${slot_num}))..$((${slot_num}*(${i}+1)-1))}
done
last_instance=${MASTERS[$((${SIZE} - 1 ))]}
last_instance_arr=(${last_instance//:/ })
last_ip=${last_instance_arr[0]}
last_port=${last_instance_arr[1]}
redis-cli -h ${last_ip} -p ${last_port} -a ${PASSWORD} cluster addslots 16383
echo "add slots done......."
sleep 2
#add replica
for (( i = 0; i < ${SIZE}; i++ )); do
        instance=${MASTERS[${i}]}
        instance_arr=(${instance//:/ })
        ip=${instance_arr[0]}
        port=${instance_arr[1]}
        
        slave_instance=${SLAVES[${i}]}
        slave_instance_arr=(${slave_instance//:/ })
        slave_ip=${slave_instance_arr[0]}
        slave_port=${slave_instance_arr[1]}
        uuid=$(redis-cli -h ${first_ip} -p ${first_port}  -a ${PASSWORD} cluster nodes | grep ${ip}:${port} | awk '{print $1}')
        redis-cli -h ${slave_ip} -p ${slave_port} -a ${PASSWORD} cluster replicate ${uuid}
done
echo "cluster build done.."
sleep 2
redis-cli -h ${first_ip} -p ${first_port}  -a ${PASSWORD} cluster nodes

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/605994.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号