您的位置:首页 > 数据库 > Redis

redis高可用之redis3.0集群

2015-05-29 07:18 621 查看
一、安装配置:
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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/20625855/viewspace-1676162/

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: