redis4.0集群管理

环境
192,168.29.201
192,168.29.202
192,168.29.203
192,168.29.204
192,168.29.205
192,168.29.206
192,168.29.207
192,168.29.208

为了避免安装redis4集群管理工具redis.rb。此工具为ruby高本版,特此使用官方给的一种方案,使用redis5.0的redis-cli客户端管理redis4.0集群

配置文件

[root@test_trademgt bin]# grep -v "#" redis.conf |grep -v "^$"
bind 0.0.0.0
protected-mode yes
port 7000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/hbec/redis4/logs/redis.log"
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /hbec/redis4/data_root
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly yes
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 no
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
masterauth passwd123
requirepass passwd123
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
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

 

[root@test_trademgt bin]#mkdir /hbec/redis4/data_root -p
[root@test_trademgt bin]#mkdir /hbec/redis4/logs -p

#注释-p 7000仅仅用于本地连接使用
[root@test_trademgt bin]#cd /usr/local/redis4/bin/
[root@test_trademgt bin]#./redis-server ./redis.conf

[root@test_trademgt bin]#/usr/local/redis4/bin/redis-cli5 -a passwd123 --cluster create 192.168.29.201:7000 192.168.29.202:7000 192.168.29.203:7000 192.168.29.204:7000 192.168.29.205:7000 192.168.29.206:7000 --cluster-replicas 1
[root@test_trademgt bin]#redis-cli -p 7000 -a passwd123 --cluster add-node 192.168.29.205:7205 192.168.29.201:7000 添加主节点
[root@test_trademgt bin]#redis-cli -p 7000 -a passwd123 --cluster add-node 192.168.29.206:7206 192.168.29.201:7000 --cluster-slave 添加从节点
#slot迁移至新加入slot数量为0的master节点
[root@test_trademgt bin]#/usr/local/redis4/bin/redis-cli5 -p 7000 -a passwd123 --cluster rebalance --cluster-threshold 1 --cluster-use-empty-masters 192.168.29.205:7205

[root@test_trademgt bin]#/usr/local/redis4/bin/redis-cli5 -p 7000 -a passwd123 -c cluster nodes
#数据迁移,集群缩减
[root@test_trademgt bin]# /usr/local/redis4/bin/redis-cli5 -a passwd123 --cluster reshard 192.168.29.205:7205
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.29.205:7205)
M: a02a33877e8c4f117a58303af4de492b68fa536a 192.168.29.205:7205
   slots:[12286-12287] (2 slots) master
   1 additional replica(s)
M: 1f42453e563f973bb804e9b2b7255598f51fd9e5 192.168.29.203:7000
   slots:[0-1364],[5461-6826],[10923-12285],[12288-16383] (8190 slots) master
   1 additional replica(s)
S: 219e6c1d399d53ded9cb587ddebb83aaca8fa55c 192.168.29.205:7000
   slots: (0 slots) slave
   replicates d28e5e0464cbebe020ceb495205690ca7b1681d6
M: d28e5e0464cbebe020ceb495205690ca7b1681d6 192.168.29.201:7000
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: d0b95d9b1a140b2bf34fc7cbd26c4372eb0a0a2a 192.168.29.202:7000
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 07a1ed150eb70d8cf822ac0a029baeb1ae0d7da4 192.168.29.206:7206
   slots: (0 slots) slave
   replicates a02a33877e8c4f117a58303af4de492b68fa536a
S: 7879451c0da0878dc4dfd3000479915067ca714a 192.168.29.206:7000
   slots: (0 slots) slave
   replicates d0b95d9b1a140b2bf34fc7cbd26c4372eb0a0a2a
S: b6dabc77e3f21b777aa49809893008591dc07153 192.168.29.204:7000
   slots: (0 slots) slave
   replicates 1f42453e563f973bb804e9b2b7255598f51fd9e5
[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)? 2  #移动的slot数量
What is the receiving node ID? 1f42453e563f973bb804e9b2b7255598f51fd9e5  #接收源
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: a02a33877e8c4f117a58303af4de492b68fa536a   #移动源
Source node #2: done                     #输入完成

Ready to move 2 slots.
  Source nodes:
    M: a02a33877e8c4f117a58303af4de492b68fa536a 192.168.29.205:7205
       slots:[12286-12287] (2 slots) master
       1 additional replica(s)
  Destination node:
    M: 1f42453e563f973bb804e9b2b7255598f51fd9e5 192.168.29.203:7000
       slots:[0-1364],[5461-6826],[10923-12285],[12288-16383] (8190 slots) master
       1 additional replica(s)
  Resharding plan:
    Moving slot 12286 from a02a33877e8c4f117a58303af4de492b68fa536a
    Moving slot 12287 from a02a33877e8c4f117a58303af4de492b68fa536a
Do you want to proceed with the proposed reshard plan (yes/no)? yes  #同意
Moving slot 12286 from 192.168.29.205:7205 to 192.168.29.203:7000: 
Moving slot 12287 from 192.168.29.205:7205 to 192.168.29.203:7000: 

[root@test_trademgt bin]#/usr/local/redis4/bin/redis-cli5 -p 7000 -a passwd123  del-node  先删除被迁移的master节点的slave节点,后删除空的master节点
现在集群为6台
本地单机redis数据迁移至redis集群
1、将所有的master的slot迁移到一个mater,如master 201   提示How many slots do you want to move (from 1 to 16384)?  可以选择一个大的数据,这样不用其计算移动的slot大小
2、关闭所有redis集群的从节点
3、逐一关闭主节点,最后关闭master201
4、上传aof文件至201
4、开启master201和其他master,并/usr/local/redis4/bin/redis-cli5 -p 7000 -a passwd123 -c cluster nodes 查看master状态
5、开启从节点
6、/usr/local/redis4/bin/redis-cli5  -a passwd123 --cluster rebalance --cluster-threshold 1 --cluster-use-empty-masters 192.168.29.202:7000
其中192.168.29.202:7000为集群入口并非是master201
7、查看数据是否分配至其他主节点

  

 

posted @ 2019-08-16 15:43  骑猪追夕阳_577513827  阅读(310)  评论(0编辑  收藏  举报