redis cluster(集群)模式的创建方式
redis常用的架构有三种,单例、哨兵、集群,其他的都说过了,这里只简单介绍集群搭建。
单例最简单没什么好说的。
哨兵之前说过,该模式下有哨兵节点监视master和slave,若master宕机可自动将slave转为master,但它也有一个问题,就是不能动态扩充,并且存储大小受每个节点的内存大小限制。
集群模式Redis-Cluster,采用无中心结构,每个节点都和集群内其他节点有连接,数据可以跨主机分布式存储,解决了存储大小受主机限制的问题,Redis集群预分好16384个插槽(slot),每个节点分配一部分slot,当需要在 Redis 集群中放置一个 key-value 时,根据哈希算法决定将key放到哪个slot中,进而找到对应存放数据的主机,查询数据也一样。
集群模式内部同样可以配置主从,例如集群有六个数据节点,可以设置三个主节点,每个主节点对应一个从节点,当一个主节点宕机,可以自动将从节点变成主节点,保证整个集群还能用。但是一个主节点和对应的从节点都宕机后集群将不可用。每个主节点可以配置多个从节点。
集群搭建步骤
1、创建几台虚机,(集群模式最少要三个主节点)例如我们搭建一个三主三从的集群,创建六台虚机,当然要测试的话也可以部署在同一台主机上,使用不同的端口模拟不同主机。
2、在每台主机上安装redis,注意redis配置文件需要注意cluster相关的配置,例如修改cluster-enabled 的值是yes,表示开启集群,其他的超时时间等配置根据实际修改或默认。
3、redis安装完之后不会自己变成集群,还需要执行创建集群的命令,这个每个版本不太一样,redis5使用redis-cli --cluster ,redis3使用redis-trib.rb,下面具体说。
redis5集群创建
redis5的cluster相关命令,此处只写创建,当然还支持添加节点、删除、对solt进行操作等
[root@fvb9wbpl-clustermanager-e0hhllme ~]# redis-cli --cluster help
Cluster Manager Commands:
create host1:port1 ... hostN:portN
--cluster-replicas <arg>
check host:port
--cluster-search-multiple-owners
info host:port
fix host:port
--cluster-search-multiple-owners
reshard host:port
--cluster-from <arg>
--cluster-to <arg>
--cluster-slots <arg>
--cluster-yes
--cluster-timeout <arg>
--cluster-pipeline <arg>
--cluster-replace
rebalance host:port
--cluster-weight <node1=w1...nodeN=wN>
--cluster-use-empty-masters
--cluster-timeout <arg>
--cluster-simulate
--cluster-pipeline <arg>
--cluster-threshold <arg>
--cluster-replace
add-node new_host:new_port existing_host:existing_port
--cluster-slave
--cluster-master-id <arg>
del-node host:port node_id
call host:port command arg arg .. arg
set-timeout host:port milliseconds
import host:port
--cluster-from <arg>
--cluster-copy
--cluster-replace
help For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.
创建主从集群命令,后面是集群的ip地址和端口,cluster-replicas 1表示一个主节点对应1个从节点,创建成功后会自动分配主从关系
redis-cli --cluster create --cluster-replicas 10.110.30.136: 10.110.30.137: 10.110.30.138: 10.110.30.144: 10.110.30.145: 10.110.30.146: 出现提示后再输入yes,然后开始创建集群
创建成功后查看集群,后面的ip可以是集群中的任意一个节点,结果中的M代表主节点,当M节点宕机后集群会自动把S节点变成M节点,这个可以自行测试
[root@fvb9wbpl-clustermanager-e0hhllme ~]# redis-cli --cluster check 10.110.30.68:
10.110.30.70: (5e49929d...) -> keys | slots | slaves.
10.110.30.69: (6dc594c5...) -> keys | slots | slaves.
10.110.30.112: (2b9a0210...) -> keys | slots | slaves.
[OK] keys in masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 10.110.30.68:)
S: 15a969da394187e239baab1cc57bc6ec810996fe 10.110.30.68:
slots: ( slots) slave
replicates 2b9a0210b3223a1d865324ec32cc70f8ebcbaf65
S: 095777fb0d8ad380e420b9ef465d202a745a14e6 10.110.30.114:
slots: ( slots) slave
replicates 6dc594c5180f655603504ab68591b2e7492c7963
S: 20a33128f5353d36cb084d6ae2bf24c5b4806538 10.110.30.113:
slots: ( slots) slave
replicates 5e49929d47e7bd438ea2e25c3731179f460eb387
M: 5e49929d47e7bd438ea2e25c3731179f460eb387 10.110.30.70:
slots:[-] ( slots) master
additional replica(s)
M: 6dc594c5180f655603504ab68591b2e7492c7963 10.110.30.69:
slots:[-] ( slots) master
additional replica(s)
M: 2b9a0210b3223a1d865324ec32cc70f8ebcbaf65 10.110.30.112:
slots:[-] ( slots) master
additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
redis3集群创建
redis3不支持cluster,3版本创建集群使用redis-trib.rb,当然还需要ruby等不在这里介绍。
redis-trib.rb的参数跟cluster类似,了解了上面的下面这个一看就懂,基本一样的
[root@mucuijwb-clustermanager-o9sprluh bin]# /usr/local/bin/redis-trib.rb help
Usage: redis-trib <command> <options> <arguments ...> create host1:port1 ... hostN:portN
--replicas <arg>
check host:port
info host:port
fix host:port
--timeout <arg>
reshard host:port
--from <arg>
--to <arg>
--slots <arg>
--yes
--timeout <arg>
--pipeline <arg>
rebalance host:port
--weight <arg>
--auto-weights
--use-empty-masters
--timeout <arg>
--simulate
--pipeline <arg>
--threshold <arg>
add-node new_host:new_port existing_host:existing_port
--slave
--master-id <arg>
del-node host:port node_id
set-timeout host:port milliseconds
call host:port command arg arg .. arg
import host:port
--from <arg>
--copy
--replace
help (show this help) For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.
创建主从集群命令,参数含义跟cluster的一样
/usr/local/bin/redis-trib.rb create --replicas 10.110.30.74: 10.110.30.137: 10.110.30.138: 10.110.30.144: 10.110.30.145: 10.110.30.146:
检查集群
[root@mucuijwb-clustermanager-o9sprluh bin]# /usr/local/bin/redis-trib.rb check 10.110.30.74:
>>> Performing Cluster Check (using node 10.110.30.74:)
M: 7483d09dadda2ecebd9fdbd6b1f186769e00904d 10.110.30.74:
slots:- ( slots) master
additional replica(s)
M: 76ecc2cf2ddc07fe7f2fda53f2f5318198321761 10.110.30.72:
slots:- ( slots) master
additional replica(s)
M: 0f60c9c6595726d391805f5acfaf5be13496346a 10.110.30.73:
slots:- ( slots) master
additional replica(s)
S: 6f56bbe811be2ff97ef654777ae48c3ae5d83824 10.110.30.111:
slots: ( slots) slave
replicates 76ecc2cf2ddc07fe7f2fda53f2f5318198321761
S: 8c3bb1ed5e531665dfedf126df5121b76dc604d4 10.110.30.110:
slots: ( slots) slave
replicates 7483d09dadda2ecebd9fdbd6b1f186769e00904d
S: 543c3b42c93ccac1728eaa5d5c9a43938f922890 10.110.30.108:
slots: ( slots) slave
replicates 0f60c9c6595726d391805f5acfaf5be13496346a
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
集群连接
客户端连接集群模式可以直接连接redis节点,不需要再经过中间节点转发,客户端连接集群,需要加 -c 参数,否则插入数据会报错
[root@fvb9wbpl-rediscluster-vddntq84 ~]# redis-cli -c
127.0.0.1:> dbsize
(integer)
127.0.0.1:>
连接其他主机
[root@fvb9wbpl-rediscluster-vddntq84 ~]# redis-cli -c -h 10.110.30.113 -p
10.110.30.113:> dbsize
(integer)
10.110.30.113:>
插入数据和查询数据,注意对插槽slot的分配操作,可以看出来是分布式存储的
[root@fvb9wbpl-rediscluster-vddntq84 ~]# redis-cli -c -h 10.110.30.113 -p
10.110.30.113:> set foo bar
-> Redirected to slot [] located at 10.110.30.112:
OK10.110.30.112:> set c d
-> Redirected to slot [] located at 10.110.30.69:
OK
10.110.30.69:>
10.110.30.69:> get foo
-> Redirected to slot [] located at 10.110.30.112:
"bar"
10.110.30.112:> get c
-> Redirected to slot [] located at 10.110.30.69:
"d"
10.110.30.69:>
redis cluster(集群)模式的创建方式的更多相关文章
- Redis cluster集群模式的原理
redis cluster redis cluster是Redis的分布式解决方案,在3.0版本推出后有效地解决了redis分布式方面的需求 自动将数据进行分片,每个master上放一部分数据 提供内 ...
- Azure Redis Cache (5) Redis Cache Cluster集群模式
<Windows Azure Platform 系列文章目录> Redis Cluster 3.0之后的版本,已经支持Redis Cluster集群模式,Redis Cluster采用无中 ...
- centos6下redis cluster集群部署过程
一般来说,redis主从和mysql主从目的差不多,但redis主从配置很简单,主要在从节点配置文件指定主节点ip和端口,比如:slaveof 192.168.10.10 6379,然后启动主从,主从 ...
- Ubuntu 16.04下Redis Cluster集群搭建(官方原始方案)
前提:先安装好Redis,参考:http://www.cnblogs.com/EasonJim/p/7599941.html 说明:Redis Cluster集群模式可以做到动态增加节点和下线节点,使 ...
- Docker 搭建 Redis Cluster 集群环境
使用 Docker 搭建 Redis Cluster,最重要的环节就是容器通信的问题,这一块我们在之前的文章中已经给大家解决了<Docker 网络模式详解及容器间网络通信>,本篇文章主要练 ...
- 搭建分布式 Redis Cluster 集群与 Redis 入门
目录 Redis 集群搭建 Redis 是啥 集群(Cluster) Redis Cluster 说明 Redis Cluster 节点 Redis Cluster 集群模式 不能保证一致性 创建和使 ...
- Redis系列5:深入分析Cluster 集群模式
Redis系列1:深刻理解高性能Redis的本质 Redis系列2:数据持久化提高可用性 Redis系列3:高可用之主从架构 Redis系列4:高可用之Sentinel(哨兵模式) 1 背景 前面我们 ...
- K8S部署Redis Cluster集群(三主三从模式) - 部署笔记
一.Redis 介绍 Redis代表REmote DIctionary Server是一种开源的内存中数据存储,通常用作数据库,缓存或消息代理.它可以存储和操作高级数据类型,例如列表,地图,集合和排序 ...
- docker下创建redis cluster集群
概述 在Redis中,集群的解决方案有三种 主从复制 哨兵机制 Cluster Redis Cluster是Redis的分布式解决方案,在 3.0 版本正式推出. 准备工作 1.确定本机IP地址 2. ...
随机推荐
- Linux 如何找到100M以上的大文件
find / -type f -size +100000k |xargs ls -lh|awk '{print $9 ":" $5}'
- PTA(Basic Level)1039.到底买不买
小红想买些珠子做一串自己喜欢的珠串.卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖.于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子 ...
- Vue框架下实现导入导出Excel、导出PDF
项目需求:开发一套基于Vue框架的工程档案管理系统,用于工程项目资料的填写.编辑和归档,经调研需支持如下功能: Excel报表的导入.导出 PDF文件的导出 打印表格 经过技术选型,项目组一致决定通过 ...
- appium+python教程1
Python3+Appium安装使用教程 一.安装 我们知道selenium是桌面浏览器自动化操作工具(Web Browser Automation) appium是继承selenium自动化思想旨在 ...
- 在django中进行后台管理时插入外键数据时不显示值的问题
在django的后台管理站点插入数据时,发现需要添加外键时,下拉框中不显示值 按照显示内容中的object,考虑这里应该是调用的模型类的objects对象方法,那么去models.py中对模型类添加一 ...
- 你除了在客户端上会使用Cookie,还能使用哪些可以作为数据缓存呢?
问题如标题,直奔主题.介绍下另两种缓存. 1.sessionStorage.localStorage localStorage: 是一种你不主动清除它,它会一直将存储数据存储在客户端的存储方式,即使你 ...
- 关于SpringMVC中的转发与重定向的说明
写的非常详细,参看该地址:https://www.zifangsky.cn/661.html 总结: 1.请求转发:url地址不变,可带参数,如?username=forward 2.请求重定向:ur ...
- 常见三种加密(MD5、非对称加密,对称加密)
转载. https://blog.csdn.net/SSY_1992/article/details/79094556 任何应用的开发中安全都是重中之重,在信息交互异常活跃的现在,信息加密技术显得尤为 ...
- 深入理解C++11 C3
继承构造函数 class A { public: A(int i):m_i(i) {} A(double d, int i):m_d(d),m_i(i){} private: int m_i{0}; ...
- Payload 实现分离免杀
众所周知,目前的杀毒软件的杀毒原理主要有三种方式,一种基于特征,一种基于行为,一种基于云查杀,其中云查杀的一些特点基本上也可以概括为特征码查杀,不管是哪一种杀毒软件,都会检查PE文件头,尤其是当后门程 ...