集群管理redis---linux 增、删

管理集群
redis-cli 命令
• 查看命令帮助
– redis-cli -h


• 常用选项
– -h IP 地址
– -p 端口
– -c 访问集群


redis-trib.rb 脚本
• 语法格式
– Redis-trib.rb


选项 参数
• 选项
– add-node 添加新节点
– check 对节点主机做检查
– reshard 对节点主机重新分片
– add-node --slave 添加从节点主机
– del-node 删除节点主机


测试集群中的某个节点信息
[root@53 ~]# ss -untlp | grep redis
tcp    LISTEN     0      128    192.168.4.53:6353                  *:*                   users:(("redis-server",pid=1042,fd=6))
tcp    LISTEN     0      128    192.168.4.53:16353                 *:*                   users:(("redis-server",pid=1042,fd=8))
[root@53 ~]# redis-cli -h 192.168.4.53 -p 6353
192.168.4.53:6353> cluster nodes
2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352@16352 master - 0 1530666417979 2 connected 5461-10922
0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355@16355 slave b00bfb1d93247f56719582e8b9865ae374e17c33 0 1530666416074 5 connected
45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353@16353 myself,master - 0 1530666416000 3 connected 10923-16383
9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354@16354 slave 45f61b35eaf179a4b161008b79c54122617048ee 0 1530666417578 4 connected
b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351@16351 master - 0 1530666415972 1 connected 0-5460
20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356@16356 slave 2f002d4ec870d72d2f966c6051a586c57cff1afa 0 1530666416977 6 connected
192.168.4.53:6353> 


1.在客户端访问任意一台master角色的redis服务器,查询数据或存储数据
50:
ping —c 2 192.168.4.5x
redis-cli -c -h 192.168.4.51 -p 6351
>set name bob
>set age 19
>keys *
>exit


redis-cli -c -h 192.168.4.52 -p 6351
>key *
>get age
>get name


管理集群:redis-trib.rb

把某个master角色主机的redis服务停止,对应的从库会自动升级为主库


50作为客户端访问检查集群是否正常运行
配置redis环境
[root@host50 yum.repos.d]# yum -y install gcc gcc-c++
[root@host50 yum.repos.d]# cd
[root@host50 ~]# ls
anaconda-ks.cfg  redis-4.0.8.tar.gz  zhuhaiyan.txt
redis-4.0.8      root@192.168.4.1
[root@host50 ~]# cd redis-4.0.8/
[root@host50 redis-4.0.8]# make
[root@host50 redis-4.0.8]# make install
[root@host50 redis-4.0.8]# cd utils/
[root@host50 utils]# vim ./install_server.sh 
[root@host50 utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server


Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
检查连接
[root@host50 utils]# redis-cli -c -h 192.168.4.51 -p 6351
192.168.4.51:6351> set name bob
-> Redirected to slot [5798] located at 192.168.4.52:6352
OK
192.168.4.52:6352> set age 19
-> Redirected to slot [741] located at 192.168.4.51:6351
OK
192.168.4.51:6351> Keys *
1) "age"
192.168.4.51:6351> exit
[root@host50 utils]# redis-cli -c -h 192.168.4.52 -p 6352
192.168.4.52:6352> Key *
(error) ERR unknown command 'Key'
192.168.4.52:6352> Keys *
1) "name"
192.168.4.52:6352> get age
-> Redirected to slot [741] located at 192.168.4.51:6351
"19"
192.168.4.51:6351> get name
-> Redirected to slot [5798] located at 192.168.4.52:6352
"bob"




查看集群内的信息
[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots: (0 slots) slave
   replicates 2f002d4ec870d72d2f966c6051a586c57cff1afa
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.




52数据库停掉
[root@52 ~]# redis-cli -h 192.168.4.52 -p 6352 shutdown
[root@52 ~]# ss -untlp | grep redis




56升级为主,当56在坏掉的时候,集群将会崩溃
[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:5461-10922 (5462 slots) master
   0 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.




在添加入52
[root@52 ~]# /etc/init.d/redis_6379 start 
Starting Redis server...
[root@52 ~]# ss -untlp | grep redis
tcp    LISTEN     0      128    192.168.4.52:6352                  *:*                   users:(("redis-server",pid=2022,fd=6))
tcp    LISTEN     0      128    192.168.4.52:16352                 *:*                   users:(("redis-server",pid=2022,fd=8))








51的信息
[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.




哈希槽范围


添加master角色主机  哈希槽 0~16384


添加57作为主库
配置redis环境
[root@host57 yum.repos.d]# yum -y install gcc gcc-c++
[root@host57 yum.repos.d]# cd
[root@host57 ~]# ls
anaconda-ks.cfg  redis-4.0.8.tar.gz  
redis-4.0.8     
[root@host57 ~]# cd redis-4.0.8/
[root@host57 redis-4.0.8]# make
[root@host57 redis-4.0.8]# make install
[root@host57 redis-4.0.8]# cd utils/
[root@host57 utils]# vim ./install_server.sh 
[root@host57 utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server


Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!








[root@host57 ~]# vim /etc/redis/6379.conf
70 bind 192.168.4.57
93 port 6357
815 cluster-enabled yes
823 cluster-config-file nodes-6357.conf 
829 cluster-node-timeout 5000


[root@host57 ~]# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped
[root@host57 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@host57 ~]# /etc/init.d/redis_6379 status
Redis is running (8287)
[root@host57 ~]# ss -utnlp | grep redis
tcp    LISTEN     0      128    192.168.4.57:6357                  *:*                   users:(("redis-server",pid=8287,fd=6))
tcp    LISTEN     0      128    192.168.4.57:16357                 *:*                   users:(("redis-server",pid=8287,fd=8))
[root@host57 ~]# redis-cli -h 192.168.4.57 -p 6357
192.168.4.57:6357> cluser info
(error) ERR unknown command 'cluser'
192.168.4.57:6357> cluster info
cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:0
cluster_current_epoch:0
cluster_my_epoch:0
cluster_stats_messages_sent:0
cluster_stats_messages_received:0
192.168.4.57:6357> cluster nodes
6df9172d2b03bf298dc7342acdcf1b385f367aba :6357@16357 myself,master - 0 0 0 connected






[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots: (0 slots) slave
   replicates 2f002d4ec870d72d2f966c6051a586c57cff1afa
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[root@51 ~]# redis-trib.rb add-node 192.168.4.57:6357 192.168.4.51:6351
>>> Adding node 192.168.4.57:6357 to cluster 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[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.4.57:6357 to make it join the cluster.
[OK] New node added correctly.




[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357
   slots: (0 slots) master
   0 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.






[root@51 ~]# redis-trib.rb reshard  192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357
   slots: (0 slots) master
   0 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[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)? 4096
What is the receiving node ID? 6df9172d2b03bf298dc7342acdcf1b385f367aba
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








[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.


















添加salve角色主机
主机58
[root@host58 yum.repos.d]# yum -y install gcc gcc-c++
[root@host58 yum.repos.d]# cd
[root@host58 ~]# ls
anaconda-ks.cfg  redis-4.0.8.tar.gz  zhuhaiyan.txt
redis-4.0.8      root@192.168.4.1
[root@host58 ~]# cd redis-4.0.8/
[root@host58 redis-4.0.8]# make
[root@host58 redis-4.0.8]# make install
[root@host58 redis-4.0.8]# cd utils/
[root@host58 utils]# vim ./install_server.sh 
[root@host58 utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server


Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!








[root@host58 ~]# vim /etc/redis/6379.conf
70 bind 192.168.4.58
93 port 6358
815 cluster-enabled yes
823 cluster-config-file nodes-6358.conf 
829 cluster-node-timeout 5000


[root@host58 ~]# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped
[root@host58 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@host58 ~]# /etc/init.d/redis_6379 status
Redis is running (8287)
[root@host58 ~]# ss -utnlp | grep redis
tcp    LISTEN     0      128    192.168.4.57:6357                  *:*                   users:(("redis-server",pid=8287,fd=6))
tcp    LISTEN     0      128    192.168.4.57:16357                 *:*                   users:(("redis-server",pid=8287,fd=8))
[root@host58 ~]# redis-cli -h 192.168.4.58 -p 6358
192.168.4.58:6358> cluser info
(error) ERR unknown command 'cluser'
192.168.4.58:6358> cluster info
cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:0
cluster_current_epoch:0
cluster_my_epoch:0
cluster_stats_messages_sent:0
cluster_stats_messages_received:0
192.168.4.58:6358> cluster nodes
6df9172d2b03bf298dc7342acdcf1b385f367aba :6357@16357 myself,master - 0 0 0 connected






[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
M: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots: (0 slots) slave
   replicates 2f002d4ec870d72d2f966c6051a586c57cff1afa
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...








[root@51 ~]# redis-trib.rb add-node --slave 192.168.4.58:6358 192.168.4.51:6351
>>> Adding node 192.168.4.58:6358 to cluster 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Automatically selected master 192.168.4.57:6357
>>> Send CLUSTER MEET to node 192.168.4.58:6358 to make it join the cluster.
Waiting for the cluster to join...
>>> Configure node as replica of 192.168.4.57:6357.
[OK] New node added correctly.
[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: b0c55a35186066cdcdba76063c78b992f9647b0f 192.168.4.58:6358
   slots: (0 slots) slave
   replicates 6df9172d2b03bf298dc7342acdcf1b385f367aba
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.






移除从节点


[root@51 ~]# redis-trib.rb del-node  192.168.4.51:6351 b0c55a35186066cdcdba76063c78b992f9647b0f
>>> Removing node b0c55a35186066cdcdba76063c78b992f9647b0f from cluster 192.168.4.51:6351
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.








[root@localhost ~]# redis-cli -h 192.168.4.58 -p 6358
192.168.4.58:6358> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:8
cluster_size:4
cluster_current_epoch:8
cluster_my_epoch:8
cluster_stats_messages_ping_sent:16179
cluster_stats_messages_pong_sent:14146
cluster_stats_messages_meet_sent:7
cluster_stats_messages_sent:30332
cluster_stats_messages_ping_received:14144
cluster_stats_messages_pong_received:16186
cluster_stats_messages_meet_received:2
cluster_stats_messages_received:30332
192.168.4.58:6358> cluster info
Could not connect to Redis at 192.168.4.58:6358: Connection refused
not connected> exit


[root@host58 ~]# ss -utnlp | grep redis
[root@host58 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@host58 ~]# /etc/init.d/redis_6379 status
Redis is running (7862)
[root@host58 ~]# redis-cli -h 192.168.4.58 -p 6358
192.168.4.58:6358> cluster 
(error) ERR wrong number of arguments for 'cluster' command
192.168.4.58:6358> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:8
cluster_size:4
cluster_current_epoch:8
cluster_my_epoch:8
cluster_stats_messages_ping_sent:236
cluster_stats_messages_sent:236
cluster_stats_messages_pong_received:236
cluster_stats_messages_received:236
192.168.4.58:6358> cluster nodes
0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355@16355 slave b00bfb1d93247f56719582e8b9865ae374e17c33 0 1530684853194 1 connected
9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354@16354 slave 45f61b35eaf179a4b161008b79c54122617048ee 0 1530684852092 3 connected
20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356@16356 master - 0 1530684851691 7 connected 6827-10922
6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357@16357 master - 0 1530684852192 8 connected 0-1364 5461-6826 10923-12287
b0c55a35186066cdcdba76063c78b992f9647b0f 192.168.4.58:6358@16358 myself,slave 6df9172d2b03bf298dc7342acdcf1b385f367aba 0 1530684758940 0 connected
45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353@16353 master - 0 1530684852693 3 connected 12288-16383
b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351@16351 master - 0 1530684852000 1 connected 1365-5460
2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352@16352 slave 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 0 1530684852000 7 connected
192.168.4.58:6358> 


移出主库






[root@51 ~]# redis-trib.rb del-node  192.168.4.51:6351 6df9172d2b03bf298dc7342acdcf1b385f367aba
>>> Removing node 6df9172d2b03bf298dc7342acdcf1b385f367aba from cluster 192.168.4.51:6351
[ERR] Node 192.168.4.57:6357 is not empty! Reshard data away and try again.
1.重新分片
[root@51 ~]# redis-trib.rb  reshard 192.168.4.51:6351 
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[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)? 4096    ----想要移除的哈希槽的个数
What is the receiving node ID? all
*** The specified node is not known or not a master, please retry.
What is the receiving node ID? 45f61b35eaf179a4b161008b79c54122617048ee  ----把移动哈希槽给哪个主机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:6df9172d2b03bf298dc7342acdcf1b385f367aba    ----想要移除的哈希槽对应的主机id
Source node #2:done                         ----确定需要这样做


[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357
   slots: (0 slots) master
   0 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:0-1364,5461-6826,10923-16383 (8192 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.




[root@51 ~]# redis-trib.rb del-node  192.168.4.51:6351 6df9172d2b03bf298dc7342acdcf1b385f367aba
>>> Removing node 6df9172d2b03bf298dc7342acdcf1b385f367aba from cluster 192.168.4.51:6351
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.




[root@51 ~]# redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: 2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352
   slots: (0 slots) slave
   replicates 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a
M: 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355
   slots: (0 slots) slave
   replicates b00bfb1d93247f56719582e8b9865ae374e17c33
M: 45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353
   slots:0-1364,5461-6826,10923-16383 (8192 slots) master
   1 additional replica(s)
S: 9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354
   slots: (0 slots) slave
   replicates 45f61b35eaf179a4b161008b79c54122617048ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.




主机57的配置信息还在,但是已经不属于集群的信息了
[root@host57 ~]# redis-cli -h 192.168.4.57 -p 6357
Could not connect to Redis at 192.168.4.57:6357: Connection refused
Could not connect to Redis at 192.168.4.57:6357: Connection refused
not connected> 
[root@host57 ~]# ss -ntulp | grep redis
[root@host57 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@host57 ~]# /etc/init.d/redis_6379 stop
Stopping ...
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
^C
[root@host57 ~]# redis-cli -h 192.168.4.57 -p 6357
192.168.4.57:6357> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:7
cluster_size:3
cluster_current_epoch:9
cluster_my_epoch:8
cluster_stats_messages_ping_sent:120
cluster_stats_messages_pong_sent:20
cluster_stats_messages_sent:140
cluster_stats_messages_ping_received:20
cluster_stats_messages_pong_received:120
cluster_stats_messages_received:140
192.168.4.57:6357> cluster nodes
9672778d5a8c6685daa7339df325d93f6c73b6bd 192.168.4.54:6354@16354 slave 45f61b35eaf179a4b161008b79c54122617048ee 0 1530686344800 9 connected
2f002d4ec870d72d2f966c6051a586c57cff1afa 192.168.4.52:6352@16352 slave 20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 0 1530686345604 7 connected
0ba5e235aa72f9ea10ed8f7da1a60caefc9b9b6c 192.168.4.55:6355@16355 slave b00bfb1d93247f56719582e8b9865ae374e17c33 0 1530686344000 1 connected
45f61b35eaf179a4b161008b79c54122617048ee 192.168.4.53:6353@16353 master - 0 1530686345604 9 connected 0-1364 5461-6826 10923-16383
6df9172d2b03bf298dc7342acdcf1b385f367aba 192.168.4.57:6357@16357 myself,master - 0 1530686283693 8 connected
20b20d6ddf38a67e8f81bb7badec220bf2be7b3a 192.168.4.56:6356@16356 master - 0 1530686345804 7 connected 6827-10922
b00bfb1d93247f56719582e8b9865ae374e17c33 192.168.4.51:6351@16351 master - 0 1530686344299 1 connected 1365-5460
192.168.4.57:6357> 






把移除的主机变成一个独立的数据库节点


[root@host57 ~]# vim /etc/redis/6379.conf 
#cluster-node-timeout 5
#cluster-config-file nodes-6357.conf000
#cluster-enabled yes


[root@host57 ~]# redis-cli -h 192.168.4.57 -p 6357 shutdown
[root@host57 ~]# /etc/init.d/redis_6379 stop
/var/run/redis_6379.pid does not exist, process is not running
[root@host57 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@host57 ~]# /etc/init.d/redis_6379 status
Redis is running (10048)
[root@host57 ~]# redis-cli -h 192.168.4.57 -p 6357 
192.168.4.57:6357> cluster info
ERR This instance has cluster support disabled
192.168.4.57:6357> cluster 












数据迁移上云是指什么?
如果把不同数据库都数据之间进行迁移的化,应该怎么样去实现?







































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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值