码迷,mamicode.com
首页 > 其他好文 > 详细

redis cluster practice

时间:2014-06-03 17:02:51      阅读:474      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   a   

redis cluster practice

1. create three instance folder: 9001,9002,9003,folder name as  redis instance port

bubuko.com,布布扣

2.Store configuration files redis-server, redis.conf to the three folders

bubuko.com,布布扣

3.Change redis.conf  file, keep below setting

daemonize yes
port 9001
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

note: port need to change into folder name

4.start up the three instances

zhaoguihuadediannao:~ zhaogh$ cd applications/dev/redis-cluster

zhaoguihuadediannao:redis-cluster zhaogh$ cd 9001

zhaoguihuadediannao:9001 zhaogh$ ./redis-server ./redis.conf

zhaoguihuadediannao:9003 zhaogh$ cd ../9002

zhaoguihuadediannao:9002 zhaogh$ ./redis-server ./redis.conf

zhaoguihuadediannao:9002 zhaogh$ cd ../9003

zhaoguihuadediannao:9003 zhaogh$ ./redis-server ./redis.conf

zhaoguihuadediannao:9003 zhaogh$

5.create clusters on the three instances

zhaoguihuadediannao:src zhaogh$ ./redis-trib.rb create --replicas 0 127.0.0.1:9001 127.0.0.1:9002 127.0.0.1:9003

>>> Creating cluster

Connecting to node 127.0.0.1:9001: OK

Connecting to node 127.0.0.1:9002: OK

Connecting to node 127.0.0.1:9003: OK

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

Using 3 masters:

127.0.0.1:9001

127.0.0.1:9002

127.0.0.1:9003

M: 92c9912cb1ccf657c886ecd839dd32c66efd8762 127.0.0.1:9001

slots:0-5460 (5461 slots) master

M: b6d46fcb8b0e6ee373b09a4f2cbcec744d1a259b 127.0.0.1:9002

slots:5461-10922 (5462 slots) master

M: 44ab30c7c589ffb15b9b04dd827c72cfaeedacb2 127.0.0.1:9003

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

M: 92c9912cb1ccf657c886ecd839dd32c66efd8762 127.0.0.1:9001

slots:0-5460 (5461 slots) master

M: b6d46fcb8b0e6ee373b09a4f2cbcec744d1a259b 127.0.0.1:9002

slots:5461-10922 (5462 slots) master

M: 44ab30c7c589ffb15b9b04dd827c72cfaeedacb2 127.0.0.1:9003

slots:10923-16383 (5461 slots) master

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

zhaoguihuadediannao:src zhaogh$

6. command  redis-trib.rb  needs ruby env., may install it from https://rubygems.org/gems/redis

sudo gem install redis-3.0.7.gem --local

7. test in  redis client

zhaoguihuadediannao:src zhaogh$ ./redis-cli -c -p 9001

127.0.0.1:9001> get testkey001

-> Redirected to slot [12786] located at 127.0.0.1:9003

(nil)

127.0.0.1:9003> set testkey002 testvalue002

-> Redirected to slot [401] located at 127.0.0.1:9001

OK

127.0.0.1:9001> get testkey002

"testvalue002"

127.0.0.1:9001> set testkey003 testvalue003

OK

127.0.0.1:9001>

8. even connect 9001 port, whenretrievetestkey001,redis cluster will auto redirect to port9003 .

When set 9003 with testkey002,redis cluster auto redirect to  9001

 source: http://www.cnblogs.com/zhaoguihua/p/redis-005.html

redis cluster practice,布布扣,bubuko.com

redis cluster practice

标签:des   c   style   class   blog   a   

原文地址:http://www.cnblogs.com/glenblogs/p/3765085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!