码迷,mamicode.com
首页 > 其他好文 > 详细

Redis cluster 4.0.9 迁槽不影响读写

时间:2020-07-03 19:15:33      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:byte   mys   random   设置   传输   elf   运行   query   source   

当前服务器的redis cluster节点信息如下:

[root@192-168-0-77 conf]# redis-cli -h 127.0.0.1 -p 2002 -c cluster slots | xargs  -n8 | awk {print $3":"$4"->"$6":"$7} | sort -nk2 -t : | uniq
127.0.0.1:2002->127.0.0.1:8008
127.0.0.1:3003->127.0.0.1:6006
127.0.0.1:5005->127.0.0.1:7007

添加实例:4004、9009,将 4004 设为 master

通过redis-benchmark工具对redis cluster进行无限循环读写

[root@192-168-0-77 conf]# redis-benchmark --help
-h <hostname>     Server hostname (default 127.0.0.1) (指定服务器主机名,默认:127.0.0.1-p <port>         Server port (default 6379)  (端口,默认:6379-s <socket>       Server socket (overrides host and port)  (指定服务器socket)
-a <password>     Password for Redis Auth  (密码)
-c <clients>      Number of parallel connections (default 50)  (并发连接数,默认:50并发)
-n <requests>     Total number of requests (default 100000)  (指定请求数,默认:100000-d <size>         Data size of SET/GET value in bytes (default 3)  (以字节形式指定SET/GET值,默认:3字节)
-k <boolean>      1=keep alive 0=reconnect (default 1)  
-r <keyspacelen>  Use random keys for SET/GET/INCR, random values for SADD  (SET/GET/INCR使用随机key,SADD使用随机值)
-P <numreq>       Pipeline <numreq> requests. Default 1 (no pipeline).  (通过管道传输,默认:1-e                If server replies with errors, show them on stdout.  (如果服务器返回错误,标准输出显示它们)
-q                Quiet. Just show query/sec values  (退出,仅显示query/sec)
--csv             Output in CSV format  (以CSV格式输出)
-l                Loop. Run the tests forever(循环,永久执行)
-t <tests>        Only run the comma separated list of tests. (仅运行以逗号分隔的测试命令结果,-t set,get)
-I                Idle mode. Just open N idle connections and wait. (Idle模式,仅打开N个连接并且等待)

进行压力测试,并添加新实例,进行槽迁移,在迁移槽过程中查看是否影响读写

[root@192-168-0-77 conf]# redis-benchmark -h 127.0.0.1 -p 2002 -c 100 -d 10 -r 1000000 -n 10000 -t set,get -l

[root@192-168-0-77 conf]# redis-benchmark -h 127.0.0.1 -p 3003 -c 100 -d 10 -r 1000000 -n 10000 -t set,get -l

[root@192-168-0-77 conf]# redis-benchmark -h 127.0.0.1 -p 5005 -c 100 -d 10 -r 1000000 -n 10000 -t set,get -l

启动4004、9009节点

[root@192-168-0-77 conf]# /usr/local/redis-4.0.9/bin/redis-server /u02/redis/4004/conf/redis_4004.conf

[root@192-168-0-77 conf]# /usr/local/redis-4.0.9/bin/redis-server /u02/redis/9009/conf/redis_9009.conf

添加主节点:

[root@192-168-0-77 conf]# redis-trib.rb add-node 127.0.0.1:4004 127.0.0.1:2002

查看4004节点的id:6da685506692810b47c55efa6cc4b4bc9f8ec027

[root@192-168-0-77 conf]# redis-cli -h 127.0.0.1 -p 2002 -c cluster nodes

添加4004的从节点9009:

[root@192-168-0-77 conf]# redis-trib.rb add-node --slave --master-id 6da685506692810b47c55efa6cc4b4bc9f8ec027 127.0.0.1:9009 127.0.0.1:2002

进行迁槽:(迁槽过程中通过monitor监控)

[root@192-168-0-77 conf]# redis-trib.rb reshard 127.0.0.12002
How many slots do you want to move (from 1 to 16384)? 1024         //设置slot数1024 
What is the receiving node ID? 6da685506692810b47c55efa6cc4b4bc9f8ec027     //新节点node id 
Please enter all the source node IDs. 
Type all to use all the nodes as source nodes for the hash slots. 
Type done once you entered all the source nodes IDs. 
Source node #1:all   //表示全部节点重新洗牌 
Do you want to proceed with the proposed reshard plan (yes/no)? yes   //确认重新分

这样分配槽数一定不均衡,再通过redis-trib.rb rebalance:

[root@192-168-0-77 conf]# redis-trib.rb rebalance 127.0.0.1:2002
*** No rebalancing needed! All nodes are within the 2.0% threshold。  误差在2%即可。

查看集群状态:

[root@192-168-0-77 conf]# redis-cli -h 127.0.0.1 -p 2002 -c cluster nodes
a6fa97a643ea1ae635f7e71537b330792e636422 127.0.0.1:7007@17007 slave b3966e1ed00ae4616077577f24eab2d5b13ace7a 0 1593771847000 26 connected
b3966e1ed00ae4616077577f24eab2d5b13ace7a 127.0.0.1:5005@15005 master - 0 1593771848000 26 connected 12288-16383
a4e133784359a1fbfff7a5d1c420fa6971cca592 127.0.0.1:9009@19009 slave 6da685506692810b47c55efa6cc4b4bc9f8ec027 0 1593771848000 27 connected
6da685506692810b47c55efa6cc4b4bc9f8ec027 127.0.0.1:4004@14004 master - 0 1593771846000 27 connected 0-4095
64538f2f5ec58bedb344e4b5f0ac540d9c09f506 127.0.0.1:8008@18008 slave e9883dd5b69227eb045ef85e0d95b5374c74b96a 0 1593771849452 24 connected
853a34de3d9c9347c5deac1127d3d3fe09788c2e 127.0.0.1:3003@13003 master - 0 1593771850453 25 connected 4096-8191
e9883dd5b69227eb045ef85e0d95b5374c74b96a 127.0.0.1:2002@12002 myself,master - 0 1593771847000 24 connected 8192-12287
0268ecaf869839aac9cab7b9d96c7fbac7df04d6 127.0.0.1:6006@16006 slave 853a34de3d9c9347c5deac1127d3d3fe09788c2e 0 1593771848449 25 connected

 

Redis cluster 4.0.9 迁槽不影响读写

标签:byte   mys   random   设置   传输   elf   运行   query   source   

原文地址:https://www.cnblogs.com/hankyoon/p/13232234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!