Detailed analysis of Redis cluster cluster installation configuration

Source: Internet
Author: User
Tags documentation mkdir redis ruby on rails redis cluster install redis redis server


The Redis cluster is an assembly that provides data sharing between nodes in multiple Redis. redis3.0 Previously, only support master-slave synchronization, if the main hang, write on the problem. 3.0 will be a good way to help us solve this problem.
At present, Redis 3.0 is not stable, if you want to use in the production environment, be cautious.

One, Redis server description

192.168.10.219 6379
192.168.10.219 6380
192.168.10.219 6381

192.168.10.220 6382
192.168.10.220 6383
192.168.10.220 6384
It takes at least three primary nodes for the cluster to function properly, but it is strongly recommended to use six nodes when the cluster functionality is first tested: Three are primary, while the remaining three are the nodes from each master node. All with two machines, open 6 Redis process, simulate 6 machines.

Second, install Ruby,rubygems

# yum-y Install gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel gcc-c++ A Utomake autoconf

# yum-y Install ruby RubyGems//install ruby RubyGems

Exchange source
# Gem Source-l
# Gem Source--remove http://rubygems.org/
# Gem Sources-a http://ruby.taobao.org/
# Gem Source-l

# gem Install Redis--version 3.0.0//Installation Gem_redis
Successfully installed redis-3.0.0
1 Gem installed
Installing RI documentation for redis-3.0.0 ...
Installing RDOC documentation for redis-3.0.0 ...
Previously wrote a Ruby on Rails article, please refer to: CentOS Ruby on Rails apache MySQL installation configuration detailed
People who like to compile manually, you can refer to this article to install Ruby.

Third, install redis3.0.0

1, install Redis

# wget http://download.redis.io/releases/redis-3.0.0.tar.gz
# TAR-XVZF Redis-3.0.0.tar.gz
# CD redis-3.0.0
# Make && make install
# CD SRC
# CP Redis-trib.rb/usr/local/bin

# Mkdir/etc/redis
# Mkdir/var/log/redis
The above operation must first in the two machines above all operation good.

2, configure Redis

[Root@slave2 redis-3.0.0]# Vim redis.conf//Extract root directory, have redis.conf, make the following modifications
Port 6379
Pidfile/var/run/redis-6379.pid
Dbfilename Dump-6379.rdb
Appendfilename "Appendonly-6379.aof"
Cluster-config-file nodes-6379.conf
cluster-enabled Yes
Cluster-node-timeout 5000
AppendOnly Yes

3,copy the configuration file and modify the port

# CP Redis.conf/etc/redis/redis-6379.conf
# CP Redis.conf/etc/redis/redis-6380.conf
# CP Redis.conf/etc/redis/redis-6381.conf

# SCP redis.conf 192.168.10.220:/etc/redis/redis-6382.conf
# SCP redis.conf 192.168.10.220:/etc/redis/redis-6383.conf
# SCP redis.conf 192.168.10.220:/etc/redis/redis-6384.conf

# sed-i "S/6379/6380/g"/etc/redis/redis-6380.conf
# sed-i "S/6379/6381/g"/etc/redis/redis-6381.conf

# sed-i "S/6379/6382/g"/etc/redis/redis-6382.conf
# sed-i "S/6379/6383/g"/etc/redis/redis-6383.conf
# sed-i "S/6379/6384/g"/etc/redis/redis-6384.conf
Copy the configuration files to two machines and replace the ports:

# cat redis-6380.conf |awk ' {if ($!~/^$/&& $!~/#/) {print $}} ' |grep 6380
Pidfile/var/run/redis-6380.pid
Port 6380
Dbfilename Dump-6380.rdb
Appendfilename "Appendonly-6380.aof"
Cluster-config-file nodes-6380.conf
There are 5 places to modify ports

4, Start and view Redis

# redis-server/etc/redis/redis-6379.conf >/var/log/redis/redis-6379.log 2>&1 &
# redis-server/etc/redis/redis-6380.conf >/var/log/redis/redis-6380.log 2>&1 &
# redis-server/etc/redis/redis-6381.conf >/var/log/redis/redis-6381.log 2>&1 &

# redis-server/etc/redis/redis-6382.conf >/var/log/redis/redis-6382.log 2>&1 &
# redis-server/etc/redis/redis-6383.conf >/var/log/redis/redis-6383.log 2>&1 &
# redis-server/etc/redis/redis-6384.conf >/var/log/redis/redis-6384.log 2>&1 &

# NETSTAT-TPNL |grep Redis
TCP 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 7298/redis-server *
TCP 0 0 0.0.0.0:6380 0.0.0.0:* LISTEN 7299/redis-server *
TCP 0 0 0.0.0.0:6381 0.0.0.0:* LISTEN 7304/redis-server *
TCP 0 0 0.0.0.0:16379 0.0.0.0:* LISTEN 7298/redis-server *
TCP 0 0 0.0.0.0:16380 0.0.0.0:* LISTEN 7299/redis-server *
TCP 0 0 0.0.0.0:16381 0.0.0.0:* LISTEN 7304/redis-server *
TCP 0 0::: 6379:::* LISTEN 7298/redis-server *
TCP 0 0::: 6380:::* LISTEN 7299/redis-server *
TCP 0 0::: 6381:::* LISTEN 7304/redis-server *
TCP 0 0::: 16379:::* LISTEN 7298/redis-server *
TCP 0 0::: 16380:::* LISTEN 7299/redis-server *
TCP 0 0::: 16381:::* LISTEN 7304/redis-server *

[Root@slave2 redis]# ll/etc/redis/

Total Dosage 156

-rw-r--r--1 root 0 April 23:54 appendonly-6379.aof
-rw-r--r--1 Root 0 May 1 00:08 appendonly-6380.aof
-rw-r--r--1 Root 0 May 1 00:08 appendonly-6381.aof
-rw-r--r--1 root 18 May 1 00:08 Dump-6379.rdb
-rw-r--r--1 root 18 May 1 00:08 Dump-6380.rdb
-rw-r--r--1 root 18 May 1 00:08 Dump-6381.rdb
-rw-r--r--1 root 763 May 1 00:08 nodes-6379.conf
-rw-r--r--1 root 763 May 1 00:08 nodes-6380.conf
-rw-r--r--1 root 763 May 1 00:08 nodes-6381.conf
-rw-r--r--1 root 41412 April 23:30 redis-6379.conf
-rw-r--r--1 root 41412 April 23:39 redis-6380.conf
-rw-r--r--1 root 41412 April 23:39 redis-6381.conf

All nodes start successfully and do not mean they are clustered.

Four, create clusters, and view

1, create Redis cluster

# redis-trib.rb Create--replicas 1 192.168.10.219:6379 192.168.10.219:6380 192.168.10.219:6381 192.168.10.220:6382 192.168.10.220:6383 192.168.10.220:6384
2, view Redis cluster status

[Root@slave2 redis]# redis-trib.rb Check 192.168.10.219:6379
Connecting to Node 192.168.10.219:6379:ok
Connecting to Node 192.168.10.220:6384:ok
Connecting to Node 192.168.10.219:6381:ok
Connecting to Node 192.168.10.220:6383:ok
Connecting to Node 192.168.10.220:6382:ok
Connecting to Node 192.168.10.219:6380:ok
>>> performing Cluster Check (using node 192.168.10.219:6379)
M:d40d9a367c24784b0336c7b80fb4c87337e2cba6 192.168.10.219:6379
slots:5461-10922 (5462 slots) Master
1 additional replica (s)
s:5f00f163d0c0a540ea99daf004f55588a802327b 192.168.10.220:6384
Slots: (0 slots) Slave
Replicates D40d9a367c24784b0336c7b80fb4c87337e2cba6
S:b3b1a848987b5a87a06888e126d5c9b16f871ff5 192.168.10.219:6381
Slots: (0 slots) Slave
Replicates d2eb5a8a77f87888792428aed4692dfb907e7a1d
M:D2EB5A8A77F87888792428AED4692DFB907E7A1D 192.168.10.220:6383
slots:10923-16383 (5461 slots) Master
1 additional replica (s)
m:a8eafe8b19d6a28c034917da13a43ce1230fe870 192.168.10.220:6382
slots:0-5460 (5461 slots) Master
1 additional replica (s)
S:a87d207204a53ab599bf7f6ffb9d679d0eef4f25 192.168.10.219:6380
Slots: (0 slots) Slave
Replicates a8eafe8b19d6a28c034917da13a43ce1230fe870
[OK] All nodes agree about slots configuration.
>>> Check for open Slots ...
>>> Check Slots Coverage ...
[OK] All 16384 slots covered.

Here, the Redis cluster is configured to succeed.

Five, Test Redis cluster

# redis-cli-c-P 6379-h 192.168.10.219//Login in 219
192.168.10.219:6379> Set Tank TANK1//Set test values
-> redirected to slot [4407] located at 192.168.10.220:6382
OK//Direct to 220 6382 port, data saved to 220 6382, but a little strange
192.168.10.220:6382> get tank//can fetch value
"Tank1"

[Root@manage redis]# redis-cli-c-P 6383-h 192.168.10.220//220 machine, 6383 ports
192.168.10.220:6383> Get Tank
-> redirected to slot [4407] located at 192.168.10.220:6382//direct to 220 6382 ports
"Tank1"

[Root@manage redis]# PS aux |grep redis//view process
Root 7310 0.2 0.9 137436 9724 pts/0 Sl Apr30 0:09 redis-server *:6382 [cluster]
Root 7311 0.2 0.9 137436 9776 pts/0 Sl Apr30 0:09 redis-server *:6383 [cluster]
Root 7316 0.2 0.9 137436 9944 pts/0 Sl Apr30 0:10 redis-server *:6384 [cluster]
Root 7478 0.0 0.0 103256 812 pts/0 s+ 00:56 0:00 grep redis

[Root@manage redis]# kill-9 7310//Close 220 6382 ports to see if the data will be lost

[Root@slave2 redis]# redis-trib.rb Check 192.168.10.219:6379//view cluster situation, any interface is OK
Connecting to Node 192.168.10.219:6379:ok
Connecting to Node 192.168.10.220:6384:ok
Connecting to Node 192.168.10.219:6381:ok
Connecting to Node 192.168.10.220:6383:ok
Connecting to Node 192.168.10.219:6380:ok
>>> performing Cluster Check (using node 192.168.10.219:6379)
M:d40d9a367c24784b0336c7b80fb4c87337e2cba6 192.168.10.219:6379
slots:5461-10922 (5462 slots) Master
1 additional replica (s)
s:5f00f163d0c0a540ea99daf004f55588a802327b 192.168.10.220:6384
Slots: (0 slots) Slave
Replicates D40d9a367c24784b0336c7b80fb4c87337e2cba6
S:b3b1a848987b5a87a06888e126d5c9b16f871ff5 192.168.10.219:6381
Slots: (0 slots) Slave
Replicates d2eb5a8a77f87888792428aed4692dfb907e7a1d
M:D2EB5A8A77F87888792428AED4692DFB907E7A1D 192.168.10.220:6383
slots:10923-16383 (5461 slots) Master
1 additional replica (s)
M:a87d207204a53ab599bf7f6ffb9d679d0eef4f25 192.168.10.219:6380
slots:0-5460 (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. Become, the three main two from the

[Root@slave2 redis]# redis-cli-c-P 6379-h 192.168.10.219//219 Login
192.168.10.219:6379> Get Tank
-> redirected to slot [4407] located at 192.168.10.219:6380//data was transferred to 6380 nodes.
"Tank1"
After testing, the cluster is available.

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.