介绍
小编给大家分享一下怎么清理复述,集群的所有数据,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!
1。背景:生产测试后复述中产生大量数据
生产前需要清理里德集群中的数据,
你看有很多关键呢:
使用工具
使用命令,查看是否有数据:
keys *
2。清理步骤
2.1任意登录一台复述,机器
执行下面脚本:
clear_redis_cluster.sh 10.1.33.101:8001 复述,
执行日志如下:
Clearing 10.1.33.112:8028 … Background append  only file  rewriting 开始 READONLY 你停下来# 39;t  write against a read only 只复制品; Clearing 10.1.33.110:8026 … Background append  only file  rewriting 开始 READONLY 你停下来# 39;t  write against a read only 只复制品; Clearing 10.1.33.111:8027 … Background append  only file  rewriting 开始 READONLY 你停下来# 39;t  write against a read only 只复制品; Clearing 10.1.33.107:8007 … Background append  only file  rewriting 开始 好吧 Clearing 10.1.33.108:8024 … Background append  only file  rewriting 开始 READONLY 你停下来# 39;t  write against a read only 只复制品; Clearing 10.1.33.104:8020 … Background append  only file  rewriting 开始 READONLY 你停下来# 39;t  write against a read only 只复制品; Clearing 10.1.33.114:8014 … Background append  only file  rewriting 开始 好吧 Clearing 10.1.33.109:8025 … Background append  only file  rewriting 开始 READONLY 你停下来# 39;t  write against a read only 只复制品; Clearing 10.1.33.105:8005 … Background append  only file  rewriting 开始 好吧 Clearing 10.1.33.108:8008 … Background append  only file  rewriting 开始 好的clear_redis_cluster
2.2。sh内容
# !/bin/bash #,Writed by  yijian 提醒2018/8/20 #,Batch 用clear all nodes using FLUSHALL 命令 #,用来清空一个复述,集群中的所有数据,要求,FLUSHALL 命令可用, #,如果在,redis.conf 中使用,rename 改名了,FLUSHALL,则不能执行本脚本。 #,可带两个参数: #,1)参数1,集群中的任一可用节点(必须) #,2)连接复述的密码(设置了密码才需要) REDIS_CLI=$ {REDIS_CLI: -redis-cli} REDIS_IP=$ {REDIS_IP: 127.0.0.1} REDIS_PORT=$ {REDIS_PORT: -6379} #,显示用法函数 function 使用() { echo “用法:才能,clear_redis_cluster.sh a_redis_node_of_cluster redis_password" echo 才能“例二:,clear_redis_cluster.sh & # 39; 127.0.0.1:6379& # 39;“ echo 才能“Example2:, clear_redis_cluster.sh & # 39; 127.0.0.1:6379& # 39;, & # 39; 123456 & # 39;“ } #,检查参数个数 if test $ #, -lt 1, -o $ #, -gt 2,然后 ,使用 exit 才能;1 fi #,第一个参数为集群中的节点, “REDIS_NODE=?美元 #,第二个参数为密码 REDIS_PASSWORD=?“ if test $ #, -ge 2,然后 REDIS_PASSWORD才能=?美元, fi #,取得IP和端口 eval $ (echo “REDIS_NODE"美元;,|,awk - f [\:], & # 39; {, printf (“REDIS_IP=% s \ nREDIS_PORT=% s \ n", $ 1, $ 2),} & # 39;) if test  -z “REDIS_IP"美元;,-o -z “REDIS_PORT"美元;;然后 echo 才能“Parameter 错误:,\“REDIS_NODE美元\”!” ,使用 exit 才能;1 fi #,确保redis-cli可用 echo “Checking  \ ' redis-cli \ ',……“ which “REDIS_CLI"美元,祝辞,/dev/null 2祝辞,1 if test $ ? -ne 0;,然后 echo 才能“Command  \“redis-cli \”, is not exists 或是not 可执行!” echo 才能;“你还要set environment variable \“REDIS_CLI \”,用point 用,redis-cli !” echo 才能“的例子:,export REDIS_CLI=/usr/地方/bin/redis-cli" exit 才能;1 fi if test  -z “REDIS_PASSWORD"美元;;然后 null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null怎么清理复述,集群的所有数据