企业级nosql数据库及redis集群、应用与实战

一、概述

1.NoSQL数据库概述

NoSQL(Not Only SQL)数据库是一种用于存储和管理数据的系统,它与传统的关系型数据库(SQL数据库)在几个关键方面有所不同。NoSQL数据库通常设计用于特定的数据模型,例如文档、键值对、宽列存储或图形数据库,而不是传统SQL数据库的表格模型。以下是NoSQL数据库的一些主要特点:

  • 非关系型:不使用传统的表格关系模型。
  • 可扩展性:通常设计为分布式系统,易于水平扩展。
  • 灵活性:模式自由,可以存储不同结构的数据。
  • 高性能:优化了特定类型的数据操作,通常在读写速度上有优势。
  • 容错性:许多NoSQL数据库支持数据复制和自动故障转移。

2.Redis集群概述

Redis是一种开源的、高性能的、支持网络、可基于内存也可以持久化的键值对(key-value)存储数据库。Redis集群是Redis提供的一种数据分片解决方案,旨在通过将数据分布到多个Redis节点上来提高性能和可用性。

以下是Redis集群的一些关键特性:

  • 数据分片:数据被分散存储在多个节点上,每个节点存储一部分数据。
  • 高可用性:支持主从复制和故障转移,当主节点不可用时,从节点可以自动接管。
  • 自动重分片:在运行时可以重新分配数据,无需停机。
  • 容错性:即使部分节点失败,集群仍然可以继续工作。
  • 性能提升:通过在多个节点上分散读写操作,可以显著提高性能。

Redis集群的配置和使用

配置Redis集群通常涉及以下步骤:

  1. 安装Redis:在所有节点上安装Redis。
  2. 创建配置文件:为每个节点创建配置文件,设置端口、日志文件、数据目录等。
  3. 启动节点:使用配置文件启动所有Redis节点。
  4. 创建集群:使用redis-clicreate命令创建集群,指定节点地址和端口。
  5. 测试集群:通过连接到集群并执行命令来测试其功能。

Redis集群的管理包括监控节点状态、进行故障转移、重新分片等操作,这些通常可以通过Redis提供的命令行工具redis-cli来完成。

在使用Redis集群时,需要注意数据一致性和网络延迟问题,以及如何处理节点故障和数据迁移。Redis集群的配置和维护相对复杂,需要具备一定的专业知识。

二、nosql 和 redis 的使用方法及实战

redis的安装

首先解压

[root@redis-node1 ~]# tar zxf redis-7.4.0.tar.gz
[root@redis-node1 ~]# ls
redis-7.4.0 redis-7.4.0.tar.gz
 
###安装编译工具######所有要装redis的主机都要装
[root@redis-node1 redis-7.4.0]# dnf install make gcc initscripts-10.11.6-1.el9.x86_64 -y
 
#执行编译命令
[root@redis-node1 redis-7.4.0]# make
[root@redis-node1 redis-7.4.0]# make install
#启动Redis
[root@redis-node1 redis-7.4.0]# cd utils/
[root@redis-node1 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
This systems seems to use systemd. #提示系统使用的是systemd的初始化方式
Please take a look at the provided example service unit files in this directory, 
and adapt and install them. Sorry!
 
[root@redis-node1 utils]# vim install_server.sh #解决报错问题
#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
#       echo "This systems seems to use systemd."
#       echo "Please take a look at the provided example service unit files in 
this directory, and adapt and install them. Sorry!"
#       exit 1
#fi
 
###初始化
[root@redis-node1 utils]# ./install_server.sh
 
#配置redis
[root@redis-node1 utils]# vim /etc/redis/6379.conf
bind * -::*
protected-mode no
 
[root@redis-node1 utils]# /etc/init.d/redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...
[root@redis-node1 utils]# netstat -antlpe | grep redis
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      0 
         67267      38417/redis-server
tcp6       0      0 :::6379 

再复制到其他主机中

[root@redis-node1 ~]# ls
anaconda-ks.cfg  redis-7.4.0  redis-7.4.0.tar.gz
[root@redis-node1 ~]# scp -r redis-7.4.0 root@172.25.250.20:/root
 
[root@redis-node1 ~]# cd /usr/local/bin/
[root@redis-node1 bin]# ls
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server
[root@redis-node1 bin]# ll
total 29416
-rwxr-xr-x 1 root root  6365824 Aug 25 21:57 redis-benchmark
lrwxrwxrwx 1 root root       12 Aug 25 21:57 redis-check-aof -> redis-server
lrwxrwxrwx 1 root root       12 Aug 25 21:57 redis-check-rdb -> redis-server
-rwxr-xr-x 1 root root  7207664 Aug 25 21:57 redis-cli
lrwxrwxrwx 1 root root       12 Aug 25 21:57 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 16540544 Aug 25 21:57 redis-server
[root@redis-node1 bin]# rsync -al * root@172.25.250.20:/usr/local/bin
 
 
###到172.25.250.20查看
[root@redis-node2 ~]# ls -l /usr/local/bin/
total 29416
-rwxr-xr-x 1 root root  6365824 Aug 25 21:57 redis-benchmark
lrwxrwxrwx 1 root root       12 Aug 25 21:57 redis-check-aof -> redis-server
lrwxrwxrwx 1 root root       12 Aug 25 21:57 redis-check-rdb -> redis-server
-rwxr-xr-x 1 root root  7207664 Aug 25 21:57 redis-cli
lrwxrwxrwx 1 root root       12 Aug 25 21:57 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 16540544 Aug 25 21:57 redis-server
 
[root@redis-node2 ~]# cd redis-7.4.0/
[root@redis-node2 redis-7.4.0]# ls
00-RELEASENOTES     INSTALL      redis.conf              runtest-sentinel  TLS.md
BUGS                LICENSE.txt  REDISCONTRIBUTIONS.txt  SECURITY.md       utils
CODE_OF_CONDUCT.md  Makefile     runtest                 sentinel.conf
CONTRIBUTING.md     MANIFESTO    runtest-cluster         src
deps                README.md    runtest-moduleapi       tests
[root@redis-node2 redis-7.4.0]# cd utils/
[root@redis-node2 utils]# ls
build-static-symbols.tcl    graphs                 reply_schema_linter.js
cluster_fail_time.tcl       hyperloglog            req-res-log-validator.py
corrupt_rdb.c               install_server.sh      req-res-validator
create-cluster              lru                    speed-regression.tcl
generate-command-code.py    redis-copy.rb          srandmember
generate-commands-json.py   redis_init_script      systemd-redis_multiple_servers@.service
generate-fmtargs.py         redis_init_script.tpl  systemd-redis_server.service
generate-module-api-doc.rb  redis-sha1.rb          tracking_collisions.c
gen-test-certs.sh           releasetools           whatisdoing.sh
 
####初始化
[root@redis-node2 utils]# ./install_server.sh 
 
###改配置文件
[root@redis-node2 utils]# vim /etc/redis/6379.conf 
bind * -::*
protected-mode no
 
[root@redis-node2 ~]# /etc/init.d/redis_6379 restart

redis的基本操作

基本命令

config get *                                        查看配置

select 1                                             选择数据库

flushdb                                            清空当前数据库

move key 1                                        移动key

delkey                                                    删除

rename oldkey newkey                      修改名字

expire key time                               设置过期时间

persist key                                      设置持久化

keys user*                                          查询

exists key                                        判断是否存在

使用命令

查看配置

127.0.0.1:6379[1]> CONFIG GET bind
1) "bind"
2) "* -::*"
127.0.0.1:6379[1]> CONFIG GET * 
 
#写入和读取数据
127.0.0.1:6379> SET name lee
OK
127.0.0.1:6379> GET name
"lee"
127.0.0.1:6379> set name lee ex 5
OK
127.0.0.1:6379> get name
"lee"
127.0.0.1:6379> get name
"lee"
127.0.0.1:6379> get name
"lee"
127.0.0.1:6379> get name
"lee"
127.0.0.1:6379> get name
(nil)
#如果没有设定数据过期时间会一直存在, /var/lib/redis/6379/dump.rdb内存快照中
127.0.0.1:6379> set name lee
OK
127.0.0.1:6379> KEYS * #查看所有key
 
#选择数据库 redisa中有0-15个数据库
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> get name
(nil)
127.0.0.1:6379> select 0
127.0.0.1:6379[1]> select 16
(error) ERR DB index is out of range
 
#移动数据
127.0.0.1:6379> set name lee
OK
127.0.0.1:6379> MOVE name 1
(integer) 1
127.0.0.1:6379> GET name
(nil)
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> get name
"lee"
 
#改变键名
127.0.0.1:6379[1]> RENAME name id
OK
127.0.0.1:6379[1]> get name
(nil)
127.0.0.1:6379[1]> get id
"lee"
 
#设定数据过期时间
127.0.0.1:6379> set name lee ex 10000
OK
127.0.0.1:6379> get name
"lee"
127.0.0.1:6379> EXPIRE name 3
(integer) 1
127.0.0.1:6379> get name
"lee"
127.0.0.1:6379> get name
(nil)
 
#删除
127.0.0.1:6379> set name lee
OK
127.0.0.1:6379> get name
"lee"
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> get name
(nil)
 
 
#持久化保存
127.0.0.1:6379> PERSIST name
(integer) 0
 
 
#判断key是否存在
127.0.0.1:6379> EXISTS name
(integer) 1
127.0.0.1:6379> EXISTS lee
(integer) 0 
 
#清空当前库
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> GET name
(nil)
 
#清空所有库
127.0.0.1:6379[1]> FLUSHALL
OK

配置主从同步

修改节点配置文件

[root@redis-node1 & node2 & node3 ~]# vim /etc/redis/6379.confprotected-mode no           #关闭protected模式
[root@redis-node1 &node2 & node3 ~]# /etc/init.d/redis_6379 restart
######在master节点
[root@redis-node1 ~]# redis-cli 
127.0.0.1:6379> set name ren
OK
127.0.0.1:6379> get name
"ren"
####在slave1查看
[root@redis-node2 ~]# redis-cli 
127.0.0.1:6379> get name
"ren"
####在slave2查看
[root@redis-node3 utils]# redis-cli 
127.0.0.1:6379> get name
"ren"

同步的过程

slave节点发送请求到master节点

slave节点通过master节点的认证开始进行同步

master节点会开启bgsave进程发送内存到rbd到slave节点,在此过程中是异步操作,也就是master节点仍然可以进行写入操作

slave节点收到rbd后首先清空自己的所有数据

slave节点加载rdb并进行数据恢复

在master和slave同步过程中master还会开启新的bgsave进程把没有同步的数据进行缓存

然后通过自有的replactionfeeslave函数把未通过的内存快照发送到slave的数据一条一条写入到slave中

redis哨兵

SDOWN

有主观宕机也有客观宕机。当哨兵群中多数哨兵(sentinel)进程在对master主服务器做出主观宕机(SDOWN)的判读,并且通过SENTINEL is-master-down-by-addr命令互相交流之后,得出master server下线判断,这就是客观宕机 ------ODOWN

通过一定的vote算法,从剩下的slave服务器的节点中,选一台提升为master,然后自动修改相关配置文件,并开启故障转移

sentinel机制可以解决master和slave之间的自动切换问题,当单个master的性能瓶颈问题无法出解决,类似于mysql中的MHA功能

Redis Sentinel中的Sentinel节点个数应该为大于等于3且最好为奇数

每10s每个sentinel对master和slave执行info

发现slave节点

确认主从关系

每2s每个sentinel通过master节点的channel交换信息(pub/sub)

通过sentinel_:hello频道交互

交互对节点的看法和自身信息

每1s每个sentinel对其他sentinel和redis执行ping

实验过程

关闭 protected-mode no

[root@redis-node1 ~]# cd redis-7.4.0/
[root@redis-node1 redis-7.4.0]# ls
00-RELEASENOTES     INSTALL      redis.conf              runtest-sentinel  TLS.md
BUGS                LICENSE.txt  REDISCONTRIBUTIONS.txt  SECURITY.md       utils
CODE_OF_CONDUCT.md  Makefile     runtest                 sentinel.conf
CONTRIBUTING.md     MANIFESTO    runtest-cluster         src
deps                README.md    runtest-moduleapi       tests
 
[root@redis-node1 redis-7.4.0]# vim sentinel.conf 
protected-mode no
sentinel monitor mymaster 172.25.250.10 6379 2
sentinel down-after-milliseconds mymaster 10000
 
[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf root@172.25.250.20:/etc/redis/sentinel.conf
root@172.25.250.20's password: 
sentinel.conf                                             100%   14KB  12.3MB/s   00:00    
[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf root@172.25.250.30:/etc/redis/sentinel.conf
root@172.25.250.30's password: 
sentinel.conf                                             100%   14KB  15.3MB/s   00:00    
[root@redis-node1 redis-7.4.0]# cd /etc/redis/
[root@redis-node1 redis]# ls
6379.conf  sentinel.conf
 
#########因为当master坏掉又修复好了之后,他会成为slave,然后他会还原数据或者配置文件,所以需要备份
####所有主机都操作
[root@redis-node1 redis]# cp sentinel.conf sentinel.conf.bak

再启动

####172.25.250.10(master)开启
[root@redis-node1 redis-7.4.0]# redis-sentinel /etc/redis/sentinel.conf
8281:X 26 Aug 2024 13:52:15.949 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
8281:X 26 Aug 2024 13:52:15.949 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8281:X 26 Aug 2024 13:52:15.949 * Redis version=7.4.0, bits=64, commit=00000000, modified=0, pid=8281, just started
8281:X 26 Aug 2024 13:52:15.949 * Configuration loaded
8281:X 26 Aug 2024 13:52:15.949 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8281:X 26 Aug 2024 13:52:15.949 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis Community Edition      
  .-`` .-```.  ```\/    _.,_ ''-._     7.4.0 (00000000/0) 64 bit
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379
 |    `-._   `._    /     _.-'    |     PID: 8281
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               
 
8281:X 26 Aug 2024 13:52:15.951 * Sentinel new configuration saved on disk
8281:X 26 Aug 2024 13:52:15.951 * Sentinel ID is 1823ba60190a86e7653368c718b5b733b70ead80
8281:X 26 Aug 2024 13:52:15.951 # +monitor master mymaster 172.25.250.10 6379 quorum 2
8281:X 26 Aug 2024 13:52:15.952 * +slave slave 172.25.250.20:6379 172.25.250.20 6379 @ mymaster 172.25.250.10 6379
8281:X 26 Aug 2024 13:52:15.954 * Sentinel new configuration saved on disk
8281:X 26 Aug 2024 13:52:15.954 * +slave slave 172.25.250.30:6379 172.25.250.30 6379 @ mymaster 172.25.250.10 6379
8281:X 26 Aug 2024 13:52:15.955 * Sentinel new configuration saved on disk
8281:X 26 Aug 2024 13:52:30.651 * +sentinel sentinel a23f818e9bd026df515af54110dc6d393338eb60 172.25.250.20 26379 @ mymaster 172.25.250.10 6379
8281:X 26 Aug 2024 13:52:30.653 * Sentinel new configuration saved on disk
####其他一样操作
[root@redis-node1 ~]# redis-cli 
127.0.0.1:6379> SHUTDOWN
(1.23s)
 
###然后我们关闭master模拟故障
 
####去slave上查看,可以看到node2是master,slave只有172.25.250.30(node3),因为旧master关闭了,
[root@redis-node2 redis]# redis-cli 
127.0.0.1:6379> info replication
# Replication
role:master            #####现在node2是master
connected_slaves:1
slave0:ip=172.25.250.30,port=6379,state=online,offset=23791,lag=0
master_failover_state:no-failover
master_replid:3737c2502945b0e05f08a2eedfa23a4405f670a3
master_replid2:b4d9ee5140c8c2045ca62f042f68f2ec27054c5e
master_repl_offset:23791
second_repl_offset:11700
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:23791
 
####然后我们开启172.25.250.10并查看他的状态,发现他已经变为slave
[root@redis-node1 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@redis-node1 ~]# redis-cli 
127.0.0.1:6379> info replication
# Replication
role:slave       ##############变为slave
master_host:172.25.250.20       ####指向172.25.250.20
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_read_repl_offset:37871
slave_repl_offset:37871
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:3737c2502945b0e05f08a2eedfa23a4405f670a3
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:37871
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:34578
repl_backlog_histlen:3294
 
####172.25.250,30查看
[root@redis-node3 redis]# redis-cli 
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:172.25.250.20        #######指向20
master_port:6379
master_link_status:up
master_last_io_seconds_ago:9
master_sync_in_progress:0
slave_read_repl_offset:125665
slave_repl_offset:125665
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:3737c2502945b0e05f08a2eedfa23a4405f670a3
master_replid2:b4d9ee5140c8c2045ca62f042f68f2ec27054c5e
master_repl_offset:125665
second_repl_offset:11700
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:224
repl_backlog_histlen:125442
 
 
####我们再去172.25.250.20(新master)查看,会发现172.25.250.10已经上线,并且是slave状态
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=172.25.250.30,port=6379,state=online,offset=33731,lag=0
slave1:ip=172.25.250.10,port=6379,state=wait_bgsave,offset=0,lag=0
master_failover_state:no-failover
master_replid:3737c2502945b0e05f08a2eedfa23a4405f670a3
master_replid2:b4d9ee5140c8c2045ca62f042f68f2ec27054c5e
master_repl_offset:33872
second_repl_offset:11700
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:33872
 
 
###注意
/etc/redis/sentinel.conf 文件在用哨兵程序调用后会更改其配置文件,如果需要重新做需要删掉文件重新编辑

查看监控的状态

在master中去设定

[root@redis-node2 redis]# redis-cli 
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=172.25.250.30,port=6379,state=online,offset=127149,lag=0
slave1:ip=172.25.250.10,port=6379,state=online,offset=127149,lag=0
master_failover_state:no-failover
master_replid:3737c2502945b0e05f08a2eedfa23a4405f670a3
master_replid2:b4d9ee5140c8c2045ca62f042f68f2ec27054c5e
master_repl_offset:127149
second_repl_offset:11700
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:127149
 
#########这时0个slave也可以写入
127.0.0.1:6379> CONFIG GET min-slaves-to-write
1) "min-slaves-to-write"
2) "0"
 
########设置必须最少2个master才能写入
127.0.0.1:6379> CONFIG set min-slaves-to-write 2
OK
127.0.0.1:6379> CONFIG GET min-slaves-to-write
1) "min-slaves-to-write"
2) "2"
127.0.0.1:6379> 
 
#####以上是临时设置
 
#########如果要永久设置
min-slaves-to-write 2 

redis cluster

工作的原理:

redis cluster特点

所有redis节点使用(ping机制)互联

集群中某个节点是否失效,由整个集群值超过半数的节点监测都失效。才算真正的失效

客户端不需要proxy即可直接连接redis,应用程序中需要配置有全部的redis服务器ip

redis cluster把所有的redis node 平均映射到 0-16383个槽位(slot)上,读写需要到指定的redis node上进行操作,因此有多少个redis node相当于redis 并发扩展了多少倍,每个redis node 承担16384/N个槽位

Redis cluster预先分配16384个(slot)槽位,当需要在redis集群中写入一个key -value的时候,会使用CRC16(key) mod 16384之后的值,决定将key写入值哪一个槽位从而决定写入哪一个Redis节点上,从而有效解决单机瓶颈。

部署 redus cluster

删除 10 20 和和主机上安装 redis

#####删掉之前源码编译的redis
[root@redis-node1 redis]# cd /root/redis-7.4.0/
[root@redis-node1 redis-7.4.0]# ls
00-RELEASENOTES     INSTALL      redis.conf              runtest-sentinel  TLS.md
BUGS                LICENSE.txt  REDISCONTRIBUTIONS.txt  SECURITY.md       utils
CODE_OF_CONDUCT.md  Makefile     runtest                 sentinel.conf
CONTRIBUTING.md     MANIFESTO    runtest-cluster         src
deps                README.md    runtest-moduleapi       tests
 
 
 
[root@redis-node1 redis-7.4.0]# ps aux | grep redis
root       34042  0.2  0.6 354428 11884 ?        Ssl  14:52   0:00 /usr/local/bin/redis-server *:6379
root       34149  0.0  0.1 221664  2176 pts/0    S+   14:57   0:00 grep --color=auto redis
[root@redis-node1 redis-7.4.0]# killall -9 redis-server 
[root@redis-node1 redis-7.4.0]# ps aux | grep redis
root       34155  0.0  0.1 221664  2176 pts/0    S+   14:57   0:00 grep --color=auto redis
 
[root@redis-node1 redis-7.4.0]# /etc/init.d/redis_6379 stop
 
[root@redis-node1 redis-7.4.0]# ps aux | grep redis
root       34259  0.0  0.1 221664  2176 pts/0    S+   14:58   0:00 grep --color=auto redis
[root@redis-node1 redis-7.4.0]# ps aux | grep redis
root       34262  0.0  0.1 221664  2176 pts/0    S+   14:59   0:00 grep --color=auto redis
 
[root@redis-node1 redis-7.4.0]# make uninstall 
 
cd src && make uninstall
make[1]: Entering directory '/root/redis-7.4.0/src'
rm -f /usr/local/bin/{redis-server,redis-benchmark,redis-cli,redis-check-rdb,redis-check-aof,redis-sentinel}
make[1]: Leaving directory '/root/redis-7.4.0/src'

在所有的主机上使用 rpm 的包安装 redis

[root@redis-node1 redis-7.4.0]# yum install redis -y
 
###编辑redis配置文件
[root@redis-node1 redis-7.4.0]# vim /etc/redis/redis.conf 
masterauth "123456" 		#集群主从认证
requirepass "123456" 		#redis登陆密码 redis-cli 命令连接redis后要用“auth 密码”进行认证
cluster-enabled yes 		#开启cluster集群功能
cluster-config-file nodes-6379.conf 	#指定集群配置文件
cluster-node-timeout 15000 				#节点加入集群的超时时间单位是ms
 
 
¥#####启动redis
[root@redis-node1 redis-7.4.0]# systemctl enable --now redis
 
[root@redis-node1 redis-7.4.0]# vim /etc/redis/redis.conf 
[root@redis-node1 redis-7.4.0]# systemctl restart redis
[root@redis-node1 redis-7.4.0]# netstat -antlupe | grep redis
tcp        0      0 0.0.0.0:16379           0.0.0.0:*               LISTEN      980        44
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      980        44
tcp6       0      0 :::16379                :::*                    LISTEN      980        44
tcp6       0      0 :::6379                 :::*                    LISTEN      980        44
[root@redis-node1 redis-7.4.0]# bash
 
 
[root@redis-node1 redis-7.4.0]# redis-cli 
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> set name ren
(error) CLUSTERDOWN Hash slot not served
127.0.0.1:6379> quit
 
###在10主机上拷贝redis中的/etc/redis/redis.conf到其他所有主机
[root@redis-node1 redis-7.4.0]# for i in 20 30 110 120 130; do scp/etc/redis/redis.conf root@172.25.250.$i:/etc/redis/redis.conf; done
 
 
[root@redis-node1 ~]# systemctl restart redis
[root@redis-node1 ~]# netstat -antlup | grep redis
tcp        0      0 0.0.0.0:16379           0.0.0.0:*               LISTEN      9216/redis-server * 
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      9216/redis-server * 
tcp6       0      0 :::16379                :::*                    LISTEN      9216/redis-server * 
tcp6       0      0 :::6379                 :::*                    LISTEN      9216/redis-server * 
[root@redis-node1 ~]# netstat -antlup | grep 6379
tcp        0      0 0.0.0.0:16379           0.0.0.0:*               LISTEN      9216/redis-server * 
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      9216/redis-server * 
tcp6       0      0 :::16379                :::*                    LISTEN      9216/redis-server * 
tcp6       0      0 :::6379                 :::*                    LISTEN      9216/redis-server * 
 
 
[root@redis-node1 ~]# redis-cli --cluster create -a 123456 \
> 172.25.250.10:6379 172.25.250.20:6379 172.25.250.30:6379 \
> 172.25.250.110:6379 172.25.250.120:6379 172.25.250.130:6379 \
> --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 172.25.250.120:6379 to 172.25.250.10:6379
Adding replica 172.25.250.130:6379 to 172.25.250.20:6379
Adding replica 172.25.250.110:6379 to 172.25.250.30:6379
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[0-5460] (5461 slots) master
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[5461-10922] (5462 slots) master
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[10923-16383] (5461 slots) master
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
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 172.25.250.10:6379)
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   slots: (0 slots) slave
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   slots: (0 slots) slave
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
 
####查看状态
[root@redis-node1 ~]# redis-cli -a 123456 --cluster check 172.25.250.10:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.250.10:6379 (0f336dd0...) -> 0 keys | 5461 slots | 1 slaves.
172.25.250.30:6379 (843ce275...) -> 0 keys | 5461 slots | 1 slaves.
172.25.250.20:6379 (4e79ba7b...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.25.250.10:6379)
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   slots: (0 slots) slave
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   slots: (0 slots) slave
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
 
 
[root@redis-node1 ~]# redis-cli -a 123456 --cluster info 172.25.250.10:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.250.10:6379 (0f336dd0...) -> 0 keys | 5461 slots | 1 slaves.
172.25.250.30:6379 (843ce275...) -> 0 keys | 5461 slots | 1 slaves.
172.25.250.20:6379 (4e79ba7b...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.

添加数据

[root@redis-node1 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set name lee
(error) MOVED 5798 172.25.250.20:6379       ###指向172.25.250.20
127.0.0.1:6379> get name
(error) MOVED 5798 172.25.250.20:6379
127.0.0.1:6379> set name ren
(error) MOVED 5798 172.25.250.20:6379
127.0.0.1:6379> quit
 
 
####我们去172.25.250.20看
[root@redis-node2 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> set name lee
OK
127.0.0.1:6379> get name
"lee"

集群扩散 

下载redis

####添加master
[root@redis-node1 ~]# redis-cli -a 123456 --cluster add-node 
172.25.250.40:6379 172.25.250.10:6379
 
###master添加后没有槽位
###分配槽位
[root@redis-node1 ~]#  redis-cli -a 123456 --cluster reshard 
172.25.250.10:6379     ###分配4096个槽位    all:所有主机都分配给他
 
####查看可以看到172.25.250.40有槽位了
[root@redis-node1 ~]# redis-cli -a 123456 --cluster check 172.25.250.10:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.250.10:6379 (0f336dd0...) -> 0 keys | 4096 slots | 1 slaves.
172.25.250.40:6379 (1bffc87a...) -> 1 keys | 4096 slots | 0 slaves.
172.25.250.30:6379 (843ce275...) -> 0 keys | 4096 slots | 1 slaves.
172.25.250.20:6379 (4e79ba7b...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 1 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.25.250.10:6379)
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: 1bffc87a10c9c714ea3c2274bccec7b06d584444 172.25.250.40:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   slots: (0 slots) slave
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   slots: (0 slots) slave
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
 
###添加172.25.250.40的slave,所以cluster-master-id 必须是要172.25.250.40的id
[root@redis-node1 ~]# redis-cli -a 123456 --cluster add-node 172.25.250.140:6379 172.25.250.10:6379 --cluster-slave --cluster-master-id 1bffc87a10c9c714ea3c2274bccec7b06d584444
 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 172.25.250.140:6379 to cluster 172.25.250.10:6379
>>> Performing Cluster Check (using node 172.25.250.10:6379)
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: 1bffc87a10c9c714ea3c2274bccec7b06d584444 172.25.250.40:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   slots: (0 slots) slave
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   slots: (0 slots) slave
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 172.25.250.140:6379 to make it join the cluster.
Waiting for the cluster to join
 
>>> Configure node as replica of 172.25.250.40:6379.
[OK] New node added correctly.
 
 
####查看
[root@redis-node1 ~]# redis-cli -a 123456 --cluster check 172.25.250.10:6379
 
 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.250.10:6379 (0f336dd0...) -> 0 keys | 4096 slots | 1 slaves.
172.25.250.40:6379 (1bffc87a...) -> 1 keys | 4096 slots | 1 slaves.
172.25.250.30:6379 (843ce275...) -> 0 keys | 4096 slots | 1 slaves.
172.25.250.20:6379 (4e79ba7b...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 1 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.25.250.10:6379)
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: 1bffc87a10c9c714ea3c2274bccec7b06d584444 172.25.250.40:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
   1 additional replica(s)
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   slots: (0 slots) slave
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   slots: (0 slots) slave
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 43b3521bc9bd18aba373231680da23013bc8fffe 172.25.250.140:6379
   slots: (0 slots) slave
   replicates 1bffc87a10c9c714ea3c2274bccec7b06d584444
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
 
####可以看到4主4从OK

集群维护 

删除40

[root@redis-node1 ~]# redis-cli -a 123456 --cluster del-node 172.25.250.140:6379 43b3521bc9bd18aba373231680da23013bc8fffe
 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node 43b3521bc9bd18aba373231680da23013bc8fffe from cluster 172.25.250.140:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.
[root@redis-node1 ~]# redis-cli -a 123456 --cluster check 172.25.250.10:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.250.10:6379 (0f336dd0...) -> 0 keys | 4096 slots | 1 slaves.
172.25.250.40:6379 (1bffc87a...) -> 1 keys | 4096 slots | 0 slaves.
172.25.250.30:6379 (843ce275...) -> 0 keys | 4096 slots | 1 slaves.
172.25.250.20:6379 (4e79ba7b...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 1 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.25.250.10:6379)
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: 1bffc87a10c9c714ea3c2274bccec7b06d584444 172.25.250.40:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   slots: (0 slots) slave
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   slots: (0 slots) slave
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
 
 
####清除槽位
###把172.25.250.40的槽位往172.25.250.10上迁移
[root@redis-node1 ~]# redis-cli -a 123456 --cluster reshard 172.25.250.10:6379
 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 172.25.250.10:6379)
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: 1bffc87a10c9c714ea3c2274bccec7b06d584444 172.25.250.40:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   slots: (0 slots) slave
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   slots: (0 slots) slave
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID? 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
  
####这里是172.25.250.40的id
Source node #1: 1bffc87a10c9c714ea3c2274bccec7b06d584444
Source node #2: done
 
###检测
####40上的槽位没有了
[root@redis-node1 ~]# redis-cli -a 123456 --cluster check 172.25.250.10:6379
 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.250.10:6379 (0f336dd0...) -> 1 keys | 8192 slots | 2 slaves.
172.25.250.30:6379 (843ce275...) -> 0 keys | 4096 slots | 1 slaves.
172.25.250.20:6379 (4e79ba7b...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 1 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.25.250.10:6379)
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[0-6826],[10923-12287] (8192 slots) master
   2 additional replica(s)
S: 1bffc87a10c9c714ea3c2274bccec7b06d584444 172.25.250.40:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   slots: (0 slots) slave
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   slots: (0 slots) slave
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
 
####删除40,也是master
[root@redis-node1 ~]# redis-cli -a 123456 --cluster del-node 172.25.250.40:6379 1bffc87a10c9c714ea3c2274bccec7b06d584444
 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node 1bffc87a10c9c714ea3c2274bccec7b06d584444 from cluster 172.25.250.40:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.
 
######检测  40没了
[root@redis-node1 ~]# redis-cli -a 123456 --cluster check 172.25.250.10:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.25.250.10:6379 (0f336dd0...) -> 1 keys | 8192 slots | 1 slaves.
172.25.250.30:6379 (843ce275...) -> 0 keys | 4096 slots | 1 slaves.
172.25.250.20:6379 (4e79ba7b...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 1 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.25.250.10:6379)
M: 0f336dd07f8d0c58e4275d90f1f21bc698636b6b 172.25.250.10:6379
   slots:[0-6826],[10923-12287] (8192 slots) master
   1 additional replica(s)
M: 843ce27571c8aeeb2855a8a219607ba34df1938a 172.25.250.30:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 32d0f40b0643f54edce632825dc5cd1e2c4d721c 172.25.250.110:6379
   slots: (0 slots) slave
   replicates 843ce27571c8aeeb2855a8a219607ba34df1938a
S: 0bc1d271194bbaf7d182a89d4e819281aea79165 172.25.250.130:6379
   slots: (0 slots) slave
   replicates 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412
M: 4e79ba7bf9c1eb8c0b1b31f98200611cb677f412 172.25.250.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: bad0965394102cfceee927593ba470b6f5382162 172.25.250.120:6379
   slots: (0 slots) slave
   replicates 0f336dd07f8d0c58e4275d90f1f21bc698636b6b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

三、总结

NoSQL数据库是一种提供灵活数据模型、可扩展性和高性能的数据存储解决方案,适用于处理大规模、多样化或快速变化的数据。Redis集群作为NoSQL数据库的一种,通过数据分片、高可用性和自动故障转移等机制,提供了一种高效、可靠的数据存储和处理方式。Redis集群的配置和使用虽然复杂,但能够显著提升数据处理能力,适用于需要高速读写和高度可用的应用场景。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值