redis高可用之redis3.0叢集

hotdog04發表於2015-05-29
一、安裝配置:
1、redis安裝配置:
 版本:Redis server v=3.0.1
關鍵配置引數(7000):
daemonize yes
pidfile /var/run/redis_7000.pid
port 7000 
logfile "/etc/cluster/7000/redis_7000.log"
dir  /etc/cluster/7000
appendonly yes
appendfilename "appendonly.aof"
cluster-enabled yes
cluster-config-file nodes.conf


7001,7002,7003,7004,7005修改直接修改埠號即可


配置好後啟動這個6個redis節點


2、叢集配置:


[root@localhost src]# yum install ruby
[root@localhost src]# yum install  rubygems
找不到可以到這個連結下載
https://rubygems.org/gems/redis/versions


[root@localhost src]# ./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: 8128762ecea3a8798ed5d8b06b9520c969e50cd7 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
M: 425117c39f0f201b145deb1663c994f058883009 127.0.0.1:7001
   slots:5461-10922 (5462 slots) master
M: 5a6cb57aff9e4c00a819c86e78b279864e4993b5 127.0.0.1:7002
   slots:10923-16383 (5461 slots) master
S: 9526e18bd0dee29b7deeaff25d140a0139b3962c 127.0.0.1:7003
   replicates 8128762ecea3a8798ed5d8b06b9520c969e50cd7
S: ee01f05c92b56ce9cb13619073146b6bbcc97cd3 127.0.0.1:7004
   replicates 425117c39f0f201b145deb1663c994f058883009
S: 2129adb0613dc207d37cb44d53ae11a32766c2c3 127.0.0.1:7005
   replicates 5a6cb57aff9e4c00a819c86e78b279864e4993b5
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:7000)
M: 8128762ecea3a8798ed5d8b06b9520c969e50cd7 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
M: 425117c39f0f201b145deb1663c994f058883009 127.0.0.1:7001
   slots:5461-10922 (5462 slots) master
M: 5a6cb57aff9e4c00a819c86e78b279864e4993b5 127.0.0.1:7002
   slots:10923-16383 (5461 slots) master
M: 9526e18bd0dee29b7deeaff25d140a0139b3962c 127.0.0.1:7003
   slots: (0 slots) master
   replicates 8128762ecea3a8798ed5d8b06b9520c969e50cd7
M: ee01f05c92b56ce9cb13619073146b6bbcc97cd3 127.0.0.1:7004
   slots: (0 slots) master
   replicates 425117c39f0f201b145deb1663c994f058883009
M: 2129adb0613dc207d37cb44d53ae11a32766c2c3 127.0.0.1:7005
   slots: (0 slots) master
   replicates 5a6cb57aff9e4c00a819c86e78b279864e4993b5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@localhost src]# 


二、常用命令:
cluster info 列出叢集資訊
cluster nodes 列出節點主從資訊
redis-trib.rb check  127.0.0.1:7000 檢查叢集狀態
cluster replicate 2b9ebcbd627ff0fd7a7bbcc5332fb09e72788835  指定當前連結節點為2b9ebcbd627ff0fd7a7bbcc5332fb09e72788835 的從庫


cluster資料操作:
redis-cli -c -p xxxx 可以看到資料會自動寫入到對應的節點中




節點新增、刪除、slot分配 請看redis-trib.rb幫助,簡單明瞭:


redis-trib.rb
Usage: redis-trib


  del-node        host:port node_id
  set-timeout     host:port milliseconds
  add-node        new_host:new_port existing_host:existing_port
                  --master-id
                  --slave
  help            (show this help)
  call            host:port command arg arg .. arg
  check           host:port
  create          host1:port1 ... hostN:portN
                  --replicas
  import          host:port
                  --from
  reshard         host:port
                  --from
                  --slots
                  --yes
                  --to
  fix             host:port


For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.





官方文件:http://redis.io/topics/cluster-tutorial

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20625855/viewspace-1676162/,如需轉載,請註明出處,否則將追究法律責任。

相關文章