Redis cluster construction in Linux environment

Source: Internet
Author: User
Tags redis cluster install redis

Original: http://blog.csdn.net/yj327243832a/article/details/52785100

Original: http://www.linuxidc.com/Linux/2015-08/121845.htm


LogFile "/usr/local/redis_cluster/log/"

Dir/usr/local/redis_cluster

Create a log folder under the Redis_cluster directory


./redis-server/usr/local/redis_cluster/7004/redis.conf

./redis-trib.rb Create--replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 192.168.1.248:7003 192.168.1.248:7004 192.168.1.248:7005


./redis-trib.rb Create--replicas 1 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 192.168.1.249:7000 192.168.1.249:7001 192.168.1.249:7002


./redis-trib.rb Create--replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

(To make the cluster work at least 3 primary nodes, here we will create 6 Redis nodes, of which three are the primary node, three are slave nodes, the corresponding Redis node IP and port correspondence is as follows)

127.0.0.1:7000
127.0.0.1:7001

127.0.0.1:7002

127.0.0.1:7003

127.0.0.1:7004

127.0.0.1:7005

1. Installing Redis

Upload server, unzip, compile

TAR-ZXVF redis-3.2.1.tar.gz

CD redis-3.2.1

Make

After compilation

CD src

Copy

Redis-server

Redis-cli

Two files

2. Create a cluster directory

Set up the cluster corresponding folder Rediscluster

Build 6 subfolders in this folder for r7000, r7001, r7002, r7003, r7004, r7005

Paste the file you copied in the first step into the 6 subfolders above, and authorize

chmod 775 Redis-cli

chmod 775 Redis-server

Create a file in each subfolder redis.conf

File contents

Port 7000

cluster-enabled Yes

Cluster-config-file nodes.conf

Cluster-node-timeout 5000

AppendOnly Yes

Daemonize Yes

Bind 192.168.*.*
Protected-mode No

#这两个配置不加上, no other machine can access

Each file has a different port number, 7000, 7001, 7002, 7003, 7004, 7005, respectively.

3. Start each of the six Redis instances separately

to the corresponding folder to execute the

./redis-server redis.conf

Query the Redis process as follows

[Email protected] redis]# Ps-ef|grep Redis

Root 11092 1 0 14:35? 00:00:00./redis-server *:7000 [cluster]

Root 11296 1 0 14:46? 00:00:00./redis-server *:7001 [cluster]

Root 11403 1 0 14:53? 00:00:00./redis-server *:7002 [cluster]

Root 11441 1 0 14:55? 00:00:00./redis-server *:7003 [cluster]

Root 11486 1 0 14:57? 00:00:00./redis-server *:7004 [cluster]

Root 11532 1 0 14:59? 00:00:00./redis-server *:7005 [cluster]

Root 11545 11135 0 15:00 pts/2 00:00:00 grep--color=auto Redis

4. Create a Redis cluster

Execute under the SRC folder of the installation path

./redis-trib.rb Create--replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

[Email protected] src]#/redis-trib.rb create--replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

/usr/bin/env:ruby:no such file or directory

Error:/usr/bin/env:ruby:no such file or directory

Ruby's environment is required because it is a script that executes Ruby

Installing the ruby Environment

[[email protected] src]# Yum install Ruby

Execute the Create cluster command again

[Email protected] src]#/redis-trib.rb create--replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in ' require ': Cannot load such file--Redis (Loaderror)

From/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in ' require '

From./redis-trib.rb:25:in ' <main> '

Error cannot load such file-Redis (loaderror) ...

Missing RubyGems component, installing with Yum

[email protected] src]# Yum install RubyGems

Execute the Create cluster command again

[Email protected] src]#/redis-trib.rb create--replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in ' require ': Cannot load such file--Redis (Loaderror)

From/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in ' require '

From./redis-trib.rb:25:in ' <main> '

Missing Redis and Ruby interfaces, using GEM installation

Gem Install Redis

After you create the cluster command again, the cluster creation succeeds when prompted to enter Yes

[Email protected] src]#/redis-trib.rb create--replicas 1 192.168.8.21:7000 192.168.8.21:7001 192.168.8.21:7002 192.168.8.21:7003 192.168.8.21:7004 192.168.8.21:7005

>>> Creating Cluster

>>> performing hash slots allocation on 6 nodes ...

Using 3 Masters:

192.168.8.21:7000

192.168.8.21:7001

192.168.8.21:7002

Adding replica 192.168.8.21:7003 to 192.168.8.21:7000

Adding replica 192.168.8.21:7004 to 192.168.8.21:7001

Adding replica 192.168.8.21:7005 to 192.168.8.21:7002

M:EF86D6276BB1A8BBAB07A1BD4FF8DC3F54EA73A1 192.168.8.21:7000

slots:0-5460 (5461 slots) Master

m:087d6d2f129f00262444d5bfc012b51239ee1636 192.168.8.21:7001

slots:5461-10922 (5462 slots) Master

M:67bc3416a311770682abaffde395fbfa34d7b5b0 192.168.8.21:7002

slots:10923-16383 (5461 slots) Master

S:22DCEAE7E42FF41E098854C476EC0AF27A2CBFBC 192.168.8.21:7003

Replicates EF86D6276BB1A8BBAB07A1BD4FF8DC3F54EA73A1

S:3231ff554f46b0310db5ece8a589be96b3098bed 192.168.8.21:7004

Replicates 087d6d2f129f00262444d5bfc012b51239ee1636

s:167b9645c6f1f347363c4f397c84eca666bd0456 192.168.8.21:7005

Replicates 67bc3416a311770682abaffde395fbfa34d7b5b0

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.8.21:7000)

M:EF86D6276BB1A8BBAB07A1BD4FF8DC3F54EA73A1 192.168.8.21:7000

slots:0-5460 (5461 slots) Master

m:087d6d2f129f00262444d5bfc012b51239ee1636 192.168.8.21:7001

slots:5461-10922 (5462 slots) Master

M:67bc3416a311770682abaffde395fbfa34d7b5b0 192.168.8.21:7002

slots:10923-16383 (5461 slots) Master

M:22DCEAE7E42FF41E098854C476EC0AF27A2CBFBC 192.168.8.21:7003

Slots: (0 slots) Master

Replicates EF86D6276BB1A8BBAB07A1BD4FF8DC3F54EA73A1

M:3231ff554f46b0310db5ece8a589be96b3098bed 192.168.8.21:7004

Slots: (0 slots) Master

Replicates 087d6d2f129f00262444d5bfc012b51239ee1636

m:167b9645c6f1f347363c4f397c84eca666bd0456 192.168.8.21:7005

Slots: (0 slots) Master

Replicates 67bc3416a311770682abaffde395fbfa34d7b5b0

[OK] All nodes agree about slots configuration.

>>> Check for open Slots ...

>>> Check Slots Coverage ...

[OK] All 16384 slots covered.

5. Testing

Using the REDIS-CLI command to enter a clustered environment

./redis-cli-c-P 7000

nodes.conf File Contents

5e21c3a40f5b875d1f46724febc91059ccf3f36c 127.0.0.1:7004 Slave 00158021c8af59f49ce83605601d79ef69dfb515 0 1476083335844 5 Connected

bebc7ad0769b63d5dad22f59cf7e11e8eff8142e 127.0.0.1:7003 Slave 2102328b7c064ece181bf431ae983f936770aef6 0 1476083334841 4 Connected

D264a13fb4968cd93c3b700050e38c16000ee0ed 127.0.0.1:7005 Slave 086e344b0e6fdee5e0e896c040aadd2cef32f6d9 0 1476083333841 6 Connected

086E344B0E6FDEE5E0E896C040AADD2CEF32F6D9 127.0.0.1:7002 master-0 1476083335744 3 connected 10923-16383

2102328b7c064ece181bf431ae983f936770aef6 127.0.0.1:7000 myself,master-0 0 1 connected 0-5460

00158021c8af59f49ce83605601d79ef69dfb515 127.0.0.1:7001 master-0 1476083334341 2 connected 5461-10922

VARs Currentepoch 6 Lastvoteepoch 0

Redis cluster construction in Linux environment

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.