Redis configuration cluster, redis Cluster

Source: Internet
Author: User
Tags redis cluster

Redis configuration cluster, redis Cluster
Configure the cluster configuration environment in redis

Environment centos 6.6 redis 3.0.2

For convenience, copy three copies of the redis environment under a folder, with the suffix representing the listening port number.

Compile the source code, go to the src folder, make test, and check whether the test can pass, and then make

The core configuration of the configuration file. ports are 10002, respectively.

    port 10000    cluster-enabled yes    cluster-config-file nodes.conf    cluster-node-timeout 15000    appendonly yes

Run separately

    ./redis-server ../redis.conf 

Configure a cluster

     ./redis-trib.rb create --replicas 0 127.0.0.1:10000 127.0.0.1:10001 127.0.0.1:10002


Error !!!

A ruby environment is required.

    yum install ruby

After the installation is complete, an error is returned.

    ./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)        from ./redis-trib.rb:24

Install rubygems

yum install rubygems

... Continue Error Reporting

    /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'        from ./redis-trib.rb:25

Install interfaces for redis and ruby

    gem install redis

Installation successful, local test

Use a client to connect to the server with port 10000 and set some key-value

    redis-cli -c -p 10000

Auto redirect to port 10002 is displayed.

    set weixuan fengtang    -> Redirected to slot [12705] located at 127.0.0.1:10002    OK    127.0.0.1:10002> set zhangsan Mr.Zhang    OK    127.0.0.1:10002> 

Use another client to connect to the server with port 10001 and then obtain the data

    redis-cli -c -p 10001
    127.0.0.1:10001> get weixuan    -> Redirected to slot [12705] located at 127.0.0.1:10002    "fengtang"

You can see the redirection to 10002

Add Node

Create a node environment and change the port to 10003

Start this node

    ./redis-server ../redis.conf

Add Node

    ./redis-trib.rb add-node 127.0.0.1:10003 127.0.0.1:10000

The first parameter is the new instance we just started, and the second parameter is the existing node in the cluster.

    ./redis-trib.rb add-node 127.0.0.1:10003 127.0.0.1:10000 >>> Adding node 127.0.0.1:10003          to cluster 127.0.0.1:10000    Connecting to node 127.0.0.1:10000: OK    Connecting to node 127.0.0.1:10001: OK    Connecting to node 127.0.0.1:10002: OK    >>> Performing Cluster Check (using node 127.0.0.1:10000)    M: b4a5871c0344b54e8e767af80bd6594bae8b9228 127.0.0.1:10000       slots:0-5460 (5461 slots) master       0 additional replica(s)    M: c51a32d82bf42017f2ad50907f816678293f520e 127.0.0.1:10001       slots:5461-10922 (5462 slots) master       0 additional replica(s)    M: a03226abfa843c524602afe2e22ca8c68b023e0a 127.0.0.1:10002       slots:10923-16383 (5461 slots) master       0 additional replica(s)    [OK] All nodes agree about slots configuration.    >>> Check for open slots...    >>> Check slots coverage...    [OK] All 16384 slots covered.    Connecting to node 127.0.0.1:10003: OK    >>> Send CLUSTER MEET to node 127.0.0.1:10003 to make it join the cluster.    [OK] New node added correctly.

Added

Check whether the new node has been added.

    [root@java_yf_120 src]# redis-cli -c -p 10000    127.0.0.1:10000> cluster nodes    532634b9563dce5d5165b9c09d391da5fc73cdf9 127.0.0.1:10003 master - 0 1438165131300 0 connected    c51a32d82bf42017f2ad50907f816678293f520e 127.0.0.1:10001 master - 0 1438165130298 2 connected     5461-10922    b4a5871c0344b54e8e767af80bd6594bae8b9228 127.0.0.1:10000 myself,master - 0 0 1 connected      0-5460    a03226abfa843c524602afe2e22ca8c68b023e0a 127.0.0.1:10002 master - 0 1438165130799 3 connected 10923-16383    127.0.0.1:10000> 

You can see that the instance is successfully added.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.