In-depth analysis of Redis cluster clusters

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

In-depth analysis of Redis cluster cluster installation configuration detailed below for you to introduce an in-depth analysis of Redis cluster cluster installation configuration, if you want to do a database cluster can come to see this article Oh.

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 can refer to this article to install Ruby.

Three, install redis3.0.0

1, installing 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 should be done on the first two machines.

2, configuring Redis

[[email protected] redis-3.0.0]# vim redis.conf//Unzip the 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 separately 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 locations to modify the port

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 *

[Email protected] redis]# ll/etc/redis/

Total Dosage 156

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

All nodes are started successfully, it does not mean that they are clustered.

Four, create the cluster, and view

1. Create a 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

[Email protected] 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 successfully.

Five, Test Redis cluster

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

[[email protected] redis]# redis-cli-c-P 6383-h 192.168.10.220//220 machine, 6383 ports
192.168.10.220:6383> Get Tank
Redirected to Slots [4407] located at 192.168.10.220:6382//Direct Steering 220 6382 ports
"Tank1"

[[Email protected] 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

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

[[email protected] redis]# redis-trib.rb Check 192.168.10.219:6379//view cluster condition, 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, three master two from the

[[email protected] redis]# redis-cli-c-P 6379-h 192.168.10.219//219 Login
192.168.10.219:6379> Get Tank
Redirected to Slots [4407] located at 192.168.10.219:6380//data is transferred to 6380 node
"Tank1"
After testing, the cluster is available.

In-depth analysis of Redis cluster clusters

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.