Redis Multi-machine cluster deployment documentation (CENTOS6.2)
(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)
10.168.32.116:6379
10.168.32.117:6379
10.168.32.118:6379
10.168.32.119:6379
10.168.32.120:6379
10.168.32.121:6379
Before you install the cluster, you need to install the Ruby environment on the server.
Yum install-y Ruby RubyGems
Gem Install Redis
Download the Redis version,
#git Clone Https://github.com/antirez/redis.git
#mv Redis/usr/local/redis
#cd/usr/local/redis
#make && make Install
Modify the basic configuration required for the configuration cluster, and configure the rest, as needed
#vi/usr/local/redis/redis.conf
Bind 10.168.32.116
Port 6379
Daemonize Yes
cluster-enabled Yes
Cluster-config-file nodes.conf
AppendOnly Yes
Modify these lines, the redis.conf distribution to the rest of the server, all the server configuration can be exactly the same, bind is the host IP (if you are experimenting on the same server, need to modify port, each Redis uses a separate port)
After configuring synchronization, start Redis for all servers
Redis-server/usr/local/redis/redis.conf
To perform a Redis create cluster command to create a cluster:
#./redis-trib.rb Create--replicas 1 10.168.32.116:6379 10.168.32.117:6379 10.168.32.118:6379 10.168.32.119:6379 10.168.32.120:6379 10.168.32.121:6379
>>> Creating Cluster
Connecting to Node 10.168.32.116:6379:ok
Connecting to Node 10.168.32.117:6379:ok
Connecting to Node 10.168.32.118:6379:ok
Connecting to Node 10.168.32.119:6379:ok
Connecting to Node 10.168.32.120:6379:ok
Connecting to Node 10.168.32.121:6379:ok
>>> performing hash slots allocation on 6 nodes ...
Using 3 Masters:
10.168.32.121:6379
10.168.32.120:6379
10.168.32.119:6379
Adding replica 10.168.32.118:6379 to 10.168.32.121:6379
Adding replica 10.168.32.117:6379 to 10.168.32.120:6379
Adding replica 10.168.32.116:6379 to 10.168.32.119:6379
S:F3314ECDA2EF4EA0EC140E06DE3E4BF656A5E71B 10.168.32.116:6379
Replicates a5a22ba976c05b1d495812241a8dd10a5d4a5b42
S:314F957E1021B0C262E635AD4FEEB340DFE5955C 10.168.32.117:6379
Replicates 9880ecc98cde59e0d6341ba7c54bbcae9b27c877
s:07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379
Replicates B7F33A1B733FE4A51447A788E334FAB625A984BC
M:a5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379
slots:10923-16383 (5461 slots) Master
m:9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379
slots:5461-10922 (5462 slots) Master
M:B7F33A1B733FE4A51447A788E334FAB625A984BC 10.168.32.121:6379
slots:0-5460 (5461 slots) Master
Can I Set the above configuration? (Type ' yes ' to accept): Yes this input 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 10.168.32.116:6379)
M:F3314ECDA2EF4EA0EC140E06DE3E4BF656A5E71B 10.168.32.116:6379
Slots: (0 slots) Master
Replicates a5a22ba976c05b1d495812241a8dd10a5d4a5b42
M:314F957E1021B0C262E635AD4FEEB340DFE5955C 10.168.32.117:6379
Slots: (0 slots) Master
Replicates 9880ecc98cde59e0d6341ba7c54bbcae9b27c877
m:07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379
Slots: (0 slots) Master
Replicates B7F33A1B733FE4A51447A788E334FAB625A984BC
M:a5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379
slots:10923-16383 (5461 slots) Master
m:9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379
slots:5461-10922 (5462 slots) Master
M:B7F33A1B733FE4A51447A788E334FAB625A984BC 10.168.32.121:6379
slots:0-5460 (5461 slots) Master
[OK] All nodes agree about slots configuration.
>>> Check for open Slots ...
>>> Check Slots Coverage ...
[OK] All 16384 slots covered.
This is where the Redis cluster is built successfully!
Execute command redis-cli-c-P 6379 cluster nodes, view cluster nodes
[Email protected] src]# redis-cli-c-H 10.168.32.116-p 6379 cluster nodes
314f957e1021b0c262e635ad4feeb340dfe5955c 10.168.32.117:6379 Slave 9880ecc98cde59e0d6341ba7c54bbcae9b27c877 0 1425114266105 5 Connected
A5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379 master-0 1425114267205 4 connected 10923-16383
07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379 Slave B7F33A1B733FE4A51447A788E334FAB625A984BC 0 1425114265605 6 Connected
B7F33A1B733FE4A51447A788E334FAB625A984BC 10.168.32.121:6379 master-0 1425114266205 6 connected 0-5460
f3314ecda2ef4ea0ec140e06de3e4bf656a5e71b 10.168.32.116:6379 Myself,slave a5a22ba976c05b1d495812241a8dd10a5d4a5b42 0 0 1 connected
9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379 master-0 1425114266505 5 Connected 5461-10922
7: Use the REDIS-CLI command to enter the cluster environment
Redis-cli-c-H 10.168.32.117-p 6379 |
Redis Cluster Operations Node
1: Add a node, IP 10.168.32.122, Port 6379
Start by starting the node you want to add
cd/usr/local/redis/ #vi/usr/local/redis/redis.conf Bind 10.168.32.122 Port 6379 Start Redis Redis-server/usr/local/redis/redis.conf To add a new node to the cluster |
Cd/usr/local/redis/src
[Email protected] src]#/redis-trib.rb add-node 10.168.32.122:6379 10.168.32.116:6379
>>> Adding node 10.168.32.122:6379 to cluster 10.168.32.116:6379
Connecting to Node 10.168.32.116:6379:ok
Connecting to Node 10.168.32.117:6379:ok
Connecting to Node 10.168.32.119:6379:ok
Connecting to Node 10.168.32.118:6379:ok
Connecting to Node 10.168.32.121:6379:ok
Connecting to Node 10.168.32.120:6379:ok
>>> performing Cluster Check (using node 10.168.32.116:6379)
S:F3314ECDA2EF4EA0EC140E06DE3E4BF656A5E71B 10.168.32.116:6379
Slots: (0 slots) Slave
Replicates a5a22ba976c05b1d495812241a8dd10a5d4a5b42
S:314F957E1021B0C262E635AD4FEEB340DFE5955C 10.168.32.117:6379
Slots: (0 slots) Slave
Replicates 9880ecc98cde59e0d6341ba7c54bbcae9b27c877
M:a5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379
slots:10923-16383 (5461 slots) Master
1 additional replica (s)
s:07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379
Slots: (0 slots) Slave
Replicates B7F33A1B733FE4A51447A788E334FAB625A984BC
M:B7F33A1B733FE4A51447A788E334FAB625A984BC 10.168.32.121:6379
slots:0-5460 (5461 slots) Master
1 additional replica (s)
m:9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379
slots:5461-10922 (5462 slots) Master
1 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 10.168.32.122:6379:ok
>>> Send CLUSTER MEET to node 10.168.32.122:6379 to make it join the CLUSTER.
[OK] New node added correctly.
View cluster Nodes
[Email protected] src]# redis-cli-c-H 10.168.32.116-p 6379 cluster nodes
314f957e1021b0c262e635ad4feeb340dfe5955c 10.168.32.117:6379 Slave 9880ecc98cde59e0d6341ba7c54bbcae9b27c877 0 1425114360107 5 Connected
38c2f060533c24698334a16b26f678ae6bd7ec41 10.168.32.122:6379 master-0 1425114361107 0 connected
A5a22ba976c05b1d495812241a8dd10a5d4a5b42 10.168.32.119:6379 master-0 1425114361507 4 connected 10923-16383
07634642c88fdf1b886d3db87dedc4b9857fce7c 10.168.32.118:6379 Slave B7F33A1B733FE4A51447A788E334FAB625A984BC 0 1425114362507 6 Connected
B7F33A1B733FE4A51447A788E334FAB625A984BC 10.168.32.121:6379 master-0 1425114360507 6 connected 0-5460
f3314ecda2ef4ea0ec140e06de3e4bf656a5e71b 10.168.32.116:6379 Myself,slave a5a22ba976c05b1d495812241a8dd10a5d4a5b42 0 0 1 connected
9880ecc98cde59e0d6341ba7c54bbcae9b27c877 10.168.32.120:6379 master-0 1425114362107 5 Connected 5461-10922
To delete a Redis cluster node
REDIS-TRIB.RB Del-node Host:port node_id
./redis-trib.rb Del-node 10.168.32.122:6379 38c2f060533c24698334a16b26f678ae6bd7ec41
Redis Multi-machine cluster deployment documentation