Redis介绍

  Redis是一个分布式缓存数据库服务器,提供基于内存访问的缓存服务,并且无论是在单服务器还是服务器集群上都有着较为灵活方便的扩展能力。

  单个的Redis实例是单进程单线程的,由于这个原因,Redis对于实例本身不需要考虑种种访问线程共享资源所带来的并发性问题,因为所有的线程访问都是队列顺序执行的。如果需要扩容,需要配置多实例。

单机多实例配置

  Redis实例是基于配置文件的,redis-server根据conf生成并运行实例,因此需要多实例的话需要配置对应数目的Conf,

    bind 127.0.0.1    # 绑定主机ip
port 7001 # 开启的端口
daemonize yes # 是否后台运行
pidfile /var/run/redis_7001.pid # pid文件名称
cluster-enabled yes # 开启集群
cluster-config-file nodes-7001.conf # 集群节点文件
dbfilename dump-7001.rdb # 数据备份名称

  单机情况下通过监听多端口的方式实现多实例,建立集群时只需要复制多份conf,并根据上面的conf修改对应的端口号即可。

  

  在开启实例后(7001,7002),进入到redis-cli之中

    127.0.0.1:7001> cluster help
1) CLUSTER <subcommand> arg arg ... arg. Subcommands are:
2) ADDSLOTS <slot> [slot ...] -- Assign slots to current node.
3) BUMPEPOCH -- Advance the cluster config epoch.
4) COUNT-failure-reports <node-id> -- Return number of failure reports for <node-id>.
5) COUNTKEYSINSLOT <slot> - Return the number of keys in <slot>.
6) DELSLOTS <slot> [slot ...] -- Delete slots information from current node.
7) FAILOVER [force|takeover] -- Promote current replica node to being a master.
8) FORGET <node-id> -- Remove a node from the cluster.
9) GETKEYSINSLOT <slot> <count> -- Return key names stored by current node in a slot.
10) FLUSHSLOTS -- Delete current node own slots information.
11) INFO - Return onformation about the cluster.
12) KEYSLOT <key> -- Return the hash slot for <key>.
13) MEET <ip> <port> [bus-port] -- Connect nodes into a working cluster.
14) MYID -- Return the node id.
15) NODES -- Return cluster configuration seen by node. Output format:
16) <id> <ip:port> <flags> <master> <pings> <pongs> <epoch> <link> <slot> ... <slot>
17) REPLICATE <node-id> -- Configure current node as replica to <node-id>.
18) RESET [hard|soft] -- Reset current node (default: soft).
19) SET-config-epoch <epoch> - Set config epoch of current node.
20) SETSLOT <slot> (importing|migrating|stable|node <node-id>) -- Set slot state.
21) REPLICAS <node-id> -- Return <node-id> replicas.
22) SLOTS -- Return information about slots range mappings. Each range is made of:
23) start, end, master and replicas IP addresses, ports and ids

  使用cluster meet 127.0.0.1 7002与7002实例建立握手连接:

  

  使用cluster nodes查看节点信息:

  

Redis 5.0以上版本不再使用redis-trib.rb

  Redis 5.0以上版本不再使用redis-trib.rb,而是统一使用Cli进行集群创建和配置

![](https://img2018.cnblogs.com/blog/915947/201903/915947-20190325113611458-1397645995.png)

总结

  上面是一个最简单的单机多实例集群搭建过程,事实上Redis还提供了一个很方便的集群搭建脚本redis-trib.rb,利用这个脚本能更轻松地搭建多机器多实例集群。下一篇将介绍如何使用redis-trib.rb来构建多机器多实例的集群。

Redis集群(单机多实例)的更多相关文章

  1. springBoot2.*使用redis集群/单机方法

    在springboot1.x系列中,其中使用的是jedis,但是到了springboot2.x其中使用的是Lettuce. 此处springboot2.x,所以使用的是Lettuce.关于jedis跟 ...

  2. 峰Redis学习(10)Redis 集群(单机多节点集群和多机多节点集群)

    单机多节点集群:参考博客:http://blog.java1234.com/blog/articles/326.html 多机多节点集群:参考博客:http://blog.java1234.com/b ...

  3. Redis系列九 Redis集群

    1. redis-cluster架构图 redis-cluster投票:容错 架构细节 ①所有的redis节点彼此互联(PING-PONG机制),内部使用二进制协议优化传输速度和带宽. ②节点的fai ...

  4. 14.6、redis集群

    1.环境配置: 服务器名称 ip地址 实例6379 实例6380 实例6381 实例6381 实例6381 实例6381 controller-node1 172.16.1.90 主 从 主 从 主 ...

  5. 面试官问我Redis集群,我真的是

    面试官:聊下Redis的分片集群,先聊 Redis Cluster好咯? 面试官:Redis Cluser是Redis 3.x才有的官方集群方案,这块你了解多少? 候选者:嗯,要不还是从基础讲起呗? ...

  6. redis单机安装以及简单redis集群搭建

    安装环境: 两台虚拟机都是Centos 7.0 IP分别为:192.168.149.132  192.168.149.133 Redis采用的版本是redis-3.2.4 集群是采用两台虚拟机模拟8个 ...

  7. centos6搭建redis集群搭建(单机多节点)

    一.安装redis 1.安装gcc环境 yum install gcc-c++ 2.下载源码包并解压 wget http://download.redis.io/releases/redis-3.2. ...

  8. Redis笔记 -- 在 Centos7.4单机中部署Redis集群(二)

    0x00--背景和目的 在单台PC服务器上部署Redis集群,通过不同的TCP端口启动多实例,模拟多台独立PC组成集群. 0x01--环境描述: Centos版本:CentOS Linux relea ...

  9. redis在Windows下以后台服务一键搭建集群(单机--伪集群)

    redis在Windows下以后台服务一键搭建集群(单机--伪集群) 一.概述 此教程介绍如何在windows系统中同一台机器上布置redis伪集群,同时要以后台服务的模式运行.布置以脚本的形式,一键 ...

  10. 通过jedis连接redis单机成功,使用redis客户端可以连接集群,但使用JedisCluster连接redis集群一直报Could not get a resource from the pool

    一,问题描述: (如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool 但是使 ...

随机推荐

  1. 常见查找算法(Java代码实现)

    一,顺序查找 查找算法中顺序查找算是最简单的了,无论是有序的还是无序的都可以,只需要一个个对比即可,但其实效率很低.我们来看下代码 public static int search(int[] a, ...

  2. ui component 是一个前端 mvc 开发框架

  3. 【Solution】API测试工具,访问方式

    1. post的时候,@requestBody 用 json的传递方式

  4. AIX7.1环境打补丁缺少bash OPATCHAUTO-72049

    DB:12.1.0.2.0 RAC OS:AIX 7.1 [To patch only the GI home] su - root export UNZIPPED_PATCH_LOCATION=/o ...

  5. python迭代-如何对迭代器做切片操作

    如何对迭代器做切片操作 问题举例 读取某个文件内容的100~300行内容,我们是否可以使用 类似列表切片的方式得到一个100~300行文件内容的生成器 分析 列表的切片操作其实是在重载方法__getI ...

  6. MFC Dialog使用

    1. OnInitDialog 对话框初始化函数 在MFC主对话框OnInitDialog()中弹出对话框 BOOL CXXXDlg::OnInitDialog() { CDialogEx::OnIn ...

  7. ubuntu16.04利用deb包安装mysql

    https://blog.csdn.net/zht741322694/article/details/79013093

  8. 在userMapper.xml文件中模糊查询的常用的3种方法

    在userMapper.xml文件中新建映射sql的标签 <!-- ******************** 模糊查询的常用的3种方式:********************* --> ...

  9. html5 css多列布局

    p{    text-indent: 2em;    line-height: 2em;}h4{    -webkit-column-span:all;    background: green;   ...

  10. datatable的select()结果直接修改,会体现在表上

    如果你只是要修改DataTable里的DataRow的话没有必要找到它的行号,直接在Select后得到的DataRow上修改就行了,它的修改会直接反映到DataTable上(其实就是直接修改了Data ...