redis-集群安装(2)变两重冗余为三重

接上述安装文档(1)

添加slave节点
添加的slave节点配置在另一个服务器上,首先配置config文件
这里我们计算一下
本来是两重冗余,8个节点集群,也就是一共16个conf文件
现在是三重冗余,8个节点集群,也就是一共24个conf文件,现在要把他分配到4个主机上,也就是每个主机6个conf文件。也就是在原来的基础上增加两个conf文件
此时就是有顺序的填数独


主机1
[ root@T1 config]# vi redis-26381.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 26381
logfile "/tmp/redis-3.2.0/log/redis-26381.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-26381.aof"
dbfilename dump-26381.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-26381.conf
auto-aof-rewrite-percentage 80-100
[ root@T1 config]# vi redis-26384.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 26384
logfile "/tmp/redis-3.2.0/log/redis-26384.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-26384.aof"
dbfilename dump-26384.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-26384.conf
auto-aof-rewrite-percentage 80-100
~                                   
主机2
[ root@T2 config]# vi redis-26382.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 26382
logfile "/tmp/redis-3.2.0/log/redis-26382.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-26382.aof"
dbfilename dump-26382.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-26382.conf
auto-aof-rewrite-percentage 80-100
[ root@T2 config]# vi redis-26383.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 26383
logfile "/tmp/redis-3.2.0/log/redis-26383.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-26383.aof"
dbfilename dump-26383.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-26383.conf
auto-aof-rewrite-percentage 80-100
~                                      
主机3
[ root@T3 config]# vi redis-26379.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 26379
logfile "/tmp/redis-3.2.0/log/redis-26379.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-26379.aof"
dbfilename dump-26379.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-26379.conf
auto-aof-rewrite-percentage 80-100
[ root@T3 config]# vi redis-26386.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 26386
logfile "/tmp/redis-3.2.0/log/redis-26386.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-26386.aof"
dbfilename dump-26386.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-26386.conf
auto-aof-rewrite-percentage 80-100
主机4
[ root@T4 config]# vi redis-26380.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 26380
logfile "/tmp/redis-3.2.0/log/redis-26380.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-26380.aof"
dbfilename dump-26380.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-26380.conf
auto-aof-rewrite-percentage 80-100
[ root@T4 config]# vi redis-26385.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 26385
logfile "/tmp/redis-3.2.0/log/redis-26385.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-26385.aof"
dbfilename dump-26385.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-26385.conf
auto-aof-rewrite-percentage 80-100
启动冗余slave
主机1
[ root@T1 config]# redis-server redis-26381.conf 
[ root@T1 config]# redis-server redis-26384.conf 
主机2
[ root@T2 config]# redis-server redis-26382.conf 
[ root@T2 config]# redis-server redis-26383.conf 
主机3
[ root@T3 config]# redis-server redis-26379.conf 
[ root@T3 config]# redis-server redis-26386.conf 
主机4
[ root@T4 config]# redis-server redis-26380.conf 
[ root@T4 config]# redis-server redis-26385.conf 
增加冗余slave节点到集群
(注意:add-node的使用方法为new_host:new_port existing_host:existing_port,前面是新添加的节点信息,后面是已存在的节点信息)
增加了新的节点之后,这个新的节点可以成为主节点或者是从节点
[ root@T1 config]# redis-trib.rb add-node --slave 172.16.57.54:26381 172.16.57.56:6381
>>> Adding node 172.16.57.54:26381 to cluster 172.16.57.56:6381
>>> Performing Cluster Check (using node 172.16.57.56:6381)
M: a15269fef298a4e62fb10b3b1bd4ec7178760c34 172.16.57.56:6381
   slots:2048-4095 (2048 slots) master
   1 additional replica(s)
S: 2d832131cf4196c83557d0a153775ee63605ed90 172.16.57.57:16383
   slots: (0 slots) slave
   replicates a15269fef298a4e62fb10b3b1bd4ec7178760c34
S: 2f1c88c822a81d22ebeddc3a0816b62997a16dbe 172.16.57.55:16379
   slots: (0 slots) slave
   replicates 3ea77504768534438608cc8282409ad0380cc230
M: 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c 172.16.57.57:6382
   slots:0-2047 (2048 slots) master
   1 additional replica(s)
M: 450e56c837a409ac25b3aaae01fb561699654098 172.16.57.56:6385
   slots:10240-12287 (2048 slots) master
   1 additional replica(s)
S: 4d6ee6db3875c75fb0f44e1c93106da5b43bd5ba 172.16.57.56:16384
   slots: (0 slots) slave
   replicates be75716373aa05a16e890427386950e59c917d1f
S: b1ead2f5918bf1ceb71c6a34ddb57017dbffd7bd 172.16.57.55:16386
   slots: (0 slots) slave
   replicates adcdcd04c6d77a0dfa6fbacff68c668f42a727fb
M: c1137994639200525ef7f561ce291b3ce38079b3 172.16.57.55:6380
   slots:4096-6143 (2048 slots) master
   1 additional replica(s)
M: 3ea77504768534438608cc8282409ad0380cc230 172.16.57.54:6379
   slots:6144-8191 (2048 slots) master
   1 additional replica(s)
S: a94b11d778ffd22c3643ee0debcb0e8d52cae037 172.16.57.54:16385
   slots: (0 slots) slave
   replicates c1137994639200525ef7f561ce291b3ce38079b3
S: e9b7be308399f30dd25f0d63b4befa536e91fe60 172.16.57.57:16381
   slots: (0 slots) slave
   replicates 450e56c837a409ac25b3aaae01fb561699654098
M: 46f9543f054435dea90aded227f5a53a1383dee2 172.16.57.55:6384
   slots:12288-14335 (2048 slots) master
   1 additional replica(s)
M: be75716373aa05a16e890427386950e59c917d1f 172.16.57.57:6386
   slots:8192-10239 (2048 slots) master
   1 additional replica(s)
M: adcdcd04c6d77a0dfa6fbacff68c668f42a727fb 172.16.57.54:6383
   slots:14336-16383 (2048 slots) master
   1 additional replica(s)
S: ec8ea752576da5eea8bc3934544826d8730e1dfd 172.16.57.56:16380
   slots: (0 slots) slave
   replicates 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c
S: 2c3b29c266cdd2796314f785891bf7dbf39c1764 172.16.57.54:16382
   slots: (0 slots) slave
   replicates 46f9543f054435dea90aded227f5a53a1383dee2
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Automatically selected master 172.16.57.56:6381
>>> Send CLUSTER MEET to node 172.16.57.54:26381 to make it join the cluster.
Waiting for the cluster to join.........
>>> Configure node as replica of 172.16.57.56:6381.
[OK] New node added correctly.
[ root@T1 config]# redis-trib.rb add-node --slave 172.16.57.54:26384 172.16.57.55:6384
主机2
[ root@T2 config]# redis-trib.rb add-node --slave 172.16.57.55:26382 172.16.57.57:6382
[ root@T2 config]# redis-trib.rb add-node --slave 172.16.57.55:26383 172.16.57.54:6383
主机3
[ root@T3 config]# redis-trib.rb add-node --slave 172.16.57.56:26379 172.16.57.54:6379、
[ root@T3 config]# redis-trib.rb add-node --slave 172.16.57.56:26386 172.16.57.57:6386
主机4
[ root@T4 config]# redis-trib.rb add-node --slave 172.16.57.57:26380 172.16.57.55:6380
[ root@T4 config]# redis-trib.rb add-node --slave 172.16.57.57:26385 172.16.57.56:6385
查看集群情况
[ root@T1 config]# redis-cli -h 172.16.57.54 -p 6379
172.16.57.54:6379> cluster nodes
2c3b29c266cdd2796314f785891bf7dbf39c1764 172.16.57.54:16382 slave 46f9543f054435dea90aded227f5a53a1383dee2 0 1463739296841 15 connected
2d832131cf4196c83557d0a153775ee63605ed90 172.16.57.57:16383 slave a15269fef298a4e62fb10b3b1bd4ec7178760c34 0 1463739294838 10 connected
a94b11d778ffd22c3643ee0debcb0e8d52cae037 172.16.57.54:16385 slave c1137994639200525ef7f561ce291b3ce38079b3 0 1463739297844 14 connected
3ad4c7bba432e075d5508011843396eb964fced7 172.16.57.57:26385 slave 450e56c837a409ac25b3aaae01fb561699654098 0 1463739297844 6 connected
926e094caebf5f63bb7f06be8d8973f618e8621e 172.16.57.56:26386 slave be75716373aa05a16e890427386950e59c917d1f 0 1463739297844 8 connected
7eeb792ba02384f2a7f77c15ba24a64b5aa31c48 172.16.57.56:26379 slave 3ea77504768534438608cc8282409ad0380cc230 0 1463739299846 1 connected
2fe7b552ad5a5bf21a1ce8a3383c6ca0d2ed4e04 172.16.57.57:26380 slave c1137994639200525ef7f561ce291b3ce38079b3 0 1463739295339 3 connected
0a2445ba6f45192ee69db944bbaed06922df1e15 172.16.57.55:26382 slave 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c 0 1463739296842 7 connected
4d6ee6db3875c75fb0f44e1c93106da5b43bd5ba 172.16.57.56:16384 slave be75716373aa05a16e890427386950e59c917d1f 0 1463739298846 12 connected
853d26575f80de4ff21a48b1946075a338a1cee2 172.16.57.55:26383 slave adcdcd04c6d77a0dfa6fbacff68c668f42a727fb 0 1463739297341 2 connected
b1ead2f5918bf1ceb71c6a34ddb57017dbffd7bd 172.16.57.55:16386 slave adcdcd04c6d77a0dfa6fbacff68c668f42a727fb 0 1463739298846 16 connected
3ea77504768534438608cc8282409ad0380cc230 172.16.57.54:6379 myself,master - 0 0 1 connected 6144-8191
e2440e0cb2205adad154dc7d00d4213cc4e430f0 172.16.57.54:26381 slave a15269fef298a4e62fb10b3b1bd4ec7178760c34 0 1463739296340 5 connected
2f1c88c822a81d22ebeddc3a0816b62997a16dbe 172.16.57.55:16379 slave 3ea77504768534438608cc8282409ad0380cc230 0 1463739300850 9 connected
be75716373aa05a16e890427386950e59c917d1f 172.16.57.57:6386 master - 0 1463739295841 8 connected 8192-10239
69cc0aff83e9743a2cb558f8453bfb04b1d6c6f2 172.16.57.54:26384 slave 46f9543f054435dea90aded227f5a53a1383dee2 0 1463739299846 4 connected
a15269fef298a4e62fb10b3b1bd4ec7178760c34 172.16.57.56:6381 master - 0 1463739294838 5 connected 2048-4095
46f9543f054435dea90aded227f5a53a1383dee2 172.16.57.55:6384 master - 0 1463739301851 4 connected 12288-14335
c1137994639200525ef7f561ce291b3ce38079b3 172.16.57.55:6380 master - 0 1463739301349 3 connected 4096-6143
adcdcd04c6d77a0dfa6fbacff68c668f42a727fb 172.16.57.54:6383 master - 0 1463739299345 2 connected 14336-16383
450e56c837a409ac25b3aaae01fb561699654098 172.16.57.56:6385 master - 0 1463739299345 6 connected 10240-12287
ec8ea752576da5eea8bc3934544826d8730e1dfd 172.16.57.56:16380 slave 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c 0 1463739299345 11 connected
e9b7be308399f30dd25f0d63b4befa536e91fe60 172.16.57.57:16381 slave 450e56c837a409ac25b3aaae01fb561699654098 0 1463739295841 13 connected
27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c 172.16.57.57:6382 master - 0 1463739299345 7 connected 0-2047
数据分片
加入新的节点后,需要将其他的节点中的hash slot移动到新的节点中,以达到负载均衡的效果,指定集群中其中一个节点的地址
[ root@T1 config]# redis-trib.rb reshard 172.16.57.54:6379
How many slots do you want to move (from 1 to 16384)?4096  --16384/4=4096.master建议为基数
What is the receiving node ID? 89be535ff56586dcec56f14122add80d89a57bb3  --新加的主节点ID注意必须是主节点
Source node #1:all  --从所有其他master节点均匀把slot移动到新加的主节点
Do you want to proceed with the proposed reshard plan (yes/no)? yes
多余的冗余步骤略,至此增加整个集群冗余度完成







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值