Redis Cluster集群搭建

redis cluster集群构建

10.16.76.144 6000
10.16.76.144 6001
10.16.76.144 6002

集群密码:abcdefg

配置主节点

1
2
3
4
5
6
10.16.76.144 6000
cluster meet 10.16.76.144 6001
cluster meet 10.16.76.144 6002
cluster nodes
cluster info

分配槽位

node1分配:0~5461
node2分配:5462~10922
node3分配:10923~16383

分配脚本addslots.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
REDIS_CLI=`which redis-cli`
REDIS_PASS=''
#node1
n=0
for ((i=n;i<=5461;i++))
do
$REDIS-CLI -h 10.16.76.144 -p 6000 -a $REDIS_PASS CLUSTER ADDSLOTS $i
done
#node2
n=5462
for ((i=n;i<=10922;i++))
do
$REDIS-CLI -h 10.16.76.144 -p 6001 -a $REDIS_PASS CLUSTER ADDSLOTS $i
done
#node3
#!/bin/bash
n=10923
for ((i=n;i<=16383;i++))
do
$REDIS-CLI -h 10.16.76.144 -p 6002 -a $REDIS_PASS CLUSTER ADDSLOTS $i
done

redis集群动态添加密码

1
2
3
4
5
config rewrite 写入配置
for i in {6000..6002}; do echo $i;done
for i in {6000..6002}; do echo $i; redis-cli -c -h 10.16.76.144 -p $i config set requirepass abcdefg ;done

redis cluster常用命令

1
2
查看key所在slot
cluster keyslot key_name