1. [root@master02 redis]# cat forget-node.sh
    2. #!/bin/bash
    3. set -e
    4. #echo "usage: host port"
    5. nodes_addrs=$(redis-cli -a $3 -h $1 -p $2 cluster nodes|grep -v handshake| awk '{print $2}')
    6. echo " -------------normal cluster nodes -----------------"
    7. echo " $nodes_addrs "
    8. echo " --------------------------------------------"
    9. for addr in ${nodes_addrs[@]}; do
    10. host=${addr%:*}
    11. port=${addr#*:}
    12. del_nodeids=$(redis-cli -a $3 -h $host -p $port cluster nodes|grep -E 'handshake|fail'| awk '{print $1}')
    13. for nodeid in ${del_nodeids[@]}; do
    14. echo " -------------delete nodes info -----------------------"
    15. echo "delete from host: $host $port, delete node id: $nodeid "
    16. echo " ------------------------------------------------------"
    17. redis-cli -a $3 -h $host -p $port cluster forget $nodeid
    18. done
    19. done

    例如:

    1. # ./forget-node.sh 172.24.130.117 6379 123456
    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    3. -------------normal cluster nodes -----------------
    4. 172.24.130.215:6379@16379
    5. 172.24.143.110:6379@16379
    6. 172.24.131.15:6379@16379
    7. 172.24.130.14:6379@16379
    8. 172.24.130.117:6379@16379
    9. 172.24.140.45:6379@16379
    10. --------------------------------------------
    11. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    12. -------------delete nodes info -----------------------
    13. delete from host: 172.24.130.215 6379@16379, delete node id: 81c855e1f803cccdb35b4dcead7fc9b990d61e52
    14. ------------------------------------------------------
    15. -------------delete nodes info -----------------------
    16. delete from host: 172.24.130.215 6379@16379, delete node id: d0c2432d276f8b16cf1b79130d5904823bd7d7f4
    17. ------------------------------------------------------
    18. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    19. -------------delete nodes info -----------------------
    20. delete from host: 172.24.143.110 6379@16379, delete node id: 453a20280a47c1f436b65eab058d315343241c16
    21. ------------------------------------------------------
    22. -------------delete nodes info -----------------------
    23. delete from host: 172.24.143.110 6379@16379, delete node id: e0ab7987585ff947eb0329a7689e168ff97ea71f
    24. ------------------------------------------------------
    25. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    26. -------------delete nodes info -----------------------
    27. delete from host: 172.24.131.15 6379@16379, delete node id: d0c2432d276f8b16cf1b79130d5904823bd7d7f4
    28. ------------------------------------------------------
    29. -------------delete nodes info -----------------------
    30. delete from host: 172.24.131.15 6379@16379, delete node id: 81c855e1f803cccdb35b4dcead7fc9b990d61e52
    31. ------------------------------------------------------
    32. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    33. -------------delete nodes info -----------------------
    34. delete from host: 172.24.130.14 6379@16379, delete node id: 4220aee6a9125d6ea7b84eb3cb0b1ea0a9a34dbb
    35. ------------------------------------------------------
    36. -------------delete nodes info -----------------------
    37. delete from host: 172.24.130.14 6379@16379, delete node id: 1b9647dd197967542a78b0b35a10adf8bad59b6a
    38. ------------------------------------------------------
    39. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    40. -------------delete nodes info -----------------------
    41. delete from host: 172.24.130.117 6379@16379, delete node id: 3113d8e188c224a71e0dcbfd2b528b4ac1f5fe62
    42. ------------------------------------------------------
    43. -------------delete nodes info -----------------------
    44. delete from host: 172.24.130.117 6379@16379, delete node id: 5fa713770dce44741fe1f1a014d198953a511c3c
    45. ------------------------------------------------------
    46. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    47. -------------delete nodes info -----------------------
    48. delete from host: 172.24.140.45 6379@16379, delete node id: 7e3d00a07e15a9ef9326186b2f300c93526a421d
    49. ------------------------------------------------------
    50. -------------delete nodes info -----------------------
    51. delete from host: 172.24.140.45 6379@16379, delete node id: 5dc88c446fa343f97811973f56d79b906d7a1402
    52. ------------------------------------------------------

    参考:
    Redis异常02-redis5.0.5 cluster节点handshake状态问题