Redis Walkthrough (8) Redis Cluster cluster environment installation

Source: Internet
Author: User
Tags create directory redis version redis cluster

Redis is a distributed cache, and the biggest advantage of a traditional database is its "distributed".

Benefits of Distributed:

    1. Easy to implement capacity expansion

    2. Equal distribution of data

    3. Very good high availability


Redis and memcached are the two popular scenarios for distributed caching, and the contrast between them


Redis Memcached
Master-Slave function

Replication Support

Primary and Standby automatic switching

Not natively supported, can be implemented by the client itself
Key-Value Consistency
Hash slots
Consistent Hash
Cluster
Server-side support (but beta version) unstable
Implemented by the client
Tool support
Provide your own tool (client Redis-cli,check-rdb ... )
Weaker
Data storage
Support
No support, restart data loss

Main contents of this chapter

Install a three-master Redis cluster environment.

Get ready

Since I have not been in touch with Ruby language, in the work hours before installation, need to install ruby environment, a little psychological burden, worry about trouble. Later, I was expected to encounter some trouble. Finally, the installation is successful, looking back, there is nothing to worry about, no outside the failure of the reload, really old, the less daring ah. I adopt the way, "soldiers to will block, punches", wrong to solve the mistake, step by step installation. With the power of the network, one by one to break the problem.

Installing the ruby Environment


1. Install Ruby

Problems encountered

Ruby is not installed

Version too low

Rubygem not installed

Gem Source Error

Please refer to

http://blog.csdn.net/c77_cn/article/details/38227797

2. Compiling Redis cluster

Download the unstable version from Https://github.com/antirez/redis/branches.

Compiling make
In this case, a redis-server that supports cluster is generated in the/USR/LOCAL/SRC/REDIS-UNSTABLE/SRC directory


3. Create a clustered environment

1. Create directory Cp/usr/local/redismkdir cluster-testcd cluster-test/mkdir 7000mkdir 7001mkdir 70022. Copy redis-server cp/usr/ local/src/redis-unstable/src/redis-server/usr/local/redis/cluster-test/7001 CP/USR/LOCAL/SRC/REDIS-UNSTABLE/SRC /redis-server/usr/local/redis/cluster-test/7000 cp/usr/local/src/redis-unstable/src/redis-server/usr/local/ redis/cluster-test/7002 #集群管理工具 (copy him to the right place for convenience) cp/usr/local/src/redis-unstable/src/redis-trib.rb/usr/local/ Redis/cluster-test

3. Build 3 redis.conf files for cluster nodes

[Email protected] cluster-test]# VI 7000/redis.conf Port 7000cluster-enabled yescluster-config-file Nodes.confcluster-node-timeout 5000appendonly yesdaemonize yeslogfile "Redis7000.log" #这是最简单的集群参数

Other 7001/redis.conf,7002.conf files, only the port and logfile parameters are different, the others are the same.

At this point 7000, the 7001,7002 directory, only 2 files, respectively, is redis-server,redis.conf

4. Start up (3 primary nodes respectively)

CD 7000./redis-server./redis.conf CD. /7001/./redis-server./redis.conf CD. /7002./redis-server./redis.conf

corresponding to a node log

26361:m SEP 21:13:22.054 * No cluster configuration found, I ' M 7f242cf2c7ce5d84103638c5017f2204e1509f4c
_._
_.-' __ '-._
_.-``    `.  `_. "-._ Redis 3.2.3 (00000000/0)
.-`` .-```. ' \ \ _.,_ '-._
(',.-' | ',) Running in cluster mode
| '-._ '-...-' __...-. '-._| '     ' _.-' | port:7001
|     '-._ '. _/_.-' | pid:26361
'-._ '-._ '-./_.-' _.-'
| '-._ '-._ '-.__.-' _.-' _.-' |
|           '-._ '-._ _.-' _.-' | Http://redis.io
'-._ '-._ '-.__.-' _.-' _.-'
| '-._ '-._ '-.__.-' _.-' _.-' |
| '-._ '-._ _.-' _.-' |
'-._ '-._ '-.__.-' _.-' _.-'
'-._ '-.__.-' _.-'
'-._ _.-'
'-.__.-'

26361:m Sep 21:13:22.075 # Server started, Redis version 3.2.3
26361:m SEP 21:13:22.075 * DB loaded from append only file:0.000 seconds
26361:m Sep 21:13:22.076 # I have the keys for unassigned slot 5659. Taking responsibility for it.
26361:m Sep 21:13:22.076 # I have the keys for unassigned slot 9980. Taking responsibility for it.
26361:m SEP 21:13:22.080 * The server is now ready for accept connections on port 7001


5. Building a Cluster

./REDIS-TRIB.RB Create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002

[Email protected] cluster-test]#/redis-trib.rb create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002
>>> Creating Cluster
>>> performing hash slots allocation on 3 nodes ...
Using 3 Masters:
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
m:5ad201ebdf0553690295dcd06f89f15750e73989 127.0.0.1:7000
slots:0-5460 (5461 slots) Master
M:7F242CF2C7CE5D84103638C5017F2204E1509F4C 127.0.0.1:7001
slots:5461-10922 (5462 slots) Master
M:8EA7B0976E4848653435E4E77AF311A6ADE330A8 127.0.0.1:7002
slots:10923-16383 (5461 slots) Master
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 127.0.0.1:7000)
m:5ad201ebdf0553690295dcd06f89f15750e73989 127.0.0.1:7000
slots:0-5460 (5461 slots) Master
0 additional replica (s)
M:8EA7B0976E4848653435E4E77AF311A6ADE330A8 127.0.0.1:7002
slots:10923-16383 (5461 slots) Master
0 additional replica (s)
M:7F242CF2C7CE5D84103638C5017F2204E1509F4C 127.0.0.1:7001
slots:5461-10922 (5462 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.

At this time the master node log

26536:m SEP 21:25:32.360 * DB loaded from append only file:0.000 seconds
26536:m SEP 21:25:32.361 * The server is now ready for accept connections on port 7000
26536:m Sep 21:27:54.651 # Configepoch set to 1 via CLUSTER Set-config-epoch
26536:m Sep 21:27:54.660 # IP address for this node updated to 127.0.0.1
26536:m Sep 21:27:59.619 # Cluster State Changed:ok

6. Testing

[[Email protected] cluster-test]#  /usr/local/redis/bin/redis-cli  -c -p  7000127.0.0.1:7000> keys * (Empty list or set) 127.0.0.1:7000> set  title  "Cluster1" ok127.0.0.1:7000> set title1  "Cluster1" ok127.0.0.1:7000>  set title2  "Cluster1"-> redirected to slot [14045] located at  127.0.0.1:7002ok127.0.0.1:7002> set title5  "Cluster4"-> redirected to slot  [1594] located at 127.0.0.1:7000OK127.0.0.1:7000> set title3  "Cluster4" -> redirected to slot [9980] located at 127.0.0.1:7001ok127.0.0.1:7001 > get title-> Redirected to slot [2217] located at  127.0.0.1:7000 "Cluster1" 127.0.0.1:7000> get title2-> redirected to slot [ 14045] located at 127.0.0.1:7002 "cluster8111" 127.0.0.1:7002> get title3-> redirected to slot  [9980] located at 127.0.0.1:7001 "Cluster4" #节点间来回重定向


When we get here, the environment is well-built. Of course, this is the simplest cluster. In the future, as the drill in-depth, the cluster will be further explored.


Errors that may be encountered (is the second time to build the cluster times wrong)

ERR Slot 2217 is already busy (Redis::commanderror)

(In all nodes do Flushall and then CLUSTER RESET SOFT)



Reference Resources

http://blog.csdn.net/c77_cn/article/details/38227797

Http://redis.io/topics/cluster-tutorial

Http://redisdoc.com/topic/cluster-tutorial.html

This article is from a "simple" blog, so be sure to keep this source http://dba10g.blog.51cto.com/764602/1851458

Redis Walkthrough (8) Redis Cluster cluster environment installation

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.