redis cluster practice

来源:互联网 发布:简简单单软件 编辑:程序博客网 时间:2024/06/05 00:12

redis cluster practice

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

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

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 fromhttps://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 connect9001 port, whenretrievetestkey001,redis cluster will auto redirect to port9003 .

When set9003 withtestkey002,redis cluster auto redirect to 9001

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

0 0
原创粉丝点击