[root@master02 redis]# cat forget-node.sh#!/bin/bashset -e#echo "usage: host port"nodes_addrs=$(redis-cli -a $3 -h $1 -p $2 cluster nodes|grep -v handshake| awk '{print $2}')echo " -------------normal cluster nodes -----------------"echo " $nodes_addrs "echo " --------------------------------------------"for addr in ${nodes_addrs[@]}; dohost=${addr%:*}port=${addr#*:}del_nodeids=$(redis-cli -a $3 -h $host -p $port cluster nodes|grep -E 'handshake|fail'| awk '{print $1}')for nodeid in ${del_nodeids[@]}; doecho " -------------delete nodes info -----------------------"echo "delete from host: $host $port, delete node id: $nodeid "echo " ------------------------------------------------------"redis-cli -a $3 -h $host -p $port cluster forget $nodeiddonedone
例如:
# ./forget-node.sh 172.24.130.117 6379 123456Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.-------------normal cluster nodes -----------------172.24.130.215:6379@16379172.24.143.110:6379@16379172.24.131.15:6379@16379172.24.130.14:6379@16379172.24.130.117:6379@16379172.24.140.45:6379@16379--------------------------------------------Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.-------------delete nodes info -----------------------delete from host: 172.24.130.215 6379@16379, delete node id: 81c855e1f803cccdb35b4dcead7fc9b990d61e52-------------------------------------------------------------------delete nodes info -----------------------delete from host: 172.24.130.215 6379@16379, delete node id: d0c2432d276f8b16cf1b79130d5904823bd7d7f4------------------------------------------------------Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.-------------delete nodes info -----------------------delete from host: 172.24.143.110 6379@16379, delete node id: 453a20280a47c1f436b65eab058d315343241c16-------------------------------------------------------------------delete nodes info -----------------------delete from host: 172.24.143.110 6379@16379, delete node id: e0ab7987585ff947eb0329a7689e168ff97ea71f------------------------------------------------------Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.-------------delete nodes info -----------------------delete from host: 172.24.131.15 6379@16379, delete node id: d0c2432d276f8b16cf1b79130d5904823bd7d7f4-------------------------------------------------------------------delete nodes info -----------------------delete from host: 172.24.131.15 6379@16379, delete node id: 81c855e1f803cccdb35b4dcead7fc9b990d61e52------------------------------------------------------Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.-------------delete nodes info -----------------------delete from host: 172.24.130.14 6379@16379, delete node id: 4220aee6a9125d6ea7b84eb3cb0b1ea0a9a34dbb-------------------------------------------------------------------delete nodes info -----------------------delete from host: 172.24.130.14 6379@16379, delete node id: 1b9647dd197967542a78b0b35a10adf8bad59b6a------------------------------------------------------Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.-------------delete nodes info -----------------------delete from host: 172.24.130.117 6379@16379, delete node id: 3113d8e188c224a71e0dcbfd2b528b4ac1f5fe62-------------------------------------------------------------------delete nodes info -----------------------delete from host: 172.24.130.117 6379@16379, delete node id: 5fa713770dce44741fe1f1a014d198953a511c3c------------------------------------------------------Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.-------------delete nodes info -----------------------delete from host: 172.24.140.45 6379@16379, delete node id: 7e3d00a07e15a9ef9326186b2f300c93526a421d-------------------------------------------------------------------delete nodes info -----------------------delete from host: 172.24.140.45 6379@16379, delete node id: 5dc88c446fa343f97811973f56d79b906d7a1402------------------------------------------------------
