redis-5.0.5的内置集群部署

前面介绍过redis4.0.11版本的内置集群部署,这里省略之前的操作,我们直接看创建集群的指令。

在redis4.x版本之前还需要安装ruby,yum安装的ruby版本都是2.0的,不符合要求,升级ruby还有点麻烦,并用redis-trib指令进行创建集群

redis5.0版本后,使用redis-cli 语法,避免了安装和升级ruby,操作简单。

配置文件:

bind 192.168.22.33
protected-mode yes
port 7000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /opt/redis-5.0.5/pid/redis7000.pid
loglevel notice
logfile "/opt/redis-5.0.5/log/redis7000.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump7000.rdb
dir /opt/redis-5.0.5/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
maxclients 10000
maxmemory 5gb
maxmemory-policy volatile-lfu
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 15000
cluster-require-full-coverage no
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

复制为6份,并启动,启动成功如下所是:

[root@wyl redis-5.0.5]# ps -ef|grep redis
root      60838      1  0 15:42 ?        00:00:00 ./bin/redis-server 192.168.22.33:7000 [cluster]
root      64061      1  0 15:46 ?        00:00:00 ./bin/redis-server 192.168.22.33:7001 [cluster]
root      64141      1  0 15:46 ?        00:00:00 ./bin/redis-server 192.168.22.33:7002 [cluster]
root      64147      1  0 15:46 ?        00:00:00 ./bin/redis-server 192.168.22.33:7003 [cluster]
root      64187      1  0 15:46 ?        00:00:00 ./bin/redis-server 192.168.22.33:7004 [cluster]
root      64229      1  0 15:46 ?        00:00:00 ./bin/redis-server 192.168.22.33:7005 [cluster]

创建集群:


[root@wyl redis-5.0.5]# ./bin/redis-cli --cluster create 192.168.22.33:7000 192.168.22.33:7001 192.168.22.33:7002 192.168.22.33:7003 192.168.22.33:7004 192.168.22.33:7005 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.22.33:7004 to 192.168.22.33:7000
Adding replica 192.168.22.33:7005 to 192.168.22.33:7001
Adding replica 192.168.22.33:7003 to 192.168.22.33:7002
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 3d580f0ecc38145f93af7d910f6321b225b338af 192.168.22.33:7000
   slots:[0-5460] (5461 slots) master
M: d960e8db22124b5759e2c693e6ba55238a051785 192.168.22.33:7001
   slots:[5461-10922] (5462 slots) master
M: dd7fbb1956d23bc210ea61aa608b665b59c2cd1e 192.168.22.33:7002
   slots:[10923-16383] (5461 slots) master
S: 63ab774ccbf7b7bdb58a314f0c013876cb4db899 192.168.22.33:7003
   replicates dd7fbb1956d23bc210ea61aa608b665b59c2cd1e
S: 5ce084550353be2bd582a901156f3c79eac202df 192.168.22.33:7004
   replicates 3d580f0ecc38145f93af7d910f6321b225b338af
S: 0f9ff62d9c90d36332552286f021dcfe09e4251b 192.168.22.33:7005
   replicates d960e8db22124b5759e2c693e6ba55238a051785
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
......
>>> Performing Cluster Check (using node 192.168.22.33:7000)
M: 3d580f0ecc38145f93af7d910f6321b225b338af 192.168.22.33:7000
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 0f9ff62d9c90d36332552286f021dcfe09e4251b 192.168.22.33:7005
   slots: (0 slots) slave
   replicates d960e8db22124b5759e2c693e6ba55238a051785
S: 63ab774ccbf7b7bdb58a314f0c013876cb4db899 192.168.22.33:7003
   slots: (0 slots) slave
   replicates dd7fbb1956d23bc210ea61aa608b665b59c2cd1e
M: dd7fbb1956d23bc210ea61aa608b665b59c2cd1e 192.168.22.33:7002
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: d960e8db22124b5759e2c693e6ba55238a051785 192.168.22.33:7001
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 5ce084550353be2bd582a901156f3c79eac202df 192.168.22.33:7004
   slots: (0 slots) slave
   replicates 3d580f0ecc38145f93af7d910f6321b225b338af
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

集群扩容

添加主节点:

备注:192.168.22.33:7006 是新的主节点 , 192.168.22.33:7000 是原存在的任一主节点

./bin/redis-cli --cluster add-node 192.168.22.33:7006  192.168.22.33:7000

 查看节点信息,7006节点还未分配槽位

 ./bin/redis-cli  -h 192.168.22.33 -p 7001 -c
192.168.22.33:7001> CLUSTER nodes
c1b945b0361046c9168875e4e1c1b496d9907516 192.168.22.33:7005@17005 slave 2d591abdfbc44a925e822825fda14fc6f60cc915 0 1571882461490 6 connected
d4ce5c2d9e86161c3c9b2ddaccc32b37701e94fd 192.168.22.33:7001@17001 myself,master - 0 1571882458000 2 connected 5461-10922
1f7234fc9dfe726d0af16fbd9b49c50b36f30803 192.168.22.33:7003@17003 slave 3b2314e226123b1ad7270b83579c6329b1b8689d 0 1571882460488 4 connected
2d591abdfbc44a925e822825fda14fc6f60cc915 192.168.22.33:7002@17002 master - 0 1571882463494 3 connected 10923-16383
ca1b2bdd68386b788caa70969e2542c0185d8fdb 192.168.22.33:7004@17004 slave d4ce5c2d9e86161c3c9b2ddaccc32b37701e94fd 0 1571882462000 5 connected
c972acd3671fad44257b2c533085c9335a9ed1bc 192.168.22.33:7006@17006 master - 0 1571882461000 0 connected  
3b2314e226123b1ad7270b83579c6329b1b8689d 192.168.22.33:7000@17000 master - 0 1571882462492 1 connected 0-5460

分配槽位

./bin/redis-cli --cluster reshard  192.168.22.33:7000
M: 3b2314e226123b1ad7270b83579c6329b1b8689d 192.168.22.33:7000
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: c972acd3671fad44257b2c533085c9335a9ed1bc 192.168.22.33:7006 (0 slots) master
M: 2d591abdfbc44a925e822825fda14fc6f60cc915 192.168.22.33:7002
   slots:[10922-16383] (5461slots) master
   1 additional replica(s)
S: ca1b2bdd68386b788caa70969e2542c0185d8fdb 192.168.22.33:7004
   slots: (0 slots) slave
   replicates d4ce5c2d9e86161c3c9b2ddaccc32b37701e94fd
S: c1b945b0361046c9168875e4e1c1b496d9907516 192.168.22.33:7005
   slots: (0 slots) slave
   replicates 2d591abdfbc44a925e822825fda14fc6f60cc915
M: d4ce5c2d9e86161c3c9b2ddaccc32b37701e94fd 192.168.22.33:7001
   slots:[5461-10922] (5461 slots) master
   1 additional replica(s)
S: 1f7234fc9dfe726d0af16fbd9b49c50b36f30803 192.168.22.33:7003
   slots: (0 slots) slave
   replicates 3b2314e226123b1ad7270b83579c6329b1b8689d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4000
What is the receiving node ID? c972acd3671fad44257b2c533085c9335a9ed1bc
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
Source node #2: done


#查看节点信息
192.168.22.33:7001> CLUSTER nodes
c1b945b0361046c9168875e4e1c1b496d9907516 192.168.22.33:7005@17005 slave 2d591abdfbc44a925e822825fda14fc6f60cc915 0 1571882669000 6 connected
d4ce5c2d9e86161c3c9b2ddaccc32b37701e94fd 192.168.22.33:7001@17001 myself,master - 0 1571882667000 2 connected 6795-10922
1f7234fc9dfe726d0af16fbd9b49c50b36f30803 192.168.22.33:7003@17003 slave 3b2314e226123b1ad7270b83579c6329b1b8689d 0 1571882664000 4 connected
2d591abdfbc44a925e822825fda14fc6f60cc915 192.168.22.33:7002@17002 master - 0 1571882669935 3 connected 12256-16383
ca1b2bdd68386b788caa70969e2542c0185d8fdb 192.168.22.33:7004@17004 slave d4ce5c2d9e86161c3c9b2ddaccc32b37701e94fd 0 1571882668000 5 connected
c972acd3671fad44257b2c533085c9335a9ed1bc 192.168.22.33:7006@17006 master - 0 1571882667000 7 connected 0-1332 5461-6794 10923-12255   # 已经分配了槽位
3b2314e226123b1ad7270b83579c6329b1b8689d 192.168.22.33:7000@17000 master - 0 1571882668000 1 connected 1333-5460

 添加对应的从节点

./bin/redis-cli --cluster add-node 192.168.22.33:7007  192.168.22.33:7000  --cluster-slave --cluster-master-id c972acd3671fad44257b2c533085c9335a9ed1bc
>>> Adding node 192.168.22.33:7007 to cluster 192.168.22.33:7000
>>> Performing Cluster Check (using node 192.168.22.33:7000)
M: 3b2314e226123b1ad7270b83579c6329b1b8689d 192.168.22.33:7000
   slots:[3785-6794],[10923-12255] (4343 slots) master
   1 additional replica(s)
M: c972acd3671fad44257b2c533085c9335a9ed1bc 192.168.22.33:7006
   slots:[0-1984],[6795-7801],[12256-13262] (3999 slots) master
M: 2d591abdfbc44a925e822825fda14fc6f60cc915 192.168.22.33:7002
   slots:[1985-2884],[13263-16383] (4021 slots) master
   1 additional replica(s)
S: ca1b2bdd68386b788caa70969e2542c0185d8fdb 192.168.22.33:7004
   slots: (0 slots) slave
   replicates d4ce5c2d9e86161c3c9b2ddaccc32b37701e94fd
S: c1b945b0361046c9168875e4e1c1b496d9907516 192.168.22.33:7005
   slots: (0 slots) slave
   replicates 2d591abdfbc44a925e822825fda14fc6f60cc915
M: d4ce5c2d9e86161c3c9b2ddaccc32b37701e94fd 192.168.22.33:7001
   slots:[2885-3784],[7802-10922] (4021 slots) master
   1 additional replica(s)
S: 1f7234fc9dfe726d0af16fbd9b49c50b36f30803 192.168.22.33:7003
   slots: (0 slots) slave
   replicates 3b2314e226123b1ad7270b83579c6329b1b8689d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.22.33:7007 to make it join the cluster.
Waiting for the cluster to join

>>> Configure node as replica of 192.168.22.33:7006.  # 可以看到7007作为7006的从
[OK] New node added correctly.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值