Redis集群(单机多实例)

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查看节点信息:

猜你喜欢

转载自www.cnblogs.com/hyj2357/p/10576668.html