CentOS Build Redis Cluster

Source: Internet
Author: User
Tags redis cluster install redis

Cluster principle-redis-cluster architecture Diagram

Architectural details :

(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 the physical nodes to the [0-16383]slot , cluster is responsible for maintaining node< ->slot<->value

Redisthe cluster has built- in16384a hash slot, when needed in theRedisin the cluster, place aKey-valuewhen theRedisfirst toKeyUseCRC16The algorithm calculates a result and then turns the result to16384to find the remainder, so that eachKeywill correspond to a number in the0-16383between the hash slots,RedisThe hash slots are mapped to different nodes roughly equal to the number of nodes

Redis-cluster votes:Fault Tolerance

(1) The voting process is that all master in the cluster participates , if more than half of the Master node and master node communication exceeds (cluster-node-timeout) and the current Master node is considered to be dead .

(2): When is the entire cluster unavailable (cluster_state:fail)?

A:if the cluster arbitrarilyMasterHang off,and the currentMasterNoslave.Cluster EntryfailStatus,It can also be understood as a clusterSlotsMapping[0-16383]enter when not completedfailStatus. Ps:redis-3.0.0.rc1JoinCluster-require-full-coverageParameters,default off,failed to open cluster compatibility section.

B: if more than half of the cluster master hangs, regardless of whether there is a slave cluster into the fail State .

PS: when the cluster is unavailable , All operations on the cluster are not available, received ((Error) Clusterdown the cluster is down) error

1. Setting up the environment required for the cluster

Building a cluster requires the use of an official Ruby script.

You need to install Ruby 's environment.

Install Ruby

Yum Install Ruby

Yum Install RubyGems

Redis Cluster Management tool REDIS-TRIB.RB

[Email protected] ~]# CD redis-3.0.0

[[Email protected] redis-3.0.0]# CD src

[email protected] src]# ll *.RB

-rwxrwxr-x. 1 root root 48141 Apr 1 07:01 redis-trib.rb

[Email protected] src]#

redis-trib.rb script requires a ruby Package:

Needs to be uploaded to the Linux service.

To install Ruby Packages:

Gem Install Redis-3.0.0.gem

[Email protected] ~]# gem install Redis-3.0.0.gem

Successfully installed redis-3.0.0

1 Gem installed

Installing RI documentation for redis-3.0.0 ...

Installing RDOC documentation for redis-3.0.0 ...

gemhttp://download.csdn.net/detail/u012599988/8597787

2. Building a Cluster

Step One: Create 6 redis instances with port numbers from 7001~7006

Create a directory First

Dump.rdb is a snapshot of the state to save, and the other is aof save the command.

Step Two: Modify the redis configuration file

1. Modify the port number

2 . Open the comment in front of cluster-enable.

Next Replicate 6 nodes

Description

Redis cluster requires at least 3 primary nodes, each master node has a total of 6 nodes from the node

Replicas specified as 1 indicates that each master node has a slave node

Don't forget it. The port number of the 6 nodes has been changed.

Step three: Copy the Ruby script that created the cluster into the redis-cluster directory.

Then you need to copy the REDIS-TRIB.RB Cluster management tool under the Redis src directory to Redis-cluster

Fourth step: Launch 6 redis instances

Write a script to start a batch of 6 Redis nodes

Startall the script content

Files that are set to executable

Fifth step: Create the cluster.

./REDIS-TRIB.RB Create--replicas 1 192.168.188.131:7001 192.168.188.131:7002 192.168.188.131:7003 192.168.188.131:7004 192.168.188.131:7005 192.168.188.131:7006

[Email protected] redis-cluster]#/redis-trib.rb create--replicas 1 192.168.188.131:7001 192.168.188.131:7002 192.168.188.131:7003 192.168.188.131:7004 192.168.188.131:7005 192.168.188.131:7006
>>> Creating Cluster
Connecting to Node 192.168.188.131:7001:ok
Connecting to Node 192.168.188.131:7002:ok
Connecting to Node 192.168.188.131:7003:ok
Connecting to Node 192.168.188.131:7004:ok
Connecting to Node 192.168.188.131:7005:ok
Connecting to Node 192.168.188.131:7006:ok
>>> performing hash slots allocation on 6 nodes ...Connect 6 nodes successfully
Using 3 Masters:7001-7003 as the master node
192.168.188.131:7001
192.168.188.131:7002
192.168.188.131:7003
Adding replica 192.168.188.131:7004 to 192.168.188.131:70017004 as a slave node of 7001
Adding replica 192.168.188.131:7005 to 192.168.188.131:70027005 as a slave node of 7002
Adding replica 192.168.188.131:7006 to 192.168.188.131:70037006 as a slave node of 7003
m:5a8523db7e12ca600dc82901ced06741b3010076 192.168.188.131:7001
slots:0-5460 (5461 slots) Masterallocate 0-5460 slots to 7001 master nodes
M:bf6f0929044db485dea9b565bb51e0c917d20a53 192.168.188.131:7002
slots:5461-10922 (5462 slots) Masterallocate 5461-10922 slots to 7002 master nodes
M:c5e334dc4a53f655cb98fa3c3bdef8a808a693ca 192.168.188.131:7003
slots:10923-16383 (5461 slots) Masterallocate 10923-16383 slots to 7003 master nodes
s:2a61b87b49e5b1c84092918fa2467dd70fec115f 192.168.188.131:7004The 7004,7005,7006 is the same as the node slot and the master node, from which the node is backed up
Replicates 5a8523db7e12ca600dc82901ced06741b3010076
S:14848b8c813766387cfd77229bd2d1ffd6ac8d65 192.168.188.131:7005
Replicates bf6f0929044db485dea9b565bb51e0c917d20a53
s:3192cbe437fe67bbde9062f59d5a77dabcd0d632 192.168.188.131:7006
Replicates C5E334DC4A53F655CB98FA3C3BDEF8A808A693CA
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.188.131:7001)
m:5a8523db7e12ca600dc82901ced06741b3010076 192.168.188.131:7001
slots:0-5460 (5461 slots) Master
M:bf6f0929044db485dea9b565bb51e0c917d20a53 192.168.188.131:7002
slots:5461-10922 (5462 slots) Master
M:c5e334dc4a53f655cb98fa3c3bdef8a808a693ca 192.168.188.131:7003
slots:10923-16383 (5461 slots) Master
m:2a61b87b49e5b1c84092918fa2467dd70fec115f 192.168.188.131:7004
Slots: (0 slots) Master
Replicates 5a8523db7e12ca600dc82901ced06741b3010076
M:14848b8c813766387cfd77229bd2d1ffd6ac8d65 192.168.188.131:7005
Slots: (0 slots) Master
Replicates bf6f0929044db485dea9b565bb51e0c917d20a53
m:3192cbe437fe67bbde9062f59d5a77dabcd0d632 192.168.188.131: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.
[Email protected] redis-cluster]#

3. Test the cluster

[[email protected] redis-cluster]# redis01/redis-cli-h 192.168.188.131-p 7002-c- h is the specified ip-p specified port-C represents the cluster to be connected

Note: The cluster must be added with-C, otherwise set will appear (error) moved error

192.168.188.131:7002>
[Email protected] redis-cluster]# redis01/redis-cli-h 192.168.188.131-p 7002-c
192.168.188.131:7002> set a 100
-Redirected to Slots [15495] located at 192.168.188.131:7003
Ok
192.168.188.131:7003>

CentOS Build Redis Cluster

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.