Redis 3.0 Cluster集群配置

时间:2022-10-29 07:43:37

Redis 3.0 Cluster集群配置

安装环境依赖

安装gcc:yum install gcc

安装zlib:yum install zib

安装ruby:yum install ruby

安装rubygems:yum install rubygems

安装ruby的redis驱动:gem install redis

安装redis

参考:http://www.cnblogs.com/rwxwsblog/p/5285732.html

修改配置文件

vi 6379.conf

port=6379
pidfile /var/run/redis_6379.pid
logfile /var/log/redis_6379.log
daemonize=yes
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
appendonly yes
dir /var/lib/redis/6379

复制相应的配置文件并按上述配置文件修改相应的配置(注意端口和路径)

cp 6379.conf 6380.conf
cp 6379.conf 6381.conf
cp 6379.conf 6382.conf
cp 6379.conf 6383.conf
cp 6379.conf 6384.conf
cp 6379.conf 6385.conf

依次修改相应的配置文件6380.conf6381.conf6382.conf6383.conf6384.conf6385.conf

如:vi 6380.conf

批量替换端口:%s/6379/6380/g并保存

创建数据文件目录

mkdir -p /var/lib/redis/6380 /var/lib/redis/6381 /var/lib/redis/6382 /var/lib/redis/6383 /var/lib/redis/6384 /var/lib/redis/6385

创建集群

  • 安装并配置完后6379端口的redis实例需要重启,否则会报错
  • 创建前需要分别启动redis实例

cp redis-3.0.7/src/redis-trib.rb /usr/local/bin/

redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385

创建集群实例及异常情况

[root@cas ~]# redis-trib.rb create --replicas 1  127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385
>>> Creating cluster
[ERR] Node 127.0.0.1:6379 is not configured as a cluster node.
[root@cas ~]# ps -ef|grep redis
root 22342 1 0 10:29 ? 00:00:03 /usr/local/bin/redis-server *:6379
root 22456 1 0 10:51 ? 00:00:00 redis-server *:6380 [cluster]
root 22460 1 0 10:51 ? 00:00:00 redis-server *:6381 [cluster]
root 22464 1 0 10:52 ? 00:00:00 redis-server *:6382 [cluster]
root 22470 1 0 10:52 ? 00:00:00 redis-server *:6383 [cluster]
root 22474 1 0 10:52 ? 00:00:00 redis-server *:6384 [cluster]
root 22478 1 0 10:52 ? 00:00:00 redis-server *:6385 [cluster]
root 23530 22364 0 10:58 pts/1 00:00:00 grep --color=auto redis
[root@cas ~]# kill 22342
[root@cas ~]# redis-server /etc/redis/6379.conf
[root@cas ~]# ps -ef|grep redis
root 22456 1 0 10:51 ? 00:00:00 redis-server *:6380 [cluster]
root 22460 1 0 10:51 ? 00:00:00 redis-server *:6381 [cluster]
root 22464 1 0 10:52 ? 00:00:00 redis-server *:6382 [cluster]
root 22470 1 0 10:52 ? 00:00:00 redis-server *:6383 [cluster]
root 22474 1 0 10:52 ? 00:00:00 redis-server *:6384 [cluster]
root 22478 1 0 10:52 ? 00:00:00 redis-server *:6385 [cluster]
root 23534 1 0 10:59 ? 00:00:05 redis-server *:6379 [cluster]
root 23532 22364 0 10:59 pts/1 00:00:00 grep --color=auto redis
[root@cas ~]# redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385
>>> Creating cluster
>>> Performing hash slots allocation on 7 nodes...
Using 3 masters:
127.0.0.1:6379
127.0.0.1:6380
127.0.0.1:6381
Adding replica 127.0.0.1:6382 to 127.0.0.1:6379
Adding replica 127.0.0.1:6383 to 127.0.0.1:6380
Adding replica 127.0.0.1:6384 to 127.0.0.1:6381
Adding replica 127.0.0.1:6385 to 127.0.0.1:6379
M: 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9 127.0.0.1:6379
slots:0-5460 (5461 slots) master
M: c8b630395c21c10edaf7644bd691ec06f73b9403 127.0.0.1:6380
slots:5461-10922 (5462 slots) master
M: 0d9eaa1f846081556ceedf41d92939b9f142b698 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
S: 124283594652936b01287e0c7fda5b9b8b6e15ad 127.0.0.1:6382
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
S: febaa9b89d0589e36bc7fd66d14173042e2158ed 127.0.0.1:6383
replicates c8b630395c21c10edaf7644bd691ec06f73b9403
S: 402c2e5d1f9284b09098f43cd9f14821fc7be8cf 127.0.0.1:6384
replicates 0d9eaa1f846081556ceedf41d92939b9f142b698
S: 51af4cfa2ab1b144cc72058175442ff15808a912 127.0.0.1:6385
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
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:6379)
M: 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9 127.0.0.1:6379
slots:0-5460 (5461 slots) master
M: c8b630395c21c10edaf7644bd691ec06f73b9403 127.0.0.1:6380
slots:5461-10922 (5462 slots) master
M: 0d9eaa1f846081556ceedf41d92939b9f142b698 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
M: 124283594652936b01287e0c7fda5b9b8b6e15ad 127.0.0.1:6382
slots: (0 slots) master
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
M: febaa9b89d0589e36bc7fd66d14173042e2158ed 127.0.0.1:6383
slots: (0 slots) master
replicates c8b630395c21c10edaf7644bd691ec06f73b9403
M: 402c2e5d1f9284b09098f43cd9f14821fc7be8cf 127.0.0.1:6384
slots: (0 slots) master
replicates 0d9eaa1f846081556ceedf41d92939b9f142b698
M: 51af4cfa2ab1b144cc72058175442ff15808a912 127.0.0.1:6385
slots: (0 slots) master
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

检查redis集群的健康状况

[root@cas ~]# redis-trib.rb check 127.0.0.1:6379
>>> Performing Cluster Check (using node 127.0.0.1:6379)
M: 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9 127.0.0.1:6379
slots:0-5460 (5461 slots) master
2 additional replica(s)
S: 402c2e5d1f9284b09098f43cd9f14821fc7be8cf 127.0.0.1:6384
slots: (0 slots) slave
replicates 0d9eaa1f846081556ceedf41d92939b9f142b698
M: c8b630395c21c10edaf7644bd691ec06f73b9403 127.0.0.1:6380
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 0d9eaa1f846081556ceedf41d92939b9f142b698 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 124283594652936b01287e0c7fda5b9b8b6e15ad 127.0.0.1:6382
slots: (0 slots) slave
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
S: febaa9b89d0589e36bc7fd66d14173042e2158ed 127.0.0.1:6383
slots: (0 slots) slave
replicates c8b630395c21c10edaf7644bd691ec06f73b9403
S: 51af4cfa2ab1b144cc72058175442ff15808a912 127.0.0.1:6385
slots: (0 slots) slave
replicates 477a3dad67b2a3ff8bd70e3b3c8a6112eab081e9
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

管理cluster

添加节点

add-node的使用方法为new_host:new_port existing_host:existing_port,前面是新添加的节点信息,后面是已存在的节点信息
redis-trib.rb add-node 192.168.3.61:6379 192.168.3.88:6379

数据分片及删除节点

参考:http://blog.sina.com.cn/s/blog_75ad98f30102w6po.html

参考文档:

Redis 3.0 Cluster集群配置的更多相关文章

  1. 配置redis 4.0.11 集群

    配置redis 4.0.11 集群 准备redis 软件和redis配置文件 启动Redis服务 /data/soft/redis/src/redis-check-aof --fix /log/red ...

  2. Redis高可用之集群配置(六)

    0.Redis目录结构 1)Redis介绍及部署在CentOS7上(一) 2)Redis指令与数据结构(二) 3)Redis客户端连接以及持久化数据(三) 4)Redis高可用之主从复制实践(四) 5 ...

  3. Redis 5.0.5集群搭建

    Redis 5.0.5集群搭建 一.概述 Redis3.0版本之后支持Cluster. 1.1.redis cluster的现状 目前redis支持的cluster特性: 1):节点自动发现 2):s ...

  4. Redis-5.0.5集群配置

    版本:redis-5.0.5 参考:http://redis.io/topics/cluster-tutorial. 集群部署交互式命令行工具:https://github.com/eyjian/re ...

  5. CentOS7.1.x+Druid 0.12 集群配置

    原文转载自:https://blog.csdn.net/bigtree_3721/article/details/79583008 先决条件:安装版本列表 本次安装满足下面的条件: CentOS v7 ...

  6. Redis 3.0.5 集群的命令、使用、维护

    cluster命令 CLUSTER INFO 打印集群的信息 CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息. //节点 CLUSTER MEET < ...

  7. redis 3&period;0的集群部署

    转载请注明出处:http://hot66hot.iteye.com/admin/blogs/2050676 最近研究redis-cluster,正好搭建了一个环境,遇到了很多坑,系统的总结下,等到re ...

  8. (转)redis 3&period;0的集群部署

    一:关于redis cluster 1:redis cluster的现状 reids-cluster计划在redis3.0中推出,可以看作者antirez的声明:http://antirez.com/ ...

  9. Redis 3&period;0&period;2集群搭建以及相关问题汇总

    Redis3 正式支持了 cluster,是为了解决构建redis集群时的诸多不便 (1)像操作单个redis一样操作key,不用操心key在哪个节点上(2)在线动态添加.删除redis节点,不用停止 ...

随机推荐

  1. redmine Windows装配

    原文:http://www.myexception.cn/windows/1219064.html redmine Windows安装 官方地址:http://www.redmine.org/ 所需环 ...

  2. Android开发百度地图(一)--显示基本地图

    最近由于比赛的需要,自己学习了一下百度地图的开发.希望以下的内容能够对大家有用. 一.开发前的准备工作: 1.注册百度账号,并登录.(有百度账号的话直接登录) 2.申请Key,地址:http://de ...

  3. ecshop 嵌入地图加载不了问题

    在ecshop 添加一个标识商家地理位置信息. 百度地图,加载不出来,查了下发现跟 js/transport.js 与 js/utils.js 两个文件有关在需要插入地图的地方去掉这两个文件的引用 地 ...

  4. arcgis for js 根据多边形自动缩放

    交代背景:多边形已经渲染在图层上,然后根据多边形自动缩放值合适的大小: 思路:获取图层信息,获取图层中的几何信息,获取图形范围信息,在地图上设置范围:(下面的方法有封装)记一下思路就好 var pol ...

  5. 炫酷MD风之dialog各种对话框

    这个demo也是我从别人那里学来的,不是本人写的代码,我也是个MD初学者.把这个demo分享给看到的你,希望对你有帮助. 直接上图: demo地址:百度网盘:链接:https://pan.baidu. ...

  6. &lbrack;转帖&rsqb;TLS 1&period;3 VS TLS 1&period;2,让你明白 TLS 1&period;3 的强大

    TLS 1.3 VS TLS 1.2,让你明白 TLS 1.3 的强大 https://www.jianshu.com/p/efe44d4a7501?utm_source=oschina-app 又拍 ...

  7. delphi操作sqlite3

    Delphi SQLite 简明无废话上手指南SQLite下载http://www.sqlite.org/download.html SQLite FAQhttp://www.sqlitecn.org ...

  8. GIT rebase讲解

    对分支进行rebase 从master分支checkout出fork分支,并在master和fork上都进行了一些修改 现在fork分支想要及时的同步master分支上的修改,避免在已经失效的代码上继 ...

  9. MyBatis高级及其SSM框架搭建

    代码生成器 首先meaven项目中导入支持包 <dependencies> <!-- https://mvnrepository.com/artifact/mysql/mysql-c ...

  10. Java-Runoob:Java String 类

    ylbtech-Java-Runoob:Java String 类 1.返回顶部 1. Java String 类 字符串广泛应用 在Java 编程中,在 Java 中字符串属于对象,Java 提供了 ...