Use Ruby's own tools for Redis cluster building

Source: Internet
Author: User
Tags redis cluster install redis

Use the source to install Redis and download the 3.0 version on the official website.

(1) Make sure the system is installed zlib, otherwise the gem install will report (no such file to load--zlib)

  1. #download: zlib-1.2. 6. Tar

  2. ./configure

  3. Make

  4. Make install

(2) Installing Ruby

  1. # ruby1. 9.2

  2. Cd/home/searat/ruby

  3. ./configure-prefix=/usr/local/ruby

  4. Make

  5. Make install

  6. CP Ruby/usr/local/bin

(3) Installation Rubygem

  1. # rubygems-1.8. tgz.

  2. CD /home/searat/gem

  3. Ruby Setup.rb

  4. CP Bin/gem/usr/local/bin

(4) Installation Gem-redis

    1. Gem Install Redis--version 3.0. 0



wget http://rubygems.org/gems/redis/versions/3.0.0   

    1. Gem install-l/home/searat/redis-3.0. 0. Gem

Processing of the Redis directory is then done

Use the source code after the installation directory as follows:

-bash-4.1$ tree-l 2/Home/searat/redis

/Home/searat/redis

├──bin

│├──dump.rdb

│├──redis-benchmark

│├──redis-check-aof

│├──redis-check-dump

│├──redis-cli

│├──redis-sentinel-Redis-server

│└──redis-server

├──conf

│├──dump.rdb

│└──redis.conf

├──log

│└──redis.log

└──redis_6379

Copy the REDIS-TRIB.RB to/Home/searat/redis/bin from the source package, and find the Create-cluster script from the source package, copy to/Home/searat/redis Under the/bin.

If you are using Create-cluster to create a Redis cluster on a single server, execute the create-cluster script directly.

If you create a Redis cluster on two or more servers, you can overwrite the Create-cluster script

-bash-4.1$ cat create-cluster #!/bin/bashport=$2    #端口号可以自己随意指定PORTNUM =3 # Define the number of port numbers replicas=1redis_home=/home/searat/redishost1=192.168.1.101host2=192.168.1.102hosts= "$HOST 1  $HOST 2 The declare -a hostgroup   #定义一个数组用来存放IP:P data in ORT form, using i=1if [  "$"  == when creating a cluster   "Start"  ]then    while [  $PORTNUM  -gt  "0"  ]; do         echo  "starting 127.0.0.1: $PORT"           $REDIS _home/bin/redis-server&nbsp ... /conf/redis_$port.confport=$ ((port+1)) portnum=$ ((PORTNUM-1))     done     exit 0fiif [  "$"  ==  "Stop"  ]then    while [   $PORTNUM  -gt  "0"  ]; do        echo  " stopping 127.0.0.1: $PORT "         $REDIS _home/bin/redis-cli -p  $PORT  shutdown nosave         port=$ ((port+1))         portnum=$ ((PORTNUM-1))      done    exit 0fiif [  "$"  ==  "create"  ]then     while [  $PORTNUM  -gt  "0"  ]; do         for host in  $HOSTS              do                 hostgroup[$i]= $host: $PORT                  i= ' expr  $i  + 1 '              done        port=$ ((PORT+1))          portnum=$ ((PORTNUM-1))     done    echo ${HOSTGROUP[*]}      $REDIS _home/bin/redis-trib.rb create --replicas 1 ${hostgroup[*]}     exit 0fiif [  "$"  ==  "clean"  ]then    rm - RF&NBSP, .... /LOG/*.LOG    RM -RF&NBSP, .... /DATA/APPENDONLY*.AOF    RM -RF&NBSP, .... /DATA/DUMP*.RDB    RM -RF&NBSP, .... /data/nodes*.conf    exit 0fiecho  "Usage: $0 [start|create|stop|clean" echo  "start       -- launch redis cluster  Instances. " echo  "create      -- create a cluster using  Redis-trib create. " echo  "stop        -- stop redis cluster  Instances. " echo  "clean &Nbsp;     -- remove all instances data, logs, configs. " 

As for redis_6379.conf, redis_6380.conf These configuration files can be configured in advance, or you can continue to append the code to automatically generate the configuration file in Create-cluster.

Redis Cluster Start-stop:/home/searat/redis/bin/create-cluster start/stop 6379

Create a cluster:/home/searat/redis/bin/create-cluster create 6379

If the following information is prompted, the creation is successful:

[OK] All nodes agree about Slotsconfiguration.

>>>check for open Slots ...

>>>check Slots Coverage ...

[OK] All 16384 slots covered.

Verify the master, slave information:

/home/searat/redis/bin/redis-cli-p $PORT cluster Nodes | Head-30

0784283914d088acd66c458f6ee32db337bc3daf192.168.0.101:6379 Master-0 1453248628585 2 connected 5461-10922

4eebf65f5b1f4ac4c547c47fd19f442b30f27396192.168.0.102: 6379myself,master -0 0 1 connected 0-5460

f0763f4d57ce2996f95fdc0693680a36bb004c98192.168.0.102: 6381 slave 0784283914D088ACD66C458F6EE32DB337BC3DAF 0 1453248627976 5 connected

d7461d15c6347a960a686530d3b72602a1fd855b192.168.0.101: 6380 slave 4eebf65f5b1f4ac4c547c47fd19f442b30f27396 0 1453248627976 4 connected

0977a10502ea3897c943ea88afe6133170ed09a8192.168.0.101: 6381 Master-0 1453248628585 7 connected 10923-16383

836cdfbf7938c983f4bae07197a413fc43f7a155192.168.0.102: 6380 slave 0977A10502EA3897C943EA88AFE6133170ED09A8 0 1453248627976 7 connected


yes! In this way, the Redis cluster is created by Create-cluster, which is convenient for management and easy to expand.



This article is from "Jacky Xin" blog, please be sure to keep this source http://jackyxin.blog.51cto.com/1976631/1736970

Use Ruby's own tools for Redis cluster building

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.