Shenzhen letter lion Redis cluster

1 lesson plan
lesson plan:
1, content management features add the cache.
a) using caching tools do redis
b) for system availability, call the shots need redis prepared. Use redis do fragmentation cluster. Build Redis cluster.

2 Use redis do caching
2.1 install redis
 Release Notes
This tutorial uses redis3.2.9 version. 3.2.9 version mainly adds redis clustering capabilities.
Installation prerequisites:
you need to install gcc: yum install gcc-c ++

1, redis download the source package.
2, the source package uploaded to the server linux
3, extract the source packet
the tar -zxvf Redis-3.2.9.tar.gz -C / usr / the src
CD /usr/src/redis-3.2.9/
the make
the make the install
[the root @ bogon redis-3.0.0] # make install PREFIX = / usr / local / redis

2.2 Starting Redis
. 1, the front end of the startup mode
CD /usr/src/redis-3.2.9/utils
./install_server.sh
LN /etc/init.d/redis_6379 -s / usr / local / bin / Redis
Redis Start
default front end startup mode, the port is 6379
2, the rear end of the boot
1) from redis redis.conf source directory to the directory of the redis installation.
2) modify the configuration file (different for each IP server other node, the other is the same)
the bind 192.168.180.100
. 3) [@ bogon the root bin] # ./redis-server redis.conf

2.3 Redis common commands
127.0.0.1:6379> SET A 10
the OK
127.0.0.1:6379> GET A
"10"

2.4 common data type
String
Hash
List
the Set
SortedSet

Build 3 Redis Cluster
3.1 Redis cluster concepts
3.1.1 redis-cluster architecture diagram

Here Insert Picture Description
redis-cluster mapping all of the physical node to [0-16383] the slot, cluster maintains Node <-> slot <-> value
Redis cluster built 16384 hash slot, when a key needs to be placed in the cluster Redis when -value, Redis crc16 algorithm calculates a first use of the key results, and the results of the remainder number of 16384, such that each key will correspond to a hash slot number between 0-16383, redis will be substantially uniform according to the number of nodes in the hash slot mapped to different nodes

Here Insert Picture Description
Key: a
calculation of a hash value, for example, a value of the grooves 100, 100 on server1, it should be placed in a server1.

Key: Hello
the Hash value: 10032 on server2 this groove. Hell you can and should exist server2.

3.1.2 redis-cluster voting: Fault Tolerance

Here Insert Picture Description
(1) led the voting process is the master of all involved in the cluster, if more than half of the master node to communicate with the master over (cluster-node-timeout), that the current master node hang.
(2): When the entire cluster is unavailable ( cluster_state: fail)?
a:. If the cluster master hang any, and the current master does not fail to enter a state slave cluster, the cluster is also to be understood that slot mapping [0-16383] is not completely fail state when entering ps:. redis-3.0 .0.rc1 added cluster-require-full-coverage parameters, off by default, open cluster compatible partial failure.
b: If the cluster master hang up more than half, regardless of whether slave cluster fail to enter the state.
PS: when the cluster is unavailable, All operations are available on the cluster do not receive ((error) CLUSTERDOWN the cluster is down) error

Our 3.2 cluster structure
in the cluster is a cluster of three nodes, each node has a main one. Take six virtual machines.
Building a distributed pseudo-cluster, using six redis instance simulated.

3.3 to build a cluster environment needed
redis 1. On each server are installed
on each server to modify the main configuration file /etc/redis/6379.conf vim
Cluster-Enabled yes
Cluster Nodes-config-File-6379.conf
2. In a use a script on the server to create the cluster
replication redis-3.2.0.gem to /
install Ruby
yum -y install RubyGems Ruby
GEM install --version Redis 3.2.0
cd /usr/src/redis-3.2.9/src
./redis -trib.rb create -replicas 1 192.168.180.100:6379 192.168.180.110:6379 192.168.180.120:6379 192.168.180.130:6379 192.168.180.140:6379 192.168.180.150:6379

Creating cluster
Connecting to node 192.168.180.100:6379: OK
Connecting to node 192.168.180.110:6379: OK
Connecting to node 192.168.180.120:6379: OK
Connecting to node 192.168.180.130:6379: OK
Connecting to node 192.168.180.140:6379: OK
Connecting to node 192.168.180.150:6379: OK

Performing hash slots allocation on 6 nodes…
Using 3 masters:
192.168.180.100:6379
192.168.180.110:6379
192.168.180.120:6379
………….
Can I set the above configuration? (type ‘yes’ to accept): yes

Updated the Configuration Nodes
the Assign A Different config Epoch to the each the Node
Sending messages to the Join at The MEET CLUSTER Cluster
Waiting for at The Cluster to the Join ... please wait timeout // If each node performs:
-p port redis-cli -h node IP - flushall and cluster reset

Performing Cluster Check (using node 192.168.25.153:7001)
M: 5a8523db7e12ca600dc82901ced06741b3010076 192.168.25.153:7001
slots:0-5460 (5461 slots) master
M: bf6f0929044db485dea9b565bb51e0c917d20a53 192.168.25.153:7002
slots:5461-10922 (5462 slots) master
M: c5e334dc4a53f655cb98fa3c3bdef8a808a693ca 192.168.25.153:7003
slots:10923-16383 (5461 slots) master
M: 2a61b87b49e5b1c84092918fa2467dd70fec115f 192.168.25.153:7004
slots: (0 slots) master
replicates 5a8523db7e12ca600dc82901ced06741b3010076
M: 14848b8c813766387cfd77229bd2d1ffd6ac8d65 192.168.25.153:7005
slots: (0 slots) master
replicates bf6f0929044db485dea9b565bb51e0c917d20a53
M: 3192cbe437fe67bbde9062f59d5a77dabcd0d632 192.168.25.153:7006
slots: (0 slots) master
replicates c5e334dc4a53f655cb98fa3c3bdef8a808a693ca
[OK] All nodes agree about slots configuration.

Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.
[root@bogon redis-cluster]#

3.4 Test cluster
Redis-cli -p 6379 -c -h 192.168180.100
the SET CentOS 7.3
GET CentOS
3.5 closed Redis
redis01 / Redis-cli the shutdown -p 6379

3.6 Redis client
3.6.1 Redis-cli
own client. Use the most.

Published 29 original articles · won praise 0 · Views 582

Guess you like

Origin blog.csdn.net/drrui520/article/details/105297500