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 
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.
eg:

>./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

Redis(7)Creating and Using Cluster Mode的更多相关文章

  1. redis介绍 (8) window 下redis的集群(cluster命令)

    前言: 前段时间我在centos上搭建过一次redis集群,那是借助ruby搭建,这次我介绍一种纯redis集群命令的方式去搭建[最后我会简单介绍ruby搭建]. redis集群搭建(三主三备): 准 ...

  2. redis 5.0 CLUSTERDOWN The cluster is down

    安装 redis 集群,设置值报错,错误信息:redis 5.0  CLUSTERDOWN The cluster is down. 这个是由于安装错误导致的,需要重新进行 修复一下. 命令如下: [ ...

  3. Redis集群模式(Cluster)部署

    1. 安装依赖包 注意:本节需要使用root用户操作 1.1 安装ruby yum install ruby -y yum install ruby-devel.x86_64 -y 1.2 安装rub ...

  4. Redis多机常用架构-cluster

    Redis-cluster:去中心化,中间件,集群中任意节点平等,任一节点可获得全局的数据 Redis-cluster 拓扑图: 架构演变及 cap 理论: 单机 Redis 属于 cp 模型. Re ...

  5. 启动redis出现Creating Server TCP listening socket *:6379: bind: No such file or directory

    E:\redis>redis-server.exe redis.windows.conf [8564] 10 Oct 20:00:36.745 # Creating Server TCP lis ...

  6. redis —主从&&集群(CLUSTER)

    REDIS主从配置 为了节省资源,本实验在一台机器进行.即,在一台机器上启动两个端口,模拟两台机器. 机器准备: [root@adailinux ~]# cp /etc/redis.conf /etc ...

  7. redis ERR This instance has cluster support disabled

    Redis  集群的时候报错: redis.clients.jedis.exceptions.JedisDataException: ERR This instance has cluster sup ...

  8. Redis系列(十)--集群cluster

    在之前学习了Master-Slave.Sentinel模式,但是在某些情况下还是无法满足系统对QPS等要求,这时候就需要Cluster,Redis3.0支持了cluster 一.为什么使用Cluste ...

  9. redis源码分析(六)--cluster集群同步

    Redis集群消息 作为支持集群模式的缓存系统,Redis集群中的各个节点需要定期地进行通信,以维持各个节点关于其它节点信息的实时性与一致性.如前一篇文章介绍的,Redis在专用的端口监听集群其它节点 ...

随机推荐

  1. SELECT时为何要加WITH(NOLOCK)

    此文章非原创,仅为分享.学习!! 要提升SQL的查询效能,一般来说大家会以建立索引(index)为第一考虑.其实除了index的建立之外,当我们在下SQL Command时,在语法中加一段WITH ( ...

  2. vs无法打开项目的解决方案

    错误提示: “未找到与约束 ContractName Microsoft.Internal.VisualStudio.PlatformUI.ISolutionAttachedCollectionSer ...

  3. style不同取值对应的日期、时间格式

    from : http://www.cnblogs.com/Gavinzhao/archive/2009/11/10/1599690.html sql server2000中使用convert来取得d ...

  4. hdu2037-----------贪心, 活动安排问题

    http://acm.hdu.edu.cn/showproblem.php?pid=2037(简单贪心-----活动安排) #include<iostream> #include<a ...

  5. iOS - MVC 架构模式

    1.MVC 从字面意思来理解,MVC 即 Modal View Controller(模型 视图 控制器),是 Xerox PARC 在 20 世纪 80 年代为编程语言 Smalltalk-80 发 ...

  6. Nginx基础知识————生成自签名ca 证书 使nginx 支持https

    创建服务器私钥,命令会让你输入一个口令: $ openssl genrsa -des3 -out server.key 1024 创建签名请求的证书(CSR): $ openssl req -new ...

  7. Nexus4铃声目录

    1. 我的铃声 是通过下面的命令 传到手机上面去的: “ adb push fringe_01_long.mp3 /sdcard/ZC/ adb push fringe_02_short.mp3 /s ...

  8. mysql Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    错误原因:/var/lib/mysql目录中socket文件不存在.连接mysql服务器有两种方式:tcp连接,通过socket文件连接.通过socket文件,启动mysql服务,mysql服务会自动 ...

  9. 关于协程的学习 & 线程栈默认10M

    先看的这篇文章:http://blog.csdn.net/qq910894904/article/details/41699541 以nginx为代表的事件驱动的异步server正在横扫天下,那么事件 ...

  10. go语言中间的循环

    在Go语言中只有很少的几个控制结构,它没有while或者do-while循环. 但是它有for.switch.if.而且switch接受像for那样可选的初始化语句.下面来认识一下他们 一.if语句 ...