redis数据迁移
作者:互联网
通过启动单实例,写入测试命令然后将单实例的数据迁移到集群中去。
一:启动单实例并写入测试命令
systemctl start redis
for i in {1..100};do redis-cli set key_${i} v_${i} && echo "${i} is ok";done
二:查看集群中有多少个key,有的话先全部删除
redis-cli --cluster info 10.0.0.101:6380
redis-cli -h 10.0.0.101 -p 6380 flushall
redis-cli -h 10.0.0.102 -p 6380 flushall
redis-cli -h 10.0.0.103 -p 6380 flushall
redis-cli -h 10.0.0.101 -p 6390 flushall
redis-cli --cluster info 10.0.0.101:6380
#不加copy参数就相当于move,单节点数据迁移完后老数据就被删除了
redis-cli --cluster import 10.0.0.101:6380 --cluster-from 10.0.0.101:6379
redis-cli
redis-cli --cluster info 10.0.0.101:6380
#加了copy参数后相当于cp,单节点数据迁移完后老数据还会保留
redis-cli
MSET k111 v111 k222 v222 k333 v333 k444 v444
redis-cli --cluster import 10.0.0.101:6380 --cluster-from 10.0.0.101:6379 --cluster-copy
#添加replace参数,迁移时候会覆盖掉同名的数据,对集群新增加的数据不受影响
redis-cli
set k111 v11
redis-cli --cluster import 10.0.0.101:6380 --cluster-from 10.0.0.101:6379 --cluster-copy --cluster-replace
redis-cli -c -h 10.0.0.101 -p 6380
get k111
补充:多实例运维脚本
cat > redis_shell.sh << 'EOF'
#!/bin/bash
USAG(){
echo "sh $0 {start|stop|restart|login|ps|tail} PORT"
}
if [ "$#" = 1 ]
then
REDIS_PORT='6379'
elif
[ "$#" = 2 -a -z "$(echo "$2"|sed 's#[0-9]##g')" ]
then
REDIS_PORT="$2"
else
USAG
exit 0
fi
REDIS_IP=$(hostname -I|awk '{print $1}')
PATH_DIR=/opt/redis_${REDIS_PORT}/
PATH_CONF=/opt/redis_${REDIS_PORT}/conf/redis_${REDIS_PORT}.conf
PATH_LOG=/opt/redis_${REDIS_PORT}/logs/redis_${REDIS_PORT}.log
CMD_START(){
redis-server ${PATH_CONF}
}
CMD_SHUTDOWN(){
redis-cli -c -h ${REDIS_IP} -p ${REDIS_PORT} shutdown
}
CMD_LOGIN(){
redis-cli -c -h ${REDIS_IP} -p ${REDIS_PORT}
}
CMD_PS(){
ps -ef|grep redis
}
CMD_TAIL(){
tail -f ${PATH_LOG}
}
case $1 in
start)
CMD_START
CMD_PS
;;
stop)
CMD_SHUTDOWN
CMD_PS
;;
restart)
CMD_START
CMD_SHUTDOWN
CMD_PS
;;
login)
CMD_LOGIN
;;
ps)
CMD_PS
;;
tail)
CMD_TAIL
;;
*)
USAG
esac
EOF
标签:10.0,cli,0.101,REDIS,CMD,redis,迁移,数据 来源: https://www.cnblogs.com/olddriver-t/p/15007930.html