1.
Cluster
even with master-slave replication , each database holds all the data in the entire cluster, making it easy to create a cask effect.
Use Jedis implements a shard cluster , which is the client's control over which key data is saved to which database , and if it has to be manually migrated when horizontally expanding , And the need to stop the entire Cluster service , This is very bad .
one of the major features of the Redis3.0 version is the cluster (Cluster), and then we'll learn the cluster together.
1.0.
Architecture
(1) all the Redis nodes connected to each other (ping-pong mechanism ), internal use of binary protocols to optimize transmission speed and bandwidth .
(2) node's fail is not valid until more than half of the nodes in the cluster are detected as invalid .
(3) Client and Redis Node Direct Connect , no need for intermediate Proxy Layer . client does not need to connect all nodes of the cluster , Connect to any of the available nodes in the cluster
(4) Redis-cluster maps All physical nodes to [0-16383]slot(Slots), cluster is responsible for maintaining node <->slot<->value
1.1. Unzip the installation package
[Email protected] local]# pwd
/usr/local
[Email protected] redis]# TAR-ZXVF redis-3.0.2.tar.gz
[Email protected] redis]# ln-s redis-3.0.2 Redis
[Email protected] redis]# pwd
/usr/local/redis
[[email protected] redis]# make
[[email protected] redis]# make install Prefix=/usr/local/redis
# Create six instance directories
[Email protected] redis]# mkdir/usr/local/redis7001
[Email protected] redis]# mkdir/usr/local/redis7002
[Email protected] redis]# mkdir/usr/local/redis7003
[Email protected] redis]# mkdir/usr/local/redis7004
[Email protected] redis]# mkdir/usr/local/redis7005
[Email protected] redis]# mkdir/usr/local/redis7006
# Copy the software to the appropriate instance
[Email protected] redis]# pwd
/usr/local/redis
[Email protected] redis]# CP-RF */usr/local/redis7001
[Email protected] redis]# CP-RF */usr/local/redis7002
[Email protected] redis]# CP-RF */usr/local/redis7003
[Email protected] redis]# CP-RF */usr/local/redis7004
[Email protected] redis]# CP-RF */usr/local/redis7005
[Email protected] redis]# CP-RF */usr/local/redis7006
1.2.
Modifying a configuration file
1. set different ports, 7001, 7002, 7003, 7004, 7005, 7006
2, open the cluster, cluster-enabled Yes
3, Specify the configuration file of the cluster , cluster-config-file "nodes-xxxx.conf"
4. Open Redis background execution, daemonize Yes
5. Start the cluster
1.3.
Create a cluster1.3.1.
Installing the ruby environment
because redis-trib.rb is written in Ruby language, you need to install a ruby Environment .
Yum-y Install zlib Ruby RubyGems
Gem Install Redis
Manual Installation :
RZ upload redis-3.2.1.gem
Gem Install-l Redis-3.2.1.gem
1.3.2.
Create a cluster
first , go to the Redis installation package path :
cd/usr/local/src/redis/redis-3.0.1/src/
Execute command :
./redis-trib.rb Create--replicas 1 10.100.25.44:7001 10.100.25.44:7002 10.100.25.44:7003 10.100.25.44:7004 10.100.25.44:7005 10.100.25.44:7006
--replicas 0: Specifies the number of data from 0, if specified as 1, each cluster node will have a copy
Note : You cannot use 127.0.0.1 here , otherwise you cannot connect to the Jedis client when it is used!
Redis-trib usage :
1.3.3.
Cluster Detection
[Email protected] redis7001]# redis-cli-p 7001
127.0.0.1:7001> cluster Nodes
DBEC41C5A8406C18810A9962ED68068FBCF9AAAC 10.100.25.44:7005 Slave D277e9e7267b8e6f7da2e72b0d4070868c51bfe3 0 1538674374274 5 Connected
D42782BF3EAF1E130D0D694533F3E1BEA7E3EF2C 10.100.25.44:7003 master-0 1538674373770 3 connected 10923-16383
9a0ab8d1772787bde727b0e78b1b8db242f60d2b 10.100.25.44:7004 Slave 1e0d1bea4f1f95ca2d673bbbe342afa2646e942b 0 1538674376293 4 Connected
17d51731c87847ed5dd6d78146f68a899e0028ab 10.100.25.44:7006 Slave d42782bf3eaf1e130d0d694533f3e1bea7e3ef2c 0 1538674371251 6 Connected
D277e9e7267b8e6f7da2e72b0d4070868c51bfe3 10.100.25.44:7002 master-0 1538674375284 2 connected 5461-10922
1e0d1bea4f1f95ca2d673bbbe342afa2646e942b 10.100.25.44:7001 myself,master-0 0 1 connected 0-5460
Redis's 3 cluster installation