Redis(7)Creating and Using Cluster Mode
1. Documents
Cluster will not support SELECT, it only contains database 0.
All the nodes use TCP bus and binary protocol to communicate. Every node connect to cluster bus. The use gossip to talk.
Some times we lost writing data
1. master node dies right before the slave node get the newly writing data.
2. master node dies, and slave node become master, and receive a writing data. when the old master recover, it does not have the newly writing data.
2. Configuration the Cluster mode
Check out the latest codes from here https://github.com/antirez/redis.git
Switch to the branch unstable
>make distclean
>make
>mkdir /Users/carl/tool/redis-unstable
>cp redis-server /Users/carl/tool/redis-unstable/
>cp redis-cli /Users/carl/tool/redis-unstable/
>cp redis-benchmark /Users/carl/tool/redis-unstable/
>cd ..
>cp redis.conf /Users/carl/tool/redis-unstable/
>sudo ln -s /Users/carl/tool/redis-unstable /opt/redis-unstable
>sudo rm -fr /opt/redis
>sudo ln -s /opt/redis-unstable /opt/redis
Prepare the Configuration files
>mkdir cluster-conf
>cd cluster-conf
>mkdir 7000 7001 7002 7003 7004 7005 7006
Change the redis.conf there and properties as follow for references;
port 7000
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
Then start all the nodes one by one
>../../redis-server ./redis.conf
Every time, we will see these message after we start one node.
[23303] 01 May 15:28:47.602 * No cluster configuration found, I'm c5a855fba006f6b3302f7c162ba3b6a71d548b58
After we start 7000 to 7005, 6 nodes, execute this command from src directory to configure cluster.
>./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
Error Message:
cannot load such file -- redis (LoadError)
Solution:
>ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
>gem -v
2.0.14
1. Use a recent ruby (1.9.3 or 2.0)
2. Install the redid gem
>sudo gem install redis
Then
>ruby -rubygems ./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
>>> Creating cluster Connecting to node 127.0.0.1:7000: OK Connecting to node 127.0.0.1:7001: OK Connecting to node 127.0.0.1:7002: OK Connecting to node 127.0.0.1:7003: OK Connecting to node 127.0.0.1:7004: OK Connecting to node 127.0.0.1:7005: OK >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 Adding replica 127.0.0.1:7003 to 127.0.0.1:7000 Adding replica 127.0.0.1:7004 to 127.0.0.1:7001 Adding replica 127.0.0.1:7005 to 127.0.0.1:7002 M: c5a855fba006f6b3302f7c162ba3b6a71d548b58 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: d0a6d910adeffa2b0ba69ddc69d9e69bdda1a41e 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 376e13f055d4119ca45824aff3e7722a3043ecf7 127.0.0.1:7002 slots:10923-16383 (5461 slots) master S: 5295fe0fae941d7f964a674c5e5a4de37738e412 127.0.0.1:7003 replicates c5a855fba006f6b3302f7c162ba3b6a71d548b58 S: 64a3ae73e370d1e016a01adaedce1606d3b7d2ea 127.0.0.1:7004 replicates d0a6d910adeffa2b0ba69ddc69d9e69bdda1a41e S: 4324a0c7c90a460b4fc107f66e61656ec23c316b 127.0.0.1:7005 replicates 376e13f055d4119ca45824aff3e7722a3043ecf7 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> 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: c5a855fba006f6b3302f7c162ba3b6a71d548b58 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: d0a6d910adeffa2b0ba69ddc69d9e69bdda1a41e 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 376e13f055d4119ca45824aff3e7722a3043ecf7 127.0.0.1:7002 slots:10923-16383 (5461 slots) master M: 5295fe0fae941d7f964a674c5e5a4de37738e412 127.0.0.1:7003 slots: (0 slots) master replicates c5a855fba006f6b3302f7c162ba3b6a71d548b58 M: 64a3ae73e370d1e016a01adaedce1606d3b7d2ea 127.0.0.1:7004 slots: (0 slots) master replicates d0a6d910adeffa2b0ba69ddc69d9e69bdda1a41e M: 4324a0c7c90a460b4fc107f66e61656ec23c316b 127.0.0.1:7005 slots: (0 slots) master replicates 376e13f055d4119ca45824aff3e7722a3043ecf7 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
—replicas 1 indicate that every master has a replica node.
It will create 3 masters and 3 slaves.
Right now, my version of branch unstable is 2.9.11.
Test and Verify the Cluster
>./redis-cli -c -p 7000
127.0.0.1:7000> set foo bar -> Redirected to slot [12182] located at 127.0.0.1:7002 OK 127.0.0.1:7002> get foo "bar" 127.0.0.1:7002> set hello world -> Redirected to slot [866] located at 127.0.0.1:7000 OK 127.0.0.1:7000> get hello "world"
Add New Node
redis>cluster nodes
This command will show all the nodes.
>./redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000
Connecting to node 127.0.0.1:7006: OK >>> Send CLUSTER MEET to node 127.0.0.1:7006 to make it join the cluster. [OK] New node added correctly.
Or add slave node
>./redis-trib.rb add-node --slave 127.0.0.1:7006 127.0.0.1:7000
Or
>./redis-trib.rb add-node --slave --master-id adsfadsfadsfsadfsdaf 127.0.0.1:7006 127.0.0.1:7000
Remove a Node
>./redis-trib.rb del-node 127.0.0.1:7000 '591d10c5251abd0ef655a458f8e16a6cca182da6'
First parameter is any node host and port, the second parameter the id of the node we plan to remove.
Error Message:
[ERR] Node 127.0.0.1:7006 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
Solution:
I delete the node, I plan to add it again. But I meet that error message.
I do not know how to fix this right now. But an easy way, delete all the files under 7006 directory except redis.conf, they it will generate a new node id.
3. Scala Client
Check the Status
redis>info
redis_mode:cluster
redis_version:2.9.11
Open project easynosqlscala
It runs great.
package com.sillycat.easynosqlscala.app
import redis.clients.jedis.{ JedisCluster, HostAndPort, Jedis }
import java.util.HashSet
object TestRedisDBConnectionApp extends App {
// val jedis = new Jedis("172.0.0.1", 7000)
// jedis.set("name", "sillycat")
// println(jedis.get("name"))
val jedisClusterNodes = new HashSet[HostAndPort]
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7000))
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7001))
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7002))
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7003))
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7004))
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7005))
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7006))
val jc = new JedisCluster(jedisClusterNodes)
jc.set("age", "32")
println("name = " + jc.get("name") + " age = " + jc.get("age"))
}
Redis Monitor
https://github.com/LittlePeng/redis-monitor
References:
Redis 1~ 6
http://sillycat.iteye.com/blog/1549504 Installation redis on windows, ubuntu, redhat
http://sillycat.iteye.com/blog/1553507 Data Type, String, Int, List, Set
http://sillycat.iteye.com/blog/1553508 Data Type, Ordered Set, Hash, Publish/Subscribe, Data Expiration
http://sillycat.iteye.com/blog/1553509 Java DAO Layer
http://sillycat.iteye.com/blog/2028180 Installation on MAC, HA Solution sentinel master slave
http://sillycat.iteye.com/blog/2033094 Scala Client
http://redis.io/topics/cluster-tutorial
http://redis.io/topics/cluster-spec
http://www.redis.cn/topics/cluster-tutorial.html
http://www.redis.cn/topics/cluster-spec.html
Tips
http://in.sdo.com/?p=1378
http://www.cnblogs.com/lulu/archive/2013/06/10/3130878.html
http://www.oschina.net/translate/utopian-redis-cluster
cluster
http://hot66hot.iteye.com/blog/2050676
相关推荐
7. Redis Cluster 的应用场景 Redis Cluster 的应用场景非常广泛,例如可以用于高性能缓存、高可用性消息队列、高性能数据存储等。 8. Redis Cluster 与 Redis Sentinel 的比较 Redis Cluster 与 Redis Sentinel ...
redis命令实践,基于Spring支持的redis线程池,(redis Cluster,主从Redis,sentenl)。适用人群:计算机,软件工程、人工智能,网络安全,电子信息等专业的大学生课程设计、期末大作业或毕业设计,作为“参考资料...
《Redis-Py-Cluster:Python中的Redis集群库详解》 Redis-Py-Cluster是一个Python库,专门用于在Python环境中操作Redis分布式集群。该库为开发者提供了便捷的方式与Redis集群进行交互,支持各种数据结构,如字符串...
而`redis-py-cluster`是Python连接Redis集群的一个库,它允许Python开发者方便地与Redis集群进行交互。`redis-py-cluster-1.3.5.tar.gz`这个压缩包文件包含了该库的源代码和相关资源,版本号为1.3.5。 首先,让我们...
`redis-py-cluster`是这个客户端的一个扩展,专门为处理Redis Cluster提供支持。在本文中,我们将深入探讨`redis-py-cluster`的1.3.4版本,并讨论其关键特性和使用方法。 **1. Redis Cluster** Redis Cluster是...
《Python操作Redis集群:redis-py-cluster详解》 在Python中与Redis进行交互,我们通常会使用`redis-py`库,然而,当涉及到Redis集群(Redis Cluster)时,`redis-py`的标准版本可能无法满足需求。为了解决这个问题...
Redis-Cluster是Redis的一个分布式实现,它允许在多个节点之间分散数据,提供高可用性和可扩展性。在Windows环境中配置Redis-Cluster,首先需要理解其基本概念和工作原理,然后按照步骤进行安装和配置。 一、Redis-...
RedisCluster是Redis的一种分布式集群解决方案,它允许将数据分散存储在多个节点上,以实现高可用性和可扩展性。在RedisCluster中,每个节点都存储一部分数据,并且负责处理一部分客户端请求,这样可以分摊服务器...
Redis 集群是一个提供在多个Redis间节点间共享数据的程序集。 Redis集群并 不支持处理多个keys... 本文,是我自己写的Redis Cluster集群搭建和配置详细步骤,包含了常用的Redis配置文件,和节点的管理等,以供大家参考.
### 关于Jedis连接Linux上的Redis出现DENIED Redis is running in protected mode问题的解决方案 #### 一、问题背景 在尝试使用Jedis客户端通过网络连接Linux服务器上的Redis时,可能会遇到一个常见的错误提示:...
redis cluster配置文件,配置后的参考; 创建目录: mkdir -p /etc/redis-cluster mkdir -p /var/log/redis mkdir -p /var/redis/7001 mkdir -p /var/redis/7002 拷贝配置文件: cp /usr/local/redis-3.2.8/redis....
Redis Cluster是Redis官方提供的分布式解决方案,它允许用户在多个节点之间分发数据,从而实现高可用性和水平扩展。本文将详细介绍Redis Cluster的工作原理、配置、使用以及与MySQL数据库的配合。 **一、Redis ...
Redis-注册中心集群 Cluster 集群-单服务器
**RedisCluster集群与Spring访问Redis详解** Redis是一个高性能的键值数据库,广泛应用于缓存、消息中间件等场景。在大型分布式系统中,为了提供高可用性和数据冗余,我们通常会采用Redis Cluster来构建集群。本文...
Redis Cluster 是一个分布式数据存储解决方案,它允许将数据分散存储在多个节点上,以实现高可用性和可扩展性。在Redis Cluster中,每个节点都存储一部分数据,并且可以通过内部的槽映射机制来管理和处理客户端的...
redis-go-cluster, 在Go中,redis集群客户端实现 redis-go-clusterredis-go-cluster是基于 burd burd burd的客户端的一个golang实现的。 它在本地缓存 slot 信息,并在集群更改时自动更新。 客户端管理每个 node的...
Redis Cluster 集群模式部署 本文将详细介绍 Redis Cluster 集群模式部署的步骤和配置过程。Redis Cluster 是 Redis 的一个高可用解决方案,通过将多个 Redis 节点组合成集群,提高 Redis 的可用性和性能。 环境...
【Redis-Cluster20161110】是一个关于Redis集群的资料包,发布于2016年11月10日。这个压缩包包含了一些用于启动和管理Redis集群的工具,以及Redis服务器的安装文件。让我们深入探讨Redis Cluster及其相关知识点。 *...