Redis3.0.5 cluster--安装

基于大神指点配置:http://blog.csdn.net/xu470438000/article/details/42971091, 加上自己遇到问题整理如下:

系统版本:先 mac ox x 10.11,安装redis3.0,搭建一下集群环境,后遇到问题 换到ubuntu 15.04,需要 ruby 环境。

官网下载3.0.5

tar -zxvf redis-3.0.5-2.tar

mv redis-3.0.5.2 ~/SoftWare

cd ~/SoftWare/redis-3.0.5.2

make && make install

redis-server 启动,安装完成

配置:

mkdir cluster/7001 

mkdir cluster/7002

mkdir cluster/7003 

mkdir cluster/7004 

mkdir cluster/7005 

mkdir cluster/7006 

cp redis.conf cluster/7001   

以 7001 为例,其他与此相同,修改如下配置:

port 7001

daemonize yes

cluster-enabled yes

cluster-config-file nodes-7001.conf

cluster-node-timeout 5000

appendonly yes

logfile "log/redis-7001.log"

loglevel debug

dir "cluster/7001/"


启动 6 个实例

redis-server cluster/7001/redis.conf 

......

redis-server cluster/7006/redis.conf 

最多就能启动2个实例,正在解决中,问题很奇怪, 最后把cluster关闭,挨个各自启动一下,没问题,改回来之后重启下就成功启动。还有就是把cluster-config-file  node-端口号.conf 由于cluster-config-file  nodes.conf 相同的名称, 顺序启动第三个节点时候文件会分配到7002文件夹内,重名!我的文件结构如下:


Redis3.0.5 cluster--安装_第1张图片

不明白为什么会出现在7002下面!

成功启动:

root@jiangqq:/usr/local/redis-3.0.5# ps -ef | grep redis

root      9831     1  0 15:47 ?        00:00:00 redis-server *:7001 [cluster]       

root      9848     1  0 15:48 ?        00:00:00 redis-server *:7002 [cluster]       

root      9874     1  0 15:50 ?        00:00:00 redis-server *:7003 [cluster]       

root      9880     1  0 15:51 ?        00:00:00 redis-server *:7004 [cluster]       

root      9886     1  0 15:51 ?        00:00:00 redis-server *:7005 [cluster]       

root      9895     1  0 15:52 ?        00:00:00 redis-server *:7006 [cluster]       

root      9900  9737  0 15:52 pts/3    00:00:00 grep --color=auto redis

root@jiangqq:/usr/local/redis-3.0.5# 


配置集群:

./src/redis-trib.rb  create --replicas 1 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 127.0.0.1:7006

报错1:

/usr/bin/env: ruby: 没有那个文件或目录

安装 ruby、rubygems 环境

linux: apt-get install ruby apt-get install rubygems

mac: 安装ruby环境 

参考:http://www.cnblogs.com/daguo/p/4097263.html

报错2:

root@java:/usr/local/redis-3.0.5# ./src/redis-trib.rb  create --replicas 1 127.0.0.1:7001 127.0.0.1:7005

/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError)

from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from ./src/redis-trib.rb:25:in `

'

安装 ruby 和 redis 接口,ruby 安装 redis client 包。

MacBook-Pro:src java$ gem install redis
Fetching: redis-3.2.2.gem (100%)
Successfully installed redis-3.2.2
Parsing documentation for redis-3.2.2
Installing ri documentation for redis-3.2.2
1 gem installed

准备完毕

root@java:/usr/local/redis-3.0.5# ./src/redis-trib.rb  create --replicas 1 127.0.0.1:7001 127.0.0.1:7005

>>> Creating cluster

Connecting to node 127.0.0.1:7001: OK

Connecting to node 127.0.0.1:7005: OK

*** ERROR: Invalid configuration for cluster creation.

*** Redis Cluster requires at least 3 master nodes.

*** This is not possible with 2 nodes and 1 replicas per node.

*** At least 6 nodes are required.


将各个节点数据flush掉,否则报错:

[ERR] Node 127.0.0.1:7002 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.


将节点加入到集群,又特么报错了:

root@java:/usr/local/redis-3.0.5/src# ./redis-trib.rb  create --replicas 1 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 127.0.0.1:7006

>>> Creating cluster

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

Connecting to node 127.0.0.1:7006: OK

>>> Performing hash slots allocation on 6 nodes...

Using 3 masters:

127.0.0.1:7001

127.0.0.1:7002

127.0.0.1:7003

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

Adding replica 127.0.0.1:7006 to 127.0.0.1:7003

M: c04c15188ccc0dbca000c595b7754a8fe2794158 127.0.0.1:7001

   slots:0-5460,5798 (5462 slots) master

M: a5ef5518546ae0850b3ec7a465996fef7ed6c5fb 127.0.0.1:7002

   slots:5461-10922 (5462 slots) master

M: 7ada5979528e2b636926f6e929eabb4706a895e5 127.0.0.1:7003

   slots:5798,10923-16383 (5462 slots) master

S: 7fbd159aeb4bd35f06b9a8dea6bb3a80676c5bf6 127.0.0.1:7004

   replicates c04c15188ccc0dbca000c595b7754a8fe2794158

S: 462f9070964d91eb5d92caac00634c69fb26ff69 127.0.0.1:7005

   replicates a5ef5518546ae0850b3ec7a465996fef7ed6c5fb

S: c229fb38c95e1bdc530ebc21320584d33443fee0 127.0.0.1:7006

   replicates 7ada5979528e2b636926f6e929eabb4706a895e5

Can I set the above configuration? (type 'yes' to accept): yes

/var/lib/gems/2.1.0/gems/redis-3.2.2/lib/redis/client.rb:114:in `call': ERR Slot 5798 is already busy (Redis::CommandError)

from /var/lib/gems/2.1.0/gems/redis-3.2.2/lib/redis.rb:2646:in `block in method_missing'

from /var/lib/gems/2.1.0/gems/redis-3.2.2/lib/redis.rb:57:in `block in synchronize'

from /usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'

from /var/lib/gems/2.1.0/gems/redis-3.2.2/lib/redis.rb:57:in `synchronize'

from /var/lib/gems/2.1.0/gems/redis-3.2.2/lib/redis.rb:2645:in `method_missing'

from ./redis-trib.rb:205:in `flush_node_config'

from ./redis-trib.rb:667:in `block in flush_nodes_config'

from ./redis-trib.rb:666:in `each'

from ./redis-trib.rb:666:in `flush_nodes_config'

from ./redis-trib.rb:1007:in `create_cluster_cmd'

from ./redis-trib.rb:1388:in `

'

root@jiangqq:/usr/local/redis-3.0.5/src# 






删除实例rdb、aof文件,重启 redis,再来一次:


root@keung:/usr/local/redis-3.0.5# src/redis-trib.rb  create --replicas 1 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 127.0.0.1:7006

mkreleasehdr.sh   redis-benchmark   redis-check-aof   redis-check-dump  redis-cli         redis-sentinel    redis-server      redis-trib.rb     

root@jiangqq:/usr/local/redis-3.0.5# src/redis-trib.rb  create --replicas 1 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 127.0.0.1:7006

>>> Creating cluster

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

Connecting to node 127.0.0.1:7006: OK

>>> Performing hash slots allocation on 6 nodes...

Using 3 masters:

127.0.0.1:7001

127.0.0.1:7002

127.0.0.1:7003

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

Adding replica 127.0.0.1:7006 to 127.0.0.1:7003

M: 1fcf7efcab49091e6dc86b64bf246c48dcd3683d 127.0.0.1:7001

   slots:0-5460 (5461 slots) master

M: 00d3325115ce9a8f017c1f2ea51fc9e393954e22 127.0.0.1:7002

   slots:5461-10922 (5462 slots) master

M: 6618c2d54c8090f1c4451c96577498966475105c 127.0.0.1:7003

   slots:10923-16383 (5461 slots) master

S: 5905617db2ca7e08aabde9989669caf6686489d9 127.0.0.1:7004

   replicates 1fcf7efcab49091e6dc86b64bf246c48dcd3683d

S: 444d9fe91c59f2df00f9805478ac35af2ed01e60 127.0.0.1:7005

   replicates 00d3325115ce9a8f017c1f2ea51fc9e393954e22

S: 01126c7db11891ef0a939a565d33900fe9f12077 127.0.0.1:7006

   replicates 6618c2d54c8090f1c4451c96577498966475105c

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:7001)

M: 1fcf7efcab49091e6dc86b64bf246c48dcd3683d 127.0.0.1:7001

   slots:0-5460 (5461 slots) master

M: 00d3325115ce9a8f017c1f2ea51fc9e393954e22 127.0.0.1:7002

   slots:5461-10922 (5462 slots) master

M: 6618c2d54c8090f1c4451c96577498966475105c 127.0.0.1:7003

   slots:10923-16383 (5461 slots) master

M: 5905617db2ca7e08aabde9989669caf6686489d9 127.0.0.1:7004

   slots: (0 slots) master

   replicates 1fcf7efcab49091e6dc86b64bf246c48dcd3683d

M: 444d9fe91c59f2df00f9805478ac35af2ed01e60 127.0.0.1:7005

   slots: (0 slots) master

   replicates 00d3325115ce9a8f017c1f2ea51fc9e393954e22

M: 01126c7db11891ef0a939a565d33900fe9f12077 127.0.0.1:7006

   slots: (0 slots) master

   replicates 6618c2d54c8090f1c4451c96577498966475105c

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

root@jiangqq:/usr/local/redis-3.0.5# 

root@jiangqq:/usr/local/redis-3.0.5# redis-cli -p 7001

127.0.0.1:7001> set name 'a'

(error) MOVED 5798 127.0.0.1:7002

127.0.0.1:7001> set name 'a'

(error) MOVED 5798 127.0.0.1:7002

127.0.0.1:7001> keys *

(empty list or set)

127.0.0.1:7001> 

root@jiangqq:/usr/local/redis-3.0.5# redis-cli -p 7002

127.0.0.1:7002> set name 'a'

OK

127.0.0.1:7001> cluster info

cluster_state:ok

cluster_slots_assigned:16384

cluster_slots_ok:16384

cluster_slots_pfail:0

cluster_slots_fail:0

cluster_known_nodes:6

cluster_size:3

cluster_current_epoch:6

cluster_my_epoch:2

cluster_stats_messages_sent:3353

cluster_stats_messages_received:3353

127.0.0.1:7001> 



OK,终于启动了,用了几乎一个工作日,搭建起来了,有如下几个问题,

1、客户端怎么连接集群呢?是把所有的IP、端口都连接起来嘛?如果是,set的时候怎么知道把他set到哪个机器了,如果只需要连接一台,如果当前连接网线掉了怎么办?lvs+keepalived?

2、集群架构也不是太理解,再想想还有什么问题。





你可能感兴趣的:(Redis)