博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Redis 3.0 Cluster集群配置
阅读量:5734 次
发布时间:2019-06-18

本文共 6331 字,大约阅读时间需要 21 分钟。

安装环境依赖
安装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.conf、6381.conf、6382.conf、6383.conf、6384.conf、6385.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://www.cnblogs.com/rwxwsblog/p/6030606.html,如需转载请自行联系原作者
你可能感兴趣的文章
基础知识:python模块的导入
查看>>
Android MVC之我的实现
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
关于批处理-1
查看>>
Tomcat部署Web应用方法总结
查看>>
Python3 django2.0 字段加密 解密 AES
查看>>
CCNA实验之:网络地址转换(NAT)实验
查看>>
计算机网络原理笔记-停止等待协议
查看>>
洛谷P3763 [TJOI2017]DNA(后缀自动机)
查看>>
确定当前记录和下一条记录之间相差的天数
查看>>
NYOJ32:组合数(DFS入门)
查看>>
使用Callable和Future接口创建线程
查看>>
BZOJ 2568 比特集合
查看>>
sql语句返回主键SCOPE_IDENTITY()
查看>>
MongoDB培训
查看>>
机器学习开源项目精选TOP30
查看>>
代码分析系列 内存执行过程
查看>>
iOS开发-邮件发送
查看>>
/etc/resolv.conf文件详解
查看>>