深入分析redis cluster 集群安装配置详解

下面小编来为各位介绍一篇深入分析redis cluster 集群安装配置详解,如果你希望做数据库集群就可以来看看此文章的哦。

http://ruby.taobao.org/  
# gem source -l  
  
# gem install redis --version 3.0.0  //安装gem_redis  
Successfully installed redis-3.0.0  
1 gem installed  
Installing ri documentation for redis-3.0.0...  
Installing RDoc documentation for redis-3.0.0...  
以前写过一篇ruby on rails的文章,请参考:centos ruby on rails apache mysql 安装配置详解
喜欢手动编译的人,可以参考这篇文章,安装ruby.

三,安装redis3.0.0

1,安装redis
   
# wget http://download.redis.io/releases/redis-3.0.0.tar.gz  
# tar -xvzf redis-3.0.0.tar.gz  
# cd redis-3.0.0  
# make && make install  
# cd src  
# cp redis-trib.rb /usr/local/bin    
  
# mkdir /etc/redis  
# mkdir /var/log/redis  
上述操作要先在二台机器上面都操作好。

2,配置redis
   
[root@slave2 redis-3.0.0]#  vim redis.conf   //解压的根目录,有redis.conf,做以下修改  
port 6379  
pidfile /var/run/redis-6379.pid  
dbfilename dump-6379.rdb  
appendfilename "appendonly-6379.aof"  
cluster-config-file nodes-6379.conf  
cluster-enabled yes  
cluster-node-timeout 5000  
appendonly yes

3,copy配置文件,并修改端口
   
# cp redis.conf /etc/redis/redis-6379.conf  
# cp redis.conf /etc/redis/redis-6380.conf  
# cp redis.conf /etc/redis/redis-6381.conf  
  
# scp redis.conf 192.168.10.220:/etc/redis/redis-6382.conf  
# scp redis.conf 192.168.10.220:/etc/redis/redis-6383.conf  
# scp redis.conf 192.168.10.220:/etc/redis/redis-6384.conf  
  
# sed -i "s/6379/6380/g" /etc/redis/redis-6380.conf  
# sed -i "s/6379/6381/g" /etc/redis/redis-6381.conf  
  
# sed -i "s/6379/6382/g" /etc/redis/redis-6382.conf  
# sed -i "s/6379/6383/g" /etc/redis/redis-6383.conf  
# sed -i "s/6379/6384/g" /etc/redis/redis-6384.conf  
将配置文件分别copy到二台机器上,并替换端口:
   
# cat redis-6380.conf |awk '{if($0 !~ /^$/ && $0 !~ /#/) {print $0}}' |grep 6380  
pidfile /var/run/redis-6380.pid  
port 6380  
dbfilename dump-6380.rdb  
appendfilename "appendonly-6380.aof"  
cluster-config-file nodes-6380.conf  
有5处修改端口的地方

4,启动并查看redis
   
# redis-server /etc/redis/redis-6379.conf > /var/log/redis/redis-6379.log 2>&1 &  
# redis-server /etc/redis/redis-6380.conf > /var/log/redis/redis-6380.log 2>&1 &  
# redis-server /etc/redis/redis-6381.conf > /var/log/redis/redis-6381.log 2>&1 &  
  
# redis-server /etc/redis/redis-6382.conf > /var/log/redis/redis-6382.log 2>&1 &  
# redis-server /etc/redis/redis-6383.conf > /var/log/redis/redis-6383.log 2>&1 &  
# redis-server /etc/redis/redis-6384.conf > /var/log/redis/redis-6384.log 2>&1 &  
  
# netstat -tpnl |grep redis  
tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      7298/redis-server *  
tcp        0      0 0.0.0.0:6380                0.0.0.0:*                   LISTEN      7299/redis-server *  
tcp        0      0 0.0.0.0:6381                0.0.0.0:*                   LISTEN      7304/redis-server *  
tcp        0      0 0.0.0.0:16379               0.0.0.0:*                   LISTEN      7298/redis-server *  
tcp        0      0 0.0.0.0:16380               0.0.0.0:*                   LISTEN      7299/redis-server *  
tcp        0      0 0.0.0.0:16381               0.0.0.0:*                   LISTEN      7304/redis-server *  
tcp        0      0 :::6379                     :::*                        LISTEN      7298/redis-server *  
tcp        0      0 :::6380                     :::*                        LISTEN      7299/redis-server *  
tcp        0      0 :::6381                     :::*                        LISTEN      7304/redis-server *  
tcp        0      0 :::16379                    :::*                        LISTEN      7298/redis-server *  
tcp        0      0 :::16380                    :::*                        LISTEN      7299/redis-server *  
tcp        0      0 :::16381                    :::*                        LISTEN      7304/redis-server *  
  
[root@slave2 redis]# ll /etc/redis/

总用量 156

-rw-r--r-- 1 root root     0 4月  30 23:54 appendonly-6379.aof  
-rw-r--r-- 1 root root     0 5月   1 00:08 appendonly-6380.aof  
-rw-r--r-- 1 root root     0 5月   1 00:08 appendonly-6381.aof  
-rw-r--r-- 1 root root    18 5月   1 00:08 dump-6379.rdb  
-rw-r--r-- 1 root root    18 5月   1 00:08 dump-6380.rdb  
-rw-r--r-- 1 root root    18 5月   1 00:08 dump-6381.rdb  
-rw-r--r-- 1 root root   763 5月   1 00:08 nodes-6379.conf  
-rw-r--r-- 1 root root   763 5月   1 00:08 nodes-6380.conf  
-rw-r--r-- 1 root root   763 5月   1 00:08 nodes-6381.conf  
-rw-r--r-- 1 root root 41412 4月  30 23:30 redis-6379.conf  
-rw-r--r-- 1 root root 41412 4月  30 23:39 redis-6380.conf  
-rw-r--r-- 1 root root 41412 4月  30 23:39 redis-6381.conf

所有节点都启动成功,并不代表,他们就是集群了。

四,创建集群,并查看

1,创建redis集群

# redis-trib.rb create --replicas 1 192.168.10.219:6379 192.168.10.219:6380 192.168.10.219:6381 192.168.10.220:6382 192.168.10.220:6383 192.168.10.220:6384  
2,查看redis集群状态
   
[root@slave2 redis]# redis-trib.rb check 192.168.10.219:6379  
Connecting to node 192.168.10.219:6379: OK  
Connecting to node 192.168.10.220:6384: OK  
Connecting to node 192.168.10.219:6381: OK  
Connecting to node 192.168.10.220:6383: OK  
Connecting to node 192.168.10.220:6382: OK  
Connecting to node 192.168.10.219:6380: OK  
>>> Performing Cluster Check (using node 192.168.10.219:6379)  
M: d40d9a367c24784b0336c7b80fb4c87337e2cba6 192.168.10.219:6379  
 slots:5461-10922 (5462 slots) master  
 1 additional replica(s)  
S: 5f00f163d0c0a540ea99daf004f55588a802327b 192.168.10.220:6384  
 slots: (0 slots) slave  
 replicates d40d9a367c24784b0336c7b80fb4c87337e2cba6  
S: b3b1a848987b5a87a06888e126d5c9b16f871ff5 192.168.10.219:6381  
 slots: (0 slots) slave  
 replicates d2eb5a8a77f87888792428aed4692dfb907e7a1d  
M: d2eb5a8a77f87888792428aed4692dfb907e7a1d 192.168.10.220:6383  
 slots:10923-16383 (5461 slots) master  
 1 additional replica(s)  
M: a8eafe8b19d6a28c034917da13a43ce1230fe870 192.168.10.220:6382  
 slots:0-5460 (5461 slots) master  
 1 additional replica(s)  
S: a87d207204a53ab599bf7f6ffb9d679d0eef4f25 192.168.10.219:6380  
 slots: (0 slots) slave  
 replicates a8eafe8b19d6a28c034917da13a43ce1230fe870  
[OK] All nodes agree about slots configuration.  
>>> Check for open slots...  
>>> Check slots coverage...  
[OK] All 16384 slots covered.

到这儿,redis集群就配置成功了

五,测试redis集群
   
# redis-cli -c -p 6379 -h 192.168.10.219   //在219登录  
192.168.10.219:6379> set tank tank1    //设置测试值  
-> Redirected to slot [4407] located at 192.168.10.220:6382  
OK   //直接转向到220 6382端口,数据存到了220 6382,不过有点奇怪  
192.168.10.220:6382> get tank   //可以取到值  
"tank1"  
  
[root@manage redis]# redis-cli -c -p 6383 -h 192.168.10.220  //220机器,6383端口  
192.168.10.220:6383> get tank  
-> Redirected to slot [4407] located at 192.168.10.220:6382  //直接转向220 6382端口  
"tank1"  
  
[root@manage redis]# ps aux |grep redis //查看进程  
root      7310  0.2  0.9 137436  9724 pts/0    Sl   Apr30   0:09 redis-server *:6382 [cluster]  
root      7311  0.2  0.9 137436  9776 pts/0    Sl   Apr30   0:09 redis-server *:6383 [cluster]  
root      7316  0.2  0.9 137436  9944 pts/0    Sl   Apr30   0:10 redis-server *:6384 [cluster]  
root      7478  0.0  0.0 103256   812 pts/0    S+   00:56   0:00 grep redis  
  
[root@manage redis]# kill -9 7310  //关闭220 6382端口,看数据会不会丢失  
  
[root@slave2 redis]# redis-trib.rb check 192.168.10.219:6379  //查看集群情况,任何接口都行  
Connecting to node 192.168.10.219:6379: OK  
Connecting to node 192.168.10.220:6384: OK  
Connecting to node 192.168.10.219:6381: OK  
Connecting to node 192.168.10.220:6383: OK  
Connecting to node 192.168.10.219:6380: OK  
>>> Performing Cluster Check (using node 192.168.10.219:6379)  
M: d40d9a367c24784b0336c7b80fb4c87337e2cba6 192.168.10.219:6379  
 slots:5461-10922 (5462 slots) master  
 1 additional replica(s)  
S: 5f00f163d0c0a540ea99daf004f55588a802327b 192.168.10.220:6384  
 slots: (0 slots) slave  
 replicates d40d9a367c24784b0336c7b80fb4c87337e2cba6  
S: b3b1a848987b5a87a06888e126d5c9b16f871ff5 192.168.10.219:6381  
 slots: (0 slots) slave  
 replicates d2eb5a8a77f87888792428aed4692dfb907e7a1d  
M: d2eb5a8a77f87888792428aed4692dfb907e7a1d 192.168.10.220:6383  
 slots:10923-16383 (5461 slots) master  
 1 additional replica(s)  
M: a87d207204a53ab599bf7f6ffb9d679d0eef4f25 192.168.10.219:6380  
 slots:0-5460 (5461 slots) master  
 0 additional replica(s)  
[OK] All nodes agree about slots configuration.  
>>> Check for open slots...  
>>> Check slots coverage...  
[OK] All 16384 slots covered.  //变成,三主二从了  
  
[root@slave2 redis]# redis-cli -c -p 6379 -h 192.168.10.219    //219登录  
192.168.10.219:6379> get tank  
-> Redirected to slot [4407] located at 192.168.10.219:6380   //数据被转到了6380节点了  
"tank1"  
经测试,集群是可用的。

深入分析redis cluster 集群的更多相关文章

  1. Redis Cluster集群搭建与配置

    Redis Cluster是一种服务器sharding分片技术,关于Redis的集群方案应该怎么做,请参考我的另一篇博客http://www.cnblogs.com/xckk/p/6134655.ht ...

  2. jedis处理redis cluster集群的密码问题

    环境介绍:jedis:2.8.0 redis版本:3.2 首先说一下redis集群的方式,一种是cluster的 一种是sentinel的,cluster的是redis 3.0之后出来新的集群方式 本 ...

  3. Redis Cluster集群搭建与应用

    1.redis-cluster设计 Redis集群搭建的方式有多种,例如使用zookeeper,但从redis 3.0之后版本支持redis-cluster集群,redis-cluster采用无中心结 ...

  4. Redis Cluster集群主从方案

    本文介绍一种通过Jedis和Cluster实现Redis集群(主从)的高可用方案,该方案需要使用Jedis2.8.0(推荐),Redis3.0及以上版本(强制). 附:Redis Cluster集群主 ...

  5. CentOS7 安装Redis Cluster集群

    上一篇中已经讲到了如何安装单击版Redis,这一篇我们来说下如何安装Cluster,关于哨兵模式这里我就不写文章安装了,有兴趣的同学可以自己去研究,哨兵模式可以在主从模式下在创建三台机器的哨兵集群监控 ...

  6. Redis Cluster集群架构实现(四)--技术流ken

    Redis集群简介 通过前面三篇博客的介绍<Redis基础认识及常用命令使用(一)--技术流ken>,<Redis基础知识补充及持久化.备份介绍(二)--技术流ken>,< ...

  7. 【精】搭建redis cluster集群,JedisCluster带密码访问【解决当中各种坑】!

    转: [精]搭建redis cluster集群,JedisCluster带密码访问[解决当中各种坑]! 2017年05月09日 00:13:18 冉椿林博客 阅读数:18208  版权声明:本文为博主 ...

  8. redis cluster集群web管理工具 relumin

    redis cluster集群web管理工具 relumin 下载地址 https://github.com/be-hase/relumin 只支持redis cluster模式 java环境 tar ...

  9. Redis Cluster集群知识学习总结

    Redis集群解决方案有两个: 1)  Twemproxy: 这是Twitter推出的解决方案,简单的说就是上层加个代理负责分发,属于client端集群方案,目前很多应用者都在采用的解决方案.Twem ...

随机推荐

  1. 【转】CentOS6.5 增加一个SFTP上传的用户

    原文链接地址:http://www.msits.com/archives/4477.html #创建sftp组groupadd sftp#创建一个用户zjhpuseradd -g sftp -s /b ...

  2. ※数据结构※→☆线性表结构(list)☆============单向循环链表结构(list circular single)(四)

    循环链表是另一种形式的链式存贮结构.它的特点是表中最后一个结点的指针域指向头结点,整个链表形成一个环. 单循环链表——在单链表中,将终端结点的指针域NULL改为指向表头结点或开始结点即可. 循环链表的 ...

  3. java.lang.NoClassDefFoundError: ognl/PropertyAccessor解决的方法

    本来不想为这个专门写一篇文章的,可是发现这么简单的一个问题居然没有人好好回答过.从方便搜索的角度考虑,特意取了这么一个题目. 事实上解决方法就是将ognl的jar包增加就可以. 比方我用的是ognl3 ...

  4. HDURevenge of Segment Tree(第二长的递增子序列)

    HDURevenge of Segment Tree(第二长的递增子序列) 题目链接 题目大意:这题是求第二长的递增子序列. 解题思路:用n^2的算法来求LIS,可是这里还要记录一下最长的那个序列是否 ...

  5. UVA 10581 - Partitioning for fun and profit(数论递推)

    10581 - Partitioning for fun and profit 题目链接 题意:给定m, n,表示分配给n个格子,分配m个数字进去,每一个格子最少1,而且序列要是递增的,问第k个字典序 ...

  6. PHP - 表单与验证

    第11章 表单与验证 学习要点: 1.Header()函数 2.接收及验证数据 我们对Web感兴趣,认为它有用的原因是其主要通过基于HTML的表单发布和收集信息的能力.这些表单用来鼓励网站的反馈.进行 ...

  7. Route@书写规则的总结

    路由书写规则的总结 概念:Routing System由一组路由组成,每一个路由规则可以匹配一种类型的URL,在请求过来的时候,Ruting ystem 就用它来处理这个URL,路由的任务就是匹配UR ...

  8. OC中多线程的一些概念

    1.进程1.1>进程是指在系统中正在运行的一个应用程序(同时打开QQ和Xcode,系统会分别启动2个进程)1.2>每个进程之间是独立的,每个进程均运行在其专用的且受保护的内存空间内 2.线 ...

  9. Android应用公布的准备——渠道注冊与认证

    今天早上申请了一个早上的渠道账号,这工作真是太繁琐,申请的是企业账号,须要营业执照等相关资料,假设申请个人的话预计须要身份证相关信息.以下贴出国内主流的几个渠道.不全然,可是基本上涵盖了大部分. 36 ...

  10. Endnote X6 如何修改输出格式(output style)成为自己想要的输出格式:

    Endnote X6 如何修改输出格式(output style)成为自己想要的输出格式: (1)首先尝试在endnote output style 网站中查找: http://www.endnote ...