redis cluster集群创建和使用

利用原生命令手动部署redis cluster

使用六台centos8服务器

[13:03:10 root@localhost ~]#yum -y install redis #在所有6个节点上安装redis服务
[13:04:02 root@localhost ~]#sed -i.bak -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e '/masterauth/a masterauth 123456' -e '/# requirepass/a requirepass 123456' -e '/# cluster-enabled yes/a cluster-enabled yes' -e '/# cluster-config-file nodes-6379.conf/a cluster-config-file nodes-6379.conf' -e '/cluster-require-full-coverage yes/c cluster-require-full-coverage no' /etc/redis.conf #修改所有节点的配置文件,按顺序排序分别是:修改redis监听端口;修改主节点密码;修改自身登录密码;开启cluster模式;配置cluster的配置文件路径,记录主从关系和槽位信息;关闭集群请求槽位全覆盖,该选项开启的话,如果集群中有一个主库宕机且无备库就会使整个集群不对外提供服务
[13:31:49 root@localhost ~]#systemctl enable --now redis #启动redis并设置为开机启动
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.
[14:18:47 root@localhost ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.18 6379 #使用meet使所有节点实现互相通信,登录任意一台节点来meet其他所有要加入到本集群中的节点
OK
[14:24:12 root@localhost ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.28 6379
OK
[14:24:19 root@localhost ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.38 6379
OK
[14:24:22 root@localhost ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.48 6379
OK
[14:24:24 root@localhost ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.58 6379
OK
[14:32:31 root@localhost ~]#vi addslot.sh #编写一个分配槽位的脚本,并利用脚本分配槽位,redis cluster的槽位范围为0-16364

#!/bin/bash
# 
#********************************************************************
#Author:            rzx
#QQ:                970707452
#Date:              2020-10-25
#FileName:         addslot.sh
#URL:               https://www.cnblogs.com/rzx-006/
#Description:      The test script
#Copyright (C):    2020 All rights reserved
#********************************************************************
host=$1
port=$2
start=$3
end=$4
pass=123456
for slot in `seq ${
      start} ${
      end}`;do
    echo slot:$slot
    redis-cli -h ${host} -p ${port} -a ${pass} --no-auth-warning cluster addslots ${slot}
done

[14:46:05 root@localhost ~]#bash addslot.sh 10.0.0.8 6379 0 5461 #利用脚本为10.0.0.8分配槽位
[14:46:05 root@localhost ~]#redis-cli -h 10.0.0.8 -a 123456 cluster info #查看10.0.0.8的集群状态
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
cluster_state:ok
cluster_slots_assigned:5462 #整个集群当中已经分配的槽位数量
cluster_slots_ok:5462
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:1
cluster_current_epoch:5
cluster_my_epoch:1
cluster_stats_messages_ping_sent:1342
cluster_stats_messages_pong_sent:1341
cluster_stats_messages_meet_sent:5
cluster_stats_messages_sent:2688
cluster_stats_messages_ping_received:1341
cluster_stats_messages_pong_received:1347
cluster_stats_messages_received:2688
[14:47:02 root@localhost ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster nodes
66173bbc45b3f8e9212286827bb5fc594aab0cd7 10.0.0.58:6379@16379 master - 0 1603608771000 5 connected
4ad896ab9a5e573061decaea13ca72f1acc16d22 10.0.0.48:6379@16379 master - 0 1603608772000 3 connected
e1e8b3a666bb3f15b3b73c689782d9a1236beab3 10.0.0.38:6379@16379 master - 0 1603608773663 0 connected
208ee5ef0b688df38824552b2154b64869175b9e 10.0.0.8:6379@16379 myself,master - 0 1603608773000 1 connected 0-5461 #分配到的槽位号
b75c9952210283a64f1ce10c5e1ad85d18dc1b36 10.0.0.28:6379@16379 master - 0 1603608771616 4 connected
50083258803ac6bc106182853e6d0bc1ebdee45d 10.0.0.18:6379@16379 master - 0 1603608772647 2 connected

[14:54:10 root@localhost ~]#bash addslot.sh 10.0.0.18 6379 5462 10922 #利用脚本为10.0.0.18分配槽位
[14:55:29 root@localhost ~]#bash addslot.sh 10.0.0.28 6379 10923 16383 #利用脚本为10.0.0.28分配槽位

[14:55:29 root@localhost ~]#redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster nodes
66173bbc45b3f8e9212286827bb5fc594aab0cd7 10.0.0.58:6379@16379 master - 0 1603609539000 5 connected
4ad896ab9a5e573061decaea13ca72f1acc16d22 10.0.0.48:6379@16379 master - 0 1603609540900 3 connected
e1e8b3a666bb3f15b3b73c689782d9a1236beab3 10.0.0.38:6379@16379 master - 0 1603609541915 0 connected
208ee5ef0b688df38824552b2154b64869175b9e 10.0.0.8:6379@16379 myself,master - 0 1603609536000 1 connected 0-5461
b75c9952210283a64f1ce10c5e1ad85d18dc1b36 10.0.0.28:6379@16379 master - 0 1603609539884 4 connected 10923-16383
50083258803ac6bc106182853e6d0bc1ebdee45d 10.0.0.18:6379@16379 master - 0 1603609540000 2 connected 5462-10922

[15:05:42 root@localhost ~]#redis-cli -h 10.0.0.38 -a 123456 --no-auth-warning cluster replicate 208ee5ef0b688df38824552b2154b64869175b9e
OK #连接到10.0.0.38,为其指定master节点,master节点ID可以通过cluster nodes查看
[15:14:31 root@localhost ~]#redis-cli -h 10.0.0.48 -a 123456 --no-auth-warning cluster replicate b75c9952210283a64f1ce10c5e1ad85d18dc1b36
OK #连接到10.0.0.48,为其指定master节点,master节点ID可以通过cluster nodes查看
[15:14:51 root@localhost ~]#redis-cli -h 10.0.0.58 -a 123456 --no-auth-warning cluster replicate 50083258803ac6bc106182853e6d0bc1ebdee45d
OK #连接到10.0.0.58,为其指定master节点,master节点ID可以通过cluster nodes查看

[15:17:08 root@localhost ~]#redis-cli -h 10.0.0.58 -a 123456 --no-auth-warning cluster nodes
208ee5ef0b688df38824552b2154b64869175b9e 10.0.0.8:6379@16379 master - 0 1603610406000 1 connected 0-5461
4ad896ab9a5e573061decaea13ca72f1acc16d22 10.0.0.48:6379@16379 slave b75c9952210283a64f1ce10c5e1ad85d18dc1b36 0 1603610406176 4 connected
50083258803ac6bc106182853e6d0bc1ebdee45d 10.0.0.18:6379@16379 master - 0 1603610404000 2 connected 5462-10922
b75c9952210283a64f1ce10c5e1ad85d18dc1b36 10.0.0.28:6379@16379 master - 0 1603610405162 4 connected 10923-16383
e1e8b3a666bb3f15b3b73c689782d9a1236beab3 10.0.0.38:6379@16379 slave 208ee5ef0b688df38824552b2154b64869175b9e 0 1603610407196 1 connected
66173bbc45b3f8e9212286827bb5fc594aab0cd7 10.0.0.58:6379@16379 myself,slave 50083258803ac6bc106182853e6d0bc1ebdee45d 0 1603610403000 5 connected
[15:20:07 root@localhost ~]#redis-cli -h 10.0.0.58 -a 123456 --no-auth-warning cluster info #完成搭建后查看集群状态
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:2
cluster_stats_messages_ping_sent:3333
cluster_stats_messages_pong_sent:3184
cluster_stats_messages_meet_sent:1
cluster_stats_messages_sent:6518
cluster_stats_messages_ping_received:3179
cluster_stats_messages_pong_received:3334
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:6518
[15:21:05 root@localhost ~]#redis-cli -h 10.0.0.58 -a 123456 --no-auth-warning cluster slots #查看主从关系以及槽位信息
1) 1) (integer) 0
   2) (integer) 5461
   3) 1) "10.0.0.8"
      2) (integer) 6379
      3) "208ee5ef0b688df38824552b2154b64869175b9e"
   4) 1) "10.0.0.38"
      2) (integer) 6379
      3) "e1e8b3a666bb3f15b3b73c689782d9a1236beab3"
2) 1) (integer) 5462
   2) (integer) 10922
   3) 1) "10.0.0.18"
      2) (integer) 6379
      3) "50083258803ac6bc106182853e6d0bc1ebdee45d"
   4) 1) "10.0.0.58"
      2) (integer) 6379
      3) "66173bbc45b3f8e9212286827bb5fc594aab0cd7"
3) 1) (integer) 10923
   2) (integer) 16383
   3) 1) "10.0.0.28"
      2) (integer) 6379
      3) "b75c9952210283a64f1ce10c5e1ad85d18dc1b36"
   4) 1) "10.0.0.48"
      2) (integer) 6379
      3) "4ad896ab9a5e573061decaea13ca72f1acc16d22"

[15:27:42 root@localhost ~]#redis-cli -h 10.0.0.58 -a 123456 --no-auth-warning set key1 v1 #当写入或读取的数据不保存至本机的槽位中时,会提示需要到另一台节点执行
(error) MOVED 9189 10.0.0.18:6379
[15:27:50 root@localhost ~]#redis-cli -h 10.0.0.58 -a 123456 --no-auth-warning -c set key1 v1 #加-c选项会自动重定向到目标节点执行
OK
[15:30:42 root@localhost ~]#redis-cli -h 10.0.0.58 -a 123456 --no-auth-warning -c get key1
"v1"
[15:31:15 root@localhost ~]#redis-cli -h 10.0.0.58 -a 123456 --no-auth-warning  get key1
(error) MOVED 9189 10.0.0.18:6379
[16:12:29 root@localhost ~]#redis-cli -a 123456 --no-auth-warning cluster keyslot 123 #计算key对应的槽位值
(integer) 5970

[16:14:39 root@localhost ~]#dnf -y instal1 python3 #安装python环境
[16:15:02 root@localhost ~]#pip3 insta71 redis-py-cluster #安装模块
[16:51:50 root@localhost ~]#vi redis_cluster_test.py #redis cluster批量写入数据py脚本

#!/usr/bin/env python3
from rediscluster import RedisCluster
startup_nodes = [
    {
     "host":"10.0.0.8", "port":6379},
    {
     "host":"10.0.0.18", "port":6379},
    {
     "host":"10.0.0.28", "port":6379},
    {
     "host":"10.0.0.38", "port":6379},
    {
     "host":"10.0.0.48", "port":6379},
    {
     "host":"10.0.0.58", "port":6379}
]
redis_conn= RedisCluster(startup_nodes=startup_nodes,password='123456',decode_responses=True)
for i in range(0,10000):
    redis_conn.set('key'+str(i),'value'+str(i))
    print('key'+str(i)+':',redis_conn.get('key'+str(i))) 

基于redis 5.0部署redis cluster

使用六台centos8服务器

[15:43:10 root@localhost ~]#yum -y install redis #在所有6个节点上安装redis服务
[15:44:02 root@localhost ~]#sed -i.bak -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e '/masterauth/a masterauth 123456' -e '/# requirepass/a requirepass 123456' -e '/# cluster-enabled yes/a cluster-enabled yes' -e '/# cluster-config-file nodes-6379.conf/a cluster-config-file nodes-6379.conf' -e '/cluster-require-full-coverage yes/c cluster-require-full-coverage no' /etc/redis.conf #修改所有节点的配置文件,按顺序排序分别是:修改redis监听端口;修改主节点密码;修改自身登录密码;开启cluster模式;配置cluster的配置文件路径,记录主从关系和槽位信息;关闭集群请求槽位全覆盖,该选项开启的话,如果集群中有一个主库宕机且无备库就会使整个集群不对外提供服务
[15:48:49 root@localhost ~]#systemctl enable --now redis #启动redis并设置为开机启动
[15:51:40 root@localhost ~]#redis-cli -a 123456 --cluster create 10.0.0.8:6379 10.0.0.18:6379 10.0.0.28:6379 10.0.0.38:6379 10.0.0.48:6379 10.0.0.58:6379 --cluster-replicas 1 #一条命令实现原生命令的meet过程、分配槽位、设置主从关系,--cluster-replicas 1表示每个主节点有几个从节点;命令默认前三节点个为主,后三个依次对应前三个主节点,
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460 #自动为三个主节点分配槽位
Master[1] -> Slots 5461 - 10922 
Master[2] -> Slots 10923 - 16383
Adding replica 10.0.0.38:6379 to 10.0.0.8:6379 #自动配置主从关系
Adding replica 10.0.0.48:6379 to 10.0.0.18:6379
Adding replica 10.0.0.58:6379 to 10.0.0.28:6379
M: b530ab922788d06da1cb85012d384ffb4fb7824f 10.0.0.8:6379 #显示节点的主从关系和槽位信息
   slots:[0-5460] (5461 slots) master
M: 43e25d5358edef69bac0dee5c964d20dda20ca4c 10.0.0.18:6379
   slots:[5461-10922] (5462 slots) master
M: 5f5f4a0032a71f307a3c710ae4fda6f6eb40c3d1 10.0.0.28:6379
   slots:[10923-16383] (5461 slots) master
S: 82ae5c91bbe25cfcd9815e4d9bd4c4d90ad4e7ab 10.0.0.38:6379
   replicates b530ab922788d06da1cb85012d384ffb4fb7824f
S: 9c21796fbc967ebd57ea30fcf7516926bdba6988 10.0.0.48:6379
   replicates 43e25d5358edef69bac0dee5c964d20dda20ca4c
S: 4acdb613601f3538eebf023df81f6cb887b617a0 10.0.0.58:6379
   replicates 5f5f4a0032a71f307a3c710ae4fda6f6eb40c3d1
Can I set the above configuration? (type 'yes' to accept): yes #输入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 10.0.0.8:6379)
M: b530ab922788d06da1cb85012d384ffb4fb7824f 10.0.0.8:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 43e25d5358edef69bac0dee5c964d20dda20ca4c 10.0.0.18:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 5f5f4a0032a71f307a3c710ae4fda6f6eb40c3d1 10.0.0.28:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 4acdb613601f3538eebf023df81f6cb887b617a0 10.0.0.58:6379
   slots: (0 slots) slave
   replicates 5f5f4a0032a71f307a3c710ae4fda6f6eb40c3d1
S: 9c21796fbc967ebd57ea30fcf7516926bdba6988 10.0.0.48:6379
   slots: (0 slots) slave
   replicates 43e25d5358edef69bac0dee5c964d20dda20ca4c
S: 82ae5c91bbe25cfcd9815e4d9bd4c4d90ad4e7ab 10.0.0.38:6379
   slots: (0 slots) slave
   replicates b530ab922788d06da1cb85012d384ffb4fb7824f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered. #所有槽位分配完成
#redis 5.0的redis cluster配置完成
[16:09:32 root@localhost ~]#redis-cli -a 123456 cluster nodes #检查一下集群节点信息
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
43e25d5358edef69bac0dee5c964d20dda20ca4c 10.0.0.18:6379@16379 master - 0 1603613374183 2 connected 5461-10922
b530ab922788d06da1cb85012d384ffb4fb7824f 10.0.0.8:6379@16379 myself,master - 0 1603613373000 1 connected 0-5460
5f5f4a0032a71f307a3c710ae4fda6f6eb40c3d1 10.0.0.28:6379@16379 master - 0 1603613372000 3 connected 10923-16383
4acdb613601f3538eebf023df81f6cb887b617a0 10.0.0.58:6379@16379 slave 5f5f4a0032a71f307a3c710ae4fda6f6eb40c3d1 0 1603613374000 6 connected
9c21796fbc967ebd57ea30fcf7516926bdba6988 10.0.0.48:6379@16379 slave 43e25d5358edef69bac0dee5c964d20dda20ca4c 0 1603613375205 5 connected
82ae5c91bbe25cfcd9815e4d9bd4c4d90ad4e7ab 10.0.0.38:6379@16379 slave b530ab922788d06da1cb85012d384ffb4fb7824f 0 1603613375000 4 connected

基于rendis 4.0部署redis cluster

使用六台centos7服务器

[17:20:10 root@localhost ~]#vi install_redis_for_centos.sh  #自动编译安装redis4.0.14脚本

#!/bin/bash
#
#********************************************************************
#Author:        wangxiaochun
#URL:           http://www.magedu.com
#Description:      The test script
#Copyright (C):     2020 All rights reserved
#********************************************************************
. /etc/init.d/functions 
VERSION=redis-4.0.14
PASSWORD=123456
INSTALL_DIR=/apps/redis

install() {
     
yum  -y install gcc jemalloc-devel || {
      action "安装软件包失败,请检查网络配置" false ; exit; }

wget http://download.redis.io/releases/${VERSION}.tar.gz || {
      action "Redis 源码下载失败" false ; exit; }



tar xf ${VERSION}.tar.gz
cd ${VERSION}


ln -s ${INSTALL_DIR}/bin/redis-*  /usr/bin/
mkdir -p ${INSTALL_DIR}/{
     etc,log,data,run}
cp redis.conf  ${INSTALL_DIR}/etc/



if id redis &> /dev/null ;then 
    action "Redis 用户已存在" false  
else
    useradd -r -s /sbin/nologin redis
    action "Redis 用户创建成功"
fi

chown -R redis.redis ${INSTALL_DIR}

vm.overcommit_memory = 1
EOF
sysctl -p 

echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
/etc/rc.d/rc.local

cat > /usr/lib/systemd/system/redis.service <<EOF
[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
ExecStart=${INSTALL_DIR}/bin/redis-server ${INSTALL_DIR}/etc/redis.conf --supervised systemd
ExecStop=/bin/kill -s QUIT \$MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

EOF
systemctl daemon-reload 
systemctl enable --now  redis &> /dev/null && action "Redis 服务启动成功,Redis信息如下:" || {
      action "Redis 启动失败" false ;exit; } 

redis-cli -a $PASSWORD INFO Server 2> /dev/null

}

install

[17:24:51 root@localhost ~]#bash install_redis_for_centos.sh #在所有节点执行脚本来安装redis
[17:53:59 root@localhost ~]#sed -i -e '/^# masterauth/a masterauth 123456' -e '/# cluster-enabled yes/a cluster-enabled yes' -e '/# cluster-config-file nodes-6379.conf/a cluster-config-file nodes-6379.conf' -e '/cluster-require-full-coverage yes/c cluster-require-full-coverage no' /apps/redis/etc/redis.conf #修改所有reids的配置文件
[17:41:51 root@localhost ~]#systemctl restart redis #重启redis
[17:56:24 root@localhost ~]#cp redis-4.0.14/src/redis-trib.rb /usr/bin/ #拷贝redis-trib.rb工具到/usr/bin下,方便使用
[18:24:54 root@localhost ~]#yum -y install ruby #安装ruby环境,但是由于cneots7yum安装ruby版本太低,需要执行其他操作
[18:52:33 root@localhost ~]#yum -y install gcc openssl-devel zlib-devel #安装编译ruby依赖包
[18:53:00 root@localhost ~]#wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.5.tar.gz #下载ruby2.5.5的源码包
--2020-10-25 18:53:24--  https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.5.tar.gz
Resolving cache.ruby-lang.org (cache.ruby-lang.org)... 151.101.77.178, 2a04:4e42:12::434
Connecting to cache.ruby-lang.org (cache.ruby-lang.org)|151.101.77.178|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15996436 (15M) [application/x-tar]
Saving to: ‘ruby-2.5.5.tar.gz’

100%[=================================================================>] 15,996,436  82.9KB/s   in 2m 57s 

2020-10-25 18:56:27 (88.2 KB/s) - ‘ruby-2.5.5.tar.gz’ saved [15996436/15996436]


[18:56:27 root@localhost ~]#tar xf ruby-2.5.5.tar.gz  #解压源码包
[18:58:51 root@localhost ruby-2.5.5]#cd ruby-2.5.5 
[18:58:51 root@localhost ruby-2.5.5]#./configure #执行configure脚本生成makefile文件
[18:59:33 root@localhost ruby-2.5.5]#make && make install #编译安装ruby
[19:06:18 root@localhost ruby-2.5.5]#ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux] #查看ruby版本,然后重新登录终端
[19:17:37 root@localhost ~]#gem install -l redis-4.1.3.gem #安装redis模块,此为安装离线包,需提前将文件下载好,下载链接:https://rubygems.org/downloads/redis-4.1.3.gem ,注意下载此包需要科学上网
Successfully installed redis-4.1.3
Parsing documentation for redis-4.1.3
Installing ri documentation for redis-4.1.3
Done installing documentation for redis after 0 seconds
1 gem installed
[19:20:38 root@localhost ~]#vi /usr/local/lib/ruby/gems/2.5.0/gems/redis-4.1.3/lib/redis/client.rb 

# frozen_string_literal: true

require_relative "errors"
require "socket"
require "cgi"

class Redis
  class Client

    DEFAULTS = {
     
      :url => lambda {
      ENV["REDIS_URL"] },
      :scheme => "redis",
      :host => "127.0.0.1",
      :port => 6379,
      :path => nil,
      :timeout => 5.0,
      :password => 123456,   #修改脚本中连接redis的密码                                                                               
      :db => 0,
      :driver => nil,
      :id => nil,
      :tcp_keepalive => 0,
      :reconnect_attempts => 1,
      :reconnect_delay => 0,
      :reconnect_delay_max => 0.5,
      :inherit_socket => false
    }

    attr_reader :options

[19:21:49 root@localhost ~]#redis-trib.rb create --replicas 1 10.0.0.7:6379 10.0.0.17:6379 10.0.0.27:6379 10.0.0.37:6379 10.0.0.47:6379 10.0.0.57:6379 #创建redis cluster集群,与redis5.0集群不同的是,从节点会随机分配给主节点,而非按顺序一一对应
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.0.0.7:6379
10.0.0.17:6379
10.0.0.27:6379
Adding replica 10.0.0.47:6379 to 10.0.0.7:6379
Adding replica 10.0.0.57:6379 to 10.0.0.17:6379
Adding replica 10.0.0.37:6379 to 10.0.0.27:6379
M: bf18eec99802798b5215ed2f8ddc12eb1248b3cb 10.0.0.7:6379
   slots:0-5460 (5461 slots) master
M: a0c915ad50c0ad66a0a4c7b6393d9e127576ad64 10.0.0.17:6379
   slots:5461-10922 (5462 slots) master
M: 97b1c4b57dbf5469bab57577f0bc022bd59917e6 10.0.0.27:6379
   slots:10923-16383 (5461 slots) master
S: b18f0f29e766120656abd946b957ef0bd712d638 10.0.0.37:6379
   replicates 97b1c4b57dbf5469bab57577f0bc022bd59917e6
S: fc17f6fea452277328d913324b463a0c91029cd3 10.0.0.47:6379
   replicates bf18eec99802798b5215ed2f8ddc12eb1248b3cb
S: aca9ab569ef599a17449bd2b9088eee4533f515e 10.0.0.57:6379
   replicates a0c915ad50c0ad66a0a4c7b6393d9e127576ad64
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 10.0.0.7:6379)
M: bf18eec99802798b5215ed2f8ddc12eb1248b3cb 10.0.0.7:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 97b1c4b57dbf5469bab57577f0bc022bd59917e6 10.0.0.27:6379
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: aca9ab569ef599a17449bd2b9088eee4533f515e 10.0.0.57:6379
   slots: (0 slots) slave
   replicates a0c915ad50c0ad66a0a4c7b6393d9e127576ad64
S: fc17f6fea452277328d913324b463a0c91029cd3 10.0.0.47:6379
   slots: (0 slots) slave
   replicates bf18eec99802798b5215ed2f8ddc12eb1248b3cb
M: a0c915ad50c0ad66a0a4c7b6393d9e127576ad64 10.0.0.17:6379
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: b18f0f29e766120656abd946b957ef0bd712d638 10.0.0.37:6379
   slots: (0 slots) slave
   replicates 97b1c4b57dbf5469bab57577f0bc022bd59917e6
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

[19:31:05 root@localhost ~]#redis-cli -a 123456 cluster slots #查看集群主从关系以及槽位信息
Warning: Using a password with '-a' option on the command line interface may not be safe.
1) 1) (integer) 10923
   2) (integer) 16383
   3) 1) "10.0.0.27"
      2) (integer) 6379
      3) "97b1c4b57dbf5469bab57577f0bc022bd59917e6"
   4) 1) "10.0.0.37"
      2) (integer) 6379
      3) "b18f0f29e766120656abd946b957ef0bd712d638"
2) 1) (integer) 0
   2) (integer) 5460
   3) 1) "10.0.0.7"
      2) (integer) 6379
      3) "bf18eec99802798b5215ed2f8ddc12eb1248b3cb"
   4) 1) "10.0.0.47"
      2) (integer) 6379
      3) "fc17f6fea452277328d913324b463a0c91029cd3"
3) 1) (integer) 5461
   2) (integer) 10922
   3) 1) "10.0.0.17"
      2) (integer) 6379
      3) "a0c915ad50c0ad66a0a4c7b6393d9e127576ad64"
   4) 1) "10.0.0.57"
      2) (integer) 6379
      3) "aca9ab569ef599a17449bd2b9088eee4533f515e"

66120656abd946b957ef0bd712d638 10.0.0.37:6379
replicates 97b1c4b57dbf5469bab57577f0bc022bd59917e6
S: fc17f6fea452277328d913324b463a0c91029cd3 10.0.0.47:6379
replicates bf18eec99802798b5215ed2f8ddc12eb1248b3cb
S: aca9ab569ef599a17449bd2b9088eee4533f515e 10.0.0.57:6379
replicates a0c915ad50c0ad66a0a4c7b6393d9e127576ad64
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 10.0.0.7:6379)
M: bf18eec99802798b5215ed2f8ddc12eb1248b3cb 10.0.0.7:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 97b1c4b57dbf5469bab57577f0bc022bd59917e6 10.0.0.27:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: aca9ab569ef599a17449bd2b9088eee4533f515e 10.0.0.57:6379
slots: (0 slots) slave
replicates a0c915ad50c0ad66a0a4c7b6393d9e127576ad64
S: fc17f6fea452277328d913324b463a0c91029cd3 10.0.0.47:6379
slots: (0 slots) slave
replicates bf18eec99802798b5215ed2f8ddc12eb1248b3cb
M: a0c915ad50c0ad66a0a4c7b6393d9e127576ad64 10.0.0.17:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b18f0f29e766120656abd946b957ef0bd712d638 10.0.0.37:6379
slots: (0 slots) slave
replicates 97b1c4b57dbf5469bab57577f0bc022bd59917e6
[OK] All nodes agree about slots configuration.

Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.

[19:31:05 root@localhost ~]#redis-cli -a 123456 cluster slots #查看集群主从关系以及槽位信息
Warning: Using a password with '-a' option on the command line interface may not be safe.
1) 1) (integer) 10923
   2) (integer) 16383
   3) 1) "10.0.0.27"
      2) (integer) 6379
      3) "97b1c4b57dbf5469bab57577f0bc022bd59917e6"
   4) 1) "10.0.0.37"
      2) (integer) 6379
      3) "b18f0f29e766120656abd946b957ef0bd712d638"
2) 1) (integer) 0
   2) (integer) 5460
   3) 1) "10.0.0.7"
      2) (integer) 6379
      3) "bf18eec99802798b5215ed2f8ddc12eb1248b3cb"
   4) 1) "10.0.0.47"
      2) (integer) 6379
      3) "fc17f6fea452277328d913324b463a0c91029cd3"
3) 1) (integer) 5461
   2) (integer) 10922
   3) 1) "10.0.0.17"
      2) (integer) 6379
      3) "a0c915ad50c0ad66a0a4c7b6393d9e127576ad64"
   4) 1) "10.0.0.57"
      2) (integer) 6379
      3) "aca9ab569ef599a17449bd2b9088eee4533f515e"

你可能感兴趣的:(linux,centos,redis,mysql,数据库)