#!/bin/bash
# 原地址
original_address='xxx.xxx.xxx.xxx:xxxx'
# 目标地址
destination_address='xxx.xxx.xxx.xxx:xxxx'
# 集群密码
clusterPwd='pwd'
# 开始槽位
startSlot=16003
# 结束槽位
endSlot=16005
#处理一下原地址
originalHost=`echo $original_address | awk -F ':' '{print $1}'`
originalPort=`echo $original_address | awk -F ':' '{print $2}'`
#处理一下目标地址
destinationHost=`echo $destination_address | awk -F ':' '{print $1}'`
destinationPORT=`echo $destination_address | awk -F ':' '{print $2}'`
#获取原节点ID
originalNodeId=`redis-cli -h $originalHost -p $originalPort -a $clusterPwd cluster nodes | grep $original_address | awk '{print $1}'`
#获取目标节点ID
destinationNodeId=`redis-cli -h $originalHost -p $originalPort -a $clusterPwd cluster nodes | grep $destination_address | awk '{print $1}'`
echo '########## 开始迁移,迁移范围:'$startSlot'-'$endSlot' ##########'
for slot in `seq ${startSlot} ${endSlot}`
do
echo '########## 正在迁移:'${slot}' ##########'
redis-cli -h $originalHost -p $originalPort -a $clusterPwd cluster setslot ${slot} migrating $destinationNodeId
redis-cli -h $destinationHost -p $destinationPORT -a $clusterPwd cluster setslot ${slot} importing $originalNodeId
redis-cli -h $originalHost -p $originalPort -a $clusterPwd cluster setslot ${slot} node $destinationNodeId
echo '########## 迁移完成:'${slot}' ##########'
done
redis集群版批量迁移槽脚本
于 2024-04-19 09:59:50 首次发布