Analysis of REDIS3 cluster installation

Source: Internet
Author: User
Original http://www.cnblogs.com/zhongkaijun/p/4728334.html

REDIS3.0 version after support cluster, specifically the Redis cluster I don't say much, see the Redis Chinese introduction.

First, direct access to Redis.io official website, download redis.tar.gz, now version 3.0.3, I have launched two Linux in the virtual machine to deploy Redis. 1. Download and unzip the package

cd/usr/local/

wget http://download.redis.io/releases/redis-3.0.3.tar.gz

TAR-ZXVF redis-3.0.3.tar.gz

MV redis-3.0.3 Redis 2. Compiling and installing

CD Redis

Make && make install

Some people here may encounter a bug that leads to compilation however (see below)

MAKE[1]: Entering directory '/redis/src '
CC adlist.o in
file included from adlist.c:34:
zmalloc.h:50:31: Error:jemalloc/jemalloc.h:no such file or directory
zmalloc.h:55:2: Error: #error "Newer version of Jemalloc require D "
make[1]: * * * [ADLIST.O] Error 1
make[1]: Leaving directory '/redis/src ' make
: * * * [ALL] Error 2

Because the Jemalloc memory allocator is not installed, you can install Jemalloc or direct input make MALLOC=LIBC && make install 3. Create a Redis node

We will create six nodes on both servers, 3 each, and 3 master 3 from.

1) Server1

cd/usr/local/

mkdir redis_cluster//Create cluster directory

mkdir 7000 7001 7002//For three nodes and their corresponding ports 7000 7001 7002

Create 7000 nodes as an example,

CD./7000

cp/usr/local/redis/redis.conf.///Copy to current 7000 directory

VI redis.conf//Edit configuration mainly modify a few parameters

Daemonize    Yes                          //redis background run
pidfile  /var/run/redis_7000.pid    //pidfile file corresponds to 7000
port  7000                                  //Port 7000
cluster-enabled  Yes                    //Open cluster   Note # remove
cluster-config-file  nodes.conf      //Cluster configuration profile for the  first time start auto
generate   cluster-node-timeout       //Request Timeout  setting 5 seconds enough
appendonly   Yes                        //aof log   on when needed to open, it will log each write operation logs

When configured, copy the modified configuration file to the 7001 7002 directory Accordingly, and note that the listener port 7001 7002 should be modified.

Next, start the service and go to the node directory

Execute Redis-server redis.conf in turn

You can see that the appendonly.aof nodes.conf is generated

Ps-ef | grep Redis to see if it started successfully

Root 885 0.8 0.2 129452 2620? SSL 20:10 0:21 redis-server *:7000 [cluster]

Root 887 0.8 0.2 129452 2616? SSL 20:10 0:21 redis-server *:7001 [cluster]

Root 893 0.8 0.2 128356 2612? SSL 20:10 0:21 redis-server *:7002 [cluster]

NETSTAT-TNLP | grep Redis can see the Redis listening port

TCP 0 0 0.0.0.0:7000 0.0.0.0:* LISTEN 885/redis-server *

TCP 0 0 0.0.0.0:7001 0.0.0.0:* LISTEN 887/redis-server *

TCP 0 0 0.0.0.0:7002 0.0.0.0:* LISTEN 893/redis-server *

TCP 0 0 0.0.0.0:17000 0.0.0.0:* LISTEN 885/redis-server *

TCP 0 0 0.0.0.0:17001 0.0.0.0:* LISTEN 887/redis-server *

TCP 0 0 0.0.0.0:17002 0.0.0.0:* LISTEN 893/redis-server *

In addition to seeing the port 700* set in the configuration file, we also have 700*+10000 (1700*), which is accessed by the client, which is accessed between nodes within the cluster.

Note that the cluster is built between multiple servers, and if the firewall is on, you need to set iptables open all ports above.

2) Server2

Steps and Server1, set the port 7003 7004 7005 4. Create a cluster

We are ready to build the Redis node for the cluster, then we will concatenate the nodes together to build the cluster. The official provides a tool: Redis-trib.rb (/USR/LOCAL/REDIS/SRC/REDIS-TRIB.RB) look at the suffix to know that this bird thing can not be directly executed, it is a program written in Ruby, so we have to install Ruby.

Yum-y install ruby Ruby-devel rubygems rpm-build//The Internet is so installed, just play it like this.

Then use the Gem command to install the Redis interface gem looks like a toolkit for Ruby anyway, that's right.

Gem Install Redis//Wait a minute, please.

Of course, it is easy to operate and both servers are installed.

The above steps are done, then run the REDIS-TRIB.RB

/usr/local/redis/src/redis-trib.rb

Usage:redis-trib <command> <options> <arguments ...>
  reshard         host:port
    --to <arg >
    --yes
    --slots <arg>
    --from <arg>
  check           host:port
  call            host:port Command arg arg. Arg
  set-timeout     host:port milliseconds
  add-node        new_host:new_port existing_host:existing_ Port
    --master-id <arg>
    --slave
  del-node        host:port node_id
  fix             Host:port
  import          host:port
    --from <arg>
  help            (Show this help)
  create          Host1:port1 ... hostn:portn
    --replicas <arg> for
check, fix, Reshard, Del-node, set-timeout can specify the host a nd port of any working node in the cluster.

See this, should understand, is to rely on the above operations to complete the Redis cluster build.

Confirm that all the nodes are started, and then create them using the parameter created (created in Server1)

/USR/LOCAL/REDIS/SRC/REDIS-TRIB.RB Create--replicas 1 127.0.0.1:7000 127.0.0.1:7001 192.168.1.199:7003 192.168.1. 199:7,004 192.168.1.199:7005 127.0.0.1:7002

EXPLANATION,--replicas 1 means that each master node is automatically assigned a slave node with 6 nodes, and the program generates 3 master (master) 3 slave (from) according to a certain rule

The firewall that has been previously warned must open the listening port, otherwise it will fail to create.

Running, prompt can I setthe above configuration? (Type ' yes ' to accept): Yes//Enter Yes

Next prompt waiting forthe cluster to join .... Installation of the time here has been waiting and so on, no response, silly half a day, look at this hint above a sentence, sending Cluster Meet Message to join the Cluster.

This is clear, I just started on a server to match, also do not need to wait, here also need to run to Server2 to do some of these operations.

In Server2, Redis-cli-c-p 700* Enter the Client command window of each Redis node respectively, enter cluster meet 192.168.1.197 7000 ...

Back to Server1, it has been created.

Take a look at/usr/local/redis/src/redis-trib.rb check 127.0.0.1:7000

Here the cluster has been initially built. 5. Testing

1) Get and set data

Redis-cli-c-P 7000

Enter Command window, direct set Hello Howareyou

switch directly to the corresponding slot node based on the hash match.

To illustrate, the Redis cluster consists of 16,383 slots, distributed across multiple nodes through shards, and read-write occurs on the master node.

2) Hypothesis Testing

Brother Decisive first put Server2 service down, (Server2 have 1 master, 2 slave), run back to Server1, see what happened, Server1 3 nodes are all master, the other several Server2 disappeared

Test it, still no problem, the cluster can still continue to work.

Cause: The Redis cluster is fault tolerant through an election, ensuring that a server hangs up and running, and that this election is a total of more than half of the master found other master hangs, the other corresponding slave nodes will be upgraded to master.

Question: What to do if the Server1 is hanging.    Brother tried, cluster is down!! There is no way, more than half hang it can not save, the whole cluster will not work. If there are three servers, each two master, remember the corresponding master-slave node

Do not put in a server, do not ask me why I use the brain to think about, cross-configuration with each other, which is not OK, you have to say at the same time two crash, oh da ...

3) About consistency

I'm not so bold to take Redis to do database persistence data, just to do the cache, the official website said very clearly, Redis Cluster is not able to guarantee strong consistency .

4) Practice in the project

Project is Java, chose Jedis This development package, brother first to run to see, wrote here. What's the big catch?


Personal thoughts:

You can configure 4 server 3 instances per server

Then configure 6 Master 6 slave


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.