0713 Preview Task 2 redis Cluster

Keywords: Linux Redis Ruby SSL RPM

Introduction to 21.22 redis cluster


  • Multiple redis nodes network interconnected, data sharing

  • All nodes are master-slave (which can be multiple slaves), where services are never provided and only served as standby

  • Processing multiple keys at once (such as mset/mget) is not supported because redis need to distribute keys evenly across nodes, and concurrent key creation can degrade performance and result in unpredictable behavior.

  • Support adding and removing nodes Online

  • Client can read and write to any primary node


21.23/21.24 redis Cluster Setup Configuration

1. Scene settings:

Two machines, three Redis services (ports)

Three ports 7000,7002,7004 on machine A, all predominantly

Three ports 7001,7003,7005 on machine B, all from

Compile and install redis on both machines, then edit and copy three different redis.conf s, set different port numbers, dir and other parameters, add cluster-related parameters, and then start six redis services

3. Edit redis_7000,redis_7002,redis_7004 on Machine A

[root@arslinux-01 ~]# vim redis_7000.conf
port 7000
bind 192.168.194.130
daemonize yes
pidfile /var/run/redis_7000.pid
dir /data/redis_data/7000
cluster-enabled yes
cluster-config-file nodes_7000.conf
cluster-node-timeout 10100
appendonly yes

The redis_7002 and redis_7004 methods are the same

Edit redis_7001,redis_7003,redis_7005 on machine B

[root@arslinux-02 ~]# vim redis_7001.conf
port 7001
bind 192.168.194.132
daemonize yes
pidfile /var/run/redis_7001.pid
dir /data/redis_data/7001
cluster-enabled yes
cluster-config-file nodes_7001.conf
cluster-node-timeout 10100
appendonly yes

The redis_7003 and redis_7005 methods are the same

Parameters can be referenced https://coding.net/u/aminglinux/p/yuanke_centos7/git/tree/master/21NOSQL

3. Create a directory

A Machine

[root@arslinux-01 ~]# mkdir /data/redis_data/
[root@arslinux-01 ~]# mkdir /data/redis_data/{7000,7002,7004}

B Machine

[root@arslinux-02 ~]# mkdir /data/redis_data/
[root@arslinux-02 ~]# mkdir /data/redis_data/{7001,7003,7005}

4. Install redis on machine B

1) Copy the compiled source package directory

[root@arslinux-01 src]# scp -r redis-4.0.1 192.168.194.132:/usr/local/src/

2) Enter the source package directory and make install directly

[root@arslinux-02 redis-4.0.1]# make install
cd src && make install
make[1]: Enter Catalog "/usr/local/src/redis-4.0.1/src"
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leave Directory/usr/local/src/redis-4.0.1/src"

5, Machine A and Machine B start 6 redis respectively

[root@arslinux-01 ~]# redis-server /etc/redis_7000.conf
21160:C 15 Jul 12:47:55.370 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21160:C 15 Jul 12:47:55.370 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=21160, just started
21160:C 15 Jul 12:47:55.371 # Configuration loaded
[root@arslinux-01 ~]# redis-server /etc/redis_7002.conf
21169:C 15 Jul 12:47:59.268 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21169:C 15 Jul 12:47:59.268 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=21169, just started
21169:C 15 Jul 12:47:59.268 # Configuration loaded
[root@arslinux-01 ~]# redis-server /etc/redis_7004.conf
21174:C 15 Jul 12:48:02.023 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21174:C 15 Jul 12:48:02.023 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=21174, just started
21174:C 15 Jul 12:48:02.023 # Configuration loaded
[root@arslinux-01 ~]# ps aux|grep redis
root       8128  0.1  0.9 147348  9080 ?        Ssl  12:03   0:04 redis-server 127.0.0.1:6379
root       8151  0.1  0.9 147348  9004 ?        Ssl  12:03   0:04 redis-server 127.0.0.1:6380
root      21161  0.1  0.2 145304  2640 ?        Ssl  12:47   0:00 redis-server 192.168.194.130:7000 [cluster]
root      21170  0.1  0.2 145304  2636 ?        Ssl  12:47   0:00 redis-server 192.168.194.130:7002 [cluster]
root      21175  0.1  0.2 145304  2640 ?        Ssl  12:48   0:00 redis-server 192.168.194.130:7004 [cluster]
root      21216  0.0  0.0 112724   988 pts/0    R+   12:49   0:00 grep --color=auto redis
[root@arslinux-02 ~]# redis-server /etc/redis_7001.conf
7773:C 15 Jul 12:48:59.676 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7773:C 15 Jul 12:48:59.676 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=7773, just started
7773:C 15 Jul 12:48:59.677 # Configuration loaded
[root@arslinux-02 ~]# redis-server /etc/redis_7003.conf
7778:C 15 Jul 12:49:02.024 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7778:C 15 Jul 12:49:02.024 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=7778, just started
7778:C 15 Jul 12:49:02.024 # Configuration loaded
[root@arslinux-02 ~]# redis-server /etc/redis_7005.conf
7783:C 15 Jul 12:49:04.469 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7783:C 15 Jul 12:49:04.470 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=7783, just started
7783:C 15 Jul 12:49:04.470 # Configuration loaded
[root@arslinux-02 ~]# ps aux|grep redis
root       7774  0.2  0.7 145304  7576 ?        Ssl  12:48   0:00 redis-server 192.168.194.132:7001 [cluster]
root       7779  0.3  0.7 145304  7576 ?        Ssl  12:49   0:00 redis-server 192.168.194.132:7003 [cluster]
root       7784  0.2  0.7 145304  7572 ?        Ssl  12:49   0:00 redis-server 192.168.194.132:7005 [cluster]

6. Close the firewall

7. Install ruby (just install it on one machine)

[root@arslinux-01 ~]# yum -y groupinstall "Development Tools"

Process omission

8. Install related packages

[root@arslinux-01 ~]# yum -y install gdbm-devel libdb4-devel libffi-devel libyaml libyaml-devel ncurses-devel openssl-devel readline-devel tcl-deve

9. Create a catalog and download source packages

[root@arslinux-01 ~]# cd /root/
[root@arslinux-01 ~]# mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
[root@arslinux-01 ~]# wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.gz -P rpmbuild/SOURCES

10. Download the Ruby2x.spec file

[root@arslinux-01 ~]# wget https://raw.githubusercontent.com/tjinjin/automate-ruby-rpm/master/ruby22x.spec -P rpmbuild/SPECS

11. Compile and make rpm packages

[root@arslinux-01 ~]# rpmbuild -bb rpmbuild/SPECS/ruby22x.spec
[root@arslinux-01 ~]# ls rpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm
rpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm
[root@arslinux-01 ~]# du -sh rpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm
10Mrpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm

12. yum installs local rpm packages (avoid dependency issues)

[root@arslinux-01 ~]# yum -y localinstall rpmbuild/RPMS/x86_64/ruby-2.2.3-1.el7.x86_64.rpm

13. Installation Error

[root@arslinux-01 ~]# gem install redis
Fetching: redis-4.1.2.gem (100%)
ERROR:  Error installing redis:
redis requires Ruby version >= 2.3.0.

14. Install rvm to update ruby Version to 2.3.0

1) Download

[root@arslinux-01 ~]# gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
[root@arslinux-01 ~]# \curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc
gpg: to 2019 July 10, 2000 Wednesday 16 31 min 02 seconds CST Created signature, using RSA,Key number 39499BDB
gpg: Good signature from Piotr Kuczynski <piotr.kuczynski@gmail.com>"
gpg: Warning: This key is not authenticated by a trusted signature!
gpg:       There is no evidence that the signature belongs to the holder it claims to be.
//Primary key fingerprint: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.9.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:
* First you need to add all users that will be using rvm to 'rvm' group,
and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.
* To start using RVM you need to run `source /etc/profile.d/rvm.sh`
in all your open shell windows, in rare cases you need to reopen all shell windows.
* Please do NOT forget to add your users to the rvm group.
The installer no longer auto-adds root or users to the rvm group. Admins must do this.
Also, please note that group memberships are ONLY evaluated at login time.
This means that users must log out then back in before group membership takes effect!
Thanks for installing RVM

2) Add rvm users to the rvm group as prompted

[root@arslinux-01 ~]# useradd -g rvm rvm

Function

[root@arslinux-01 ~]# source /etc/profile.d/rvm.sh

3) Change rvm download Ruby source to mirror ruby china

[root@arslinux-01 ~]# gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
https://gems.ruby-china.com/ added to sources
https://rubygems.org/ removed from sources

4) Re\curl

[root@arslinux-01 ~]# \curl -sSL https://get.rvm.io | bash -s stable

5) Version of rvm after installation

[root@arslinux-01 ~]# rvm -v
rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

6) View known ruby versions of rvm Libraries

[root@arslinux-01 ~]# rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.6]
[ruby-]2.5[.5]
[ruby-]2.6[.3]
[ruby-]2.7[.0-preview1]
ruby-head

7) Install ruby 2.3.0

[root@arslinux-01 ~]# rvm install 2.3.0

8) ruby version after installation

[root@arslinux-01 ~]# ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

15. Re-gem install redis

[root@arslinux-01 ~]# gem install redis
Fetching redis-4.1.2.gem
Successfully installed redis-4.1.2
Parsing documentation for redis-4.1.2
Installing ri documentation for redis-4.1.2
Done installing documentation for redis after 2 seconds
1 gem installed

16. Create a cluster master-slave

[root@arslinux-01 ~]# cp /usr/local/src/redis-4.0.1/src/redis-trib.rb  /usr/bin/
[root@arslinux-01 ~]# redis-trib.rb create --replicas 1 192.168.194.130:7000 192.168.194.130:7002 192.168.194.130:7004 192.168.194.132:7001 192.168.194.132:7003 192.168.194.132:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.194.130:7000
192.168.194.132:7001
192.168.194.130:7002
Adding replica 192.168.194.132:7003 to 192.168.194.130:7000
Adding replica 192.168.194.130:7004 to 192.168.194.132:7001
Adding replica 192.168.194.132:7005 to 192.168.194.130:7002
M: 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000
slots:0-5460 (5461 slots) master
M: 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002
slots:10923-16383 (5461 slots) master
S: 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004
replicates 62f3b3275922753035007d4dcc272c839baf45fd
M: 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001
slots:5461-10922 (5462 slots) master
S: aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003
replicates 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53
S: bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005
replicates 2ec8052ab336ccab81a6ce69ca49c454fa2971f6
Can I set the above configuration? (type 'yes' to accept):

If you are not satisfied with the configuration, you can cancel it, change it and configure it again. From the distribution law, it should be allocated by port number.

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.194.130:7000)
M: 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003
slots: (0 slots) slave
replicates 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53
M: 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005
slots: (0 slots) slave
replicates 2ec8052ab336ccab81a6ce69ca49c454fa2971f6
S: 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004
slots: (0 slots) slave
replicates 62f3b3275922753035007d4dcc272c839baf45fd
M: 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.


21.25 redis cluster operations

  • Connect redis cluster

Redis-cli-c plus-c to cluster

[root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7000
192.168.194.130:7000> set key1 123
-> Redirected to slot [9189] located at 192.168.194.132:7001
OK
192.168.194.132:7001> set key2 abc
-> Redirected to slot [4998] located at 192.168.194.130:7000
OK
192.168.194.130:7000> set key3 asdfadf
OK
192.168.194.130:7000> set key4 safasdfafafaf
-> Redirected to slot [13120] located at 192.168.194.130:7002
OK
192.168.194.130:7002> get key3
-> Redirected to slot [935] located at 192.168.194.130:7000
"asdfadf"
192.168.194.130:7000> get key4
-> Redirected to slot [13120] located at 192.168.194.130:7002
"safasdfafafaf"

Either node can create or view a key

  • View cluster status

[root@arslinux-01 ~]# redis-trib.rb check 192.168.194.130:7000
>>> Performing Cluster Check (using node 192.168.194.130:7000)
M: 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003
slots: (0 slots) slave
replicates 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53
M: 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005
slots: (0 slots) slave
replicates 2ec8052ab336ccab81a6ce69ca49c454fa2971f6
S: 992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004
slots: (0 slots) slave
replicates 62f3b3275922753035007d4dcc272c839baf45fd
M: 62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

  • List Nodes

[root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7000
192.168.194.130:7000> cluster nodes
aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563200390518 5 connected
2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563200391000 2 connected 10923-16383
bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563200389000 6 connected
992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563200391523 4 connected
62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563200389509 4 connected 5461-10922
05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563200390000 1 connected 0-5460
192.168.194.130:7000>
  • View cluster information

192.168.194.130:7000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:590
cluster_stats_messages_pong_sent:564
cluster_stats_messages_sent:1154
cluster_stats_messages_ping_received:559
cluster_stats_messages_pong_received:590
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:1154
192.168.194.130:7000>
  • Add Node

1. Add a redis_7007.conf to machine B and start

[root@arslinux-02 ~]# cp /etc/redis_7001.conf /etc/redis_7007.conf
[root@arslinux-02 ~]# vim !$
vim /etc/redis_7007.conf
[root@arslinux-02 ~]# vim /etc/redis_7007.conf
:1,$s/7001/7007/g
[root@arslinux-02 ~]# mkdir /data/redis_data/7007
[root@arslinux-02 ~]# redis-server /etc/redis_7007.conf
11778:C 15 Jul 22:25:53.285 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11778:C 15 Jul 22:25:53.286 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=11778, just started
11778:C 15 Jul 22:25:53.286 # Configuration loaded

2. Add Node CLUSTER MEET IP PORT to Machine A

192.168.194.130:7000> CLUSTER MEET 192.168.194.132 7007
OK
192.168.194.130:7000> 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:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:887
cluster_stats_messages_pong_sent:840
cluster_stats_messages_meet_sent:1
cluster_stats_messages_sent:1728
cluster_stats_messages_ping_received:835
cluster_stats_messages_pong_received:888
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:1728
192.168.194.130:7000> cluster nodes
aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563200827000 5 connected
2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563200827000 2 connected 10923-16383
5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563200827911 0 connected
bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563200829925 6 connected
992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563200827000 4 connected
62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563200828917 4 connected 5461-10922
05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563200828000 1 connected 0-5460

7007 added to node

3. Add redis_7006.conf to Machine A and start

[root@arslinux-01 ~]# cp /etc/redis_7000.conf /etc/redis_7006.conf
[root@arslinux-01 ~]# vim /etc/redis_7006.conf
:1,$s/7000/7006/g
[root@arslinux-01 ~]# mkdir /data/redis
redis/      redis2/     redis_data/
[root@arslinux-01 ~]# mkdir /data/redis_data/7006
[root@arslinux-01 ~]# redis-server /etc/redis_7006.conf
30733:C 15 Jul 22:31:09.999 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
30733:C 15 Jul 22:31:09.999 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=30733, just started
30733:C 15 Jul 22:31:09.999 # Configuration loaded

4. After adding a node, it is discovered that the newly added node also exists as a master

[root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7000
192.168.194.130:7000> CLUSTER MEET 192.168.194.130 7006
OK
192.168.194.130:7000> CLUSTER NODES
aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563201239936 5 connected
8b689873117d639562fb33044f2904454e936d31 192.168.194.130:7006@17006 master - 0 1563201240000 0 connected
2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563201239000 2 connected 10923-16383
5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563201238000 0 connected
bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563201240947 6 connected
992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563201239000 4 connected
62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563201238000 4 connected 5461-10922
05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563201238000 1 connected 0-5460

How do I set a node as slave?

  • Sets the current node as the slave of the specified node

You can go to a node you want to be master and configure slave

[root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7006
192.168.194.130:7006> CLUSTER REPLICATE 5ab4b80953ffe946608f288dad1d75e6136c7642
OK
192.168.194.130:7006> CLUSTER NODES
aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563201511361 1 connected
62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563201510347 4 connected 5461-10922
5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563201509140 7 connected
bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563201509339 2 connected
8b689873117d639562fb33044f2904454e936d31 192.168.194.130:7006@17006 myself,slave 5ab4b80953ffe946608f288dad1d75e6136c7642 0 1563201509000 0 connected
992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563201509000 4 connected
2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563201508330 2 connected 10923-16383
05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 master - 0 1563201508000 1 connected 0-5460
  • Remove Nodes

slave can be removed and need to be removed in redis of non-removal nodes

192.168.194.130:7006> CLUSTER FORGET 8b689873117d639562fb33044f2904454e936d31
(error) ERR I tried hard but I can't forget myself...
192.168.194.130:7006> quit
[root@arslinux-01 ~]# redis-cli -c -h 192.168.194.130 -p 7000
192.168.194.130:7000> CLUSTER FORGET 8b689873117d639562fb33044f2904454e936d31
OK
192.168.194.130:7000> CLUSTER NODES
aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563201752000 5 connected
2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563201751000 2 connected 10923-16383
5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563201752000 7 connected
bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563201752812 6 connected
992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563201753820 4 connected
62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563201751000 4 connected 5461-10922
05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563201749000 1 connected 0-5460
  • Save Configuration File

192.168.194.130:7000> CLUSTER SAVECONFIG
OK
192.168.194.130:7000> quit
[root@arslinux-01 ~]# cat /data/redis_data/7000/nodes_7000.conf
aa7d98cee9fca481caf8e1cdc06c1ff893693a23 192.168.194.132:7003@17003 slave 05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 0 1563201851698 5 connected
8b689873117d639562fb33044f2904454e936d31 192.168.194.130:7006@17006 slave 5ab4b80953ffe946608f288dad1d75e6136c7642 0 1563201849684 7 connected
2ec8052ab336ccab81a6ce69ca49c454fa2971f6 192.168.194.130:7002@17002 master - 0 1563201849000 2 connected 10923-16383
5ab4b80953ffe946608f288dad1d75e6136c7642 192.168.194.132:7007@17007 master - 0 1563201848675 7 connected
bac7f9d4a82091981dbc381d4b60d7677405e7e8 192.168.194.132:7005@17005 slave 2ec8052ab336ccab81a6ce69ca49c454fa2971f6 0 1563201849000 6 connected
992e0e4837ddc544f28f820066b75f17648aad2b 192.168.194.130:7004@17004 slave 62f3b3275922753035007d4dcc272c839baf45fd 0 1563201850690 4 connected
62f3b3275922753035007d4dcc272c839baf45fd 192.168.194.132:7001@17001 master - 0 1563201851000 4 connected 5461-10922
05078b35ab05d1d206f6a31d861e7a1eb8ff2e53 192.168.194.130:7000@17000 myself,master - 0 1563201847000 1 connected 0-5460
vars currentEpoch 7 lastVoteEpoch 0


extend

redis Sentinel https://segmentfault.com/a/1190000002680804

http://www.cnblogs.com/jaycekon/p/6237562.html

Posted by Barand on Mon, 15 Jul 2019 09:21:38 -0700