Nosql数据库redis集群配置详解

news2024/11/15 11:57:56

一、Redis的安装 

环境介绍:

一主双从:10(redis-node1)主,20(redis-node2) 30(redis-node3)从——使用的是红帽9.1系统

源码安装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

[root@redis-node1 redis-7.4.0]# dnf install make gcc initscripts -y——安装编译工具

[root@redis-node1 redis-7.4.0]# make && make install——开始编译

启动Redis

[root@redis-node1 redis-7.4.0]# cd utils/

[root@redis-node1 utils]# vim install_server.sh ——将系统使用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——编辑此文件后成功启动

Welcome to the redis service installer

This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]——端口号

Selecting default: 6379

Please select the redis config file name [/etc/redis/6379.conf]——配置文件

Selected default - /etc/redis/6379.conf

Please select the redis log file name [/var/log/redis_6379.log]——日志文件

Selected default - /var/log/redis_6379.log

Please select the data directory for this instance [/var/lib/redis/6379]——数据文件

Selected default - /var/lib/redis/6379

Please select the redis executable path [/usr/local/bin/redis-server]——命令文件

Selected config:

Port           : 6379

Config file    : /etc/redis/6379.conf

Log file       : /var/log/redis_6379.log

Data dir       : /var/lib/redis/6379

Executable     : /usr/local/bin/redis-server

Cli Executable : /usr/local/bin/redis-cli

Is this ok? Then press ENTER to go on or Ctrl-C to abort.

Copied /tmp/6379.conf => /etc/init.d/redis_6379

Installing service...

Successfully added to chkconfig!

Successfully added to runlevels 345!

Starting Redis server...

Installation successful!

配置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          8          1587      49806/redis-server

tcp6       0      0 :::6379                 :::*                    LISTEN      0          8          1588      49806/redis-server

查看信息

[root@redis-node1 utils]# redis-cli

127.0.0.1:6379>info

[root@redis-node1 utils]# cd /usr/local/bin/

将编译好的软件文件和命令文件同步到20和30上

[root@redis-node1 bin]# rsync -al * root@172.25.254.20:/usr/local/bin

[root@redis-node1 bin]# rsync -al * root@172.25.254.30:/usr/local/bin

[root@redis-node1 bin]# cd /root

[root@redis-node1 ~]# scp -r redis-7.4.0 root@172.25.254.20:/root

[root@redis-node1 ~]# scp -r redis-7.4.0 root@172.25.254.30:/root

重复安装动作在20和30主机上

[root@redis-node2&3 ~]# cd redis-7.4.0/

[root@redis-node2&3 redis-7.4.0]# ls

00-RELEASENOTES     deps         MANIFESTO               runtest            SECURITY.md    TLS.md

BUGS                INSTALL      README.md               runtest-cluster    sentinel.conf  utils

CODE_OF_CONDUCT.md  LICENSE.txt  redis.conf              runtest-moduleapi  src

CONTRIBUTING.md     Makefile     REDISCONTRIBUTIONS.txt  runtest-sentinel   tests

[root@redis-node2&3 redis-7.4.0]# cd utils/

[root@redis-node2&3 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&3 utils]# dnf install initscripts -y

[root@redis-node2&3 utils]# ./install_server.sh

[root@redis-node2&3 ~]# vim /etc/redis/6379.conf

bind * -::*

protected-mode no——关闭保护模式

 二、Redis的主从复制

2.1主从同步的原理

slave节点发送同步请求到master节点

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

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

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

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

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

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

2.2配置主从同步

Redis主从复制

两台slave上配置

[root@redis-node2&3 utils]# vim /etc/redis/6379.conf

replicaof 172.25.254.10 6379——添加主IP

[root@redis-node2&3 ~]# /etc/init.d/redis_6379 restart

Stopping ...

Redis stopped

Starting Redis server...

[root@redis-node1 utils]# redis-cli——可以在node1上查看到主从信息

127.0.0.1:6379> info replication

# Replication

role:master

connected_slaves:2

slave0:ip=172.25.254.20,port=6379,state=online,offset=42,lag=0

slave1:ip=172.25.254.30,port=6379,state=wait_bgsave,offset=0,lag=0

master_failover_state:no-failover

master_replid:529a24e2de5ffc361cabcd76592ef3b021bd6d80

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:42

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:42

测试:在node1上添加数据可以在20和30上看到

[root@redis-node1 utils]# redis-cli

127.0.0.1:6379> set name jcl

OK

[root@redis-node2 ~]# redis-cli

127.0.0.1:6379> get name

"jcl"

[root@redis-node3 utils]# redis-cli

127.0.0.1:6379> get name

"jcl"

三、Redis的哨兵(高可用)

3.1Redis哨兵原理

Sentinel 进程是用于监控redis集群中Master主服务器工作的状态,在Master主服务器发生故障的时候, 可以实现Master和Slave服务器的切换,保证系统的高可用,生产环境也建议使用Redis的2.8版本的以后版本

每个哨兵(Sentinel)进程会向其它哨兵(Sentinel)、Master、Slave定时发送消息,以确认对方是否”活” 着,如果发现对方在指定配置时间(此项可配置)内未得到回应,则暂时认为对方已离线,也就是所谓的” 主观认为宕机” (主观:是每个成员都具有的独自的而且可能相同也可能不同的意识),

当“哨兵群”中的多数Sentinel进程在对Master主服务器做出SDOWN 的 判断,并且通过 SENTINEL is-master-down-by-addr 命令互相交流之后,得出的Master Server下线判 断,这种方式就是“客观宕机”(客观:是不依赖于某种意识而已经实际存在的一切事物)

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

Sentinel 机制可以解决master和slave角色的自动切换问题,但单个 Master 的性能瓶颈问题无法解决,类 似于MySQL中的MHA功能

sentinel中的三个定时任务:

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

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

      每1秒每个sentinel对其他sentinel和redis执行pi

3.2哨兵实验过程

因为我们哨兵实现会改变配置文件,所以我们要提前将配置文件备份

编辑和备份配置文件

[root@redis-node1 ~]# cd redis-7.4.0/

[root@redis-node1 redis-7.4.0]# cp sentinel.conf  /etc/redis/

[root@redis-node1 redis-7.4.0]# vim /etc/redis/sentinel.conf

92 sentinel monitor mymaster 172.25.254.10 6379 2——创建sentinel监控 masterIP 2表示必须得到两票

133 sentinel down-after-milliseconds mymaster 10000——master中断时长,表示10s连不上视为下线

将配置文件同步到20和30主机上

[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf root@172.25.254.20:/etc/redis/sentinel.conf

[root@redis-node1 redis-7.4.0]# scp /etc/redis/sentinel.conf root@172.25.254.30:/etc/redis/sentinel.conf

备份配置文件

[root@redis-node1&2&3 redis-7.4.0]# cp /etc/redis/sentinel.conf /etc/redis/sentinel.conf.bak

在20和30上启动哨兵服务

[root@redis-node2 redis]# redis-sentinel sentinel.conf

60271:X 25 Aug 2024 23:02:40.539 # 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.

60271:X 25 Aug 2024 23:02:40.539 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

60271:X 25 Aug 2024 23:02:40.539 * Redis version=7.4.0, bits=64, commit=00000000, modified=0, pid=60271, just started

60271:X 25 Aug 2024 23:02:40.539 * Configuration loaded

60271:X 25 Aug 2024 23:02:40.540 * Increased maximum number of open files to 10032 (it was originally set to 1024).

60271:X 25 Aug 2024 23:02:40.540 * monotonic clock: POSIX clock_gettime

                _._

           _.-``__ ''-._

      _.-``    `.  `_.  ''-._           Redis Community Edition

  .-`` .-```.  ```\/    _.,_ ''-._     7.4.0 (00000000/0) 64 bit

 (    '      ,       .-`  | `,    )     Running in sentinel mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379

 |    `-._   `._    /     _.-'    |     PID: 60271

  `-._    `-._  `-./  _.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |           Redis - The Real-time Data Platform

  `-._    `-._`-.__.-'_.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |

  `-._    `-._`-.__.-'_.-'    _.-'

      `-._    `-.__.-'    _.-'

          `-._        _.-'

              `-.__.-'

60271:X 25 Aug 2024 23:02:40.542 * Sentinel new configuration saved on disk

60271:X 25 Aug 2024 23:02:40.542 * Sentinel ID is 298458b72b6f29fc7cc2a7e074c99572871f66a3

60271:X 25 Aug 2024 23:02:40.542 # +monitor master mymaster 172.25.254.10 6379 quorum 2

60271:X 25 Aug 2024 23:02:40.544 * +slave slave 172.25.254.20:6379 172.25.254.20 6379 @ mymaster 172.25.254.10 6379

60271:X 25 Aug 2024 23:02:40.545 * Sentinel new configuration saved on disk

60271:X 25 Aug 2024 23:02:40.545 * +slave slave 172.25.254.30:6379 172.25.254.30 6379 @ mymaster 172.25.254.10 6379

60271:X 25 Aug 2024 23:02:40.546 * Sentinel new configuration saved on disk

测试:

关闭master10的redis模拟master下线

[root@redis-node1 redis]# redis-cli

127.0.0.1:6379> SHUTDOWN

not connected>

可以看到20和30上分别会显示

60271:X 25 Aug 2024 23:04:07.999 # +sdown master mymaster 172.25.254.10 6379

36897:X 25 Aug 2024 23:15:46.303 # -odown master mymaster 172.25.254.10 6379 ——表示两个识别到master挂掉的状态时自动成为客观事实

61855:X 25 Aug 2024 23:18:36.541 * +convert-to-slave slave 172.25.254.10:6379 172.25.254.10 6379 @ mymaster 172.25.254.20 6379 ——表示10挂掉后20成为新master10恢复后成为20的slave

这时候再开一个20的新窗口,查看主从信息发现20只有30这一个slave

[root@redis-node2 redis]# redis-cli

127.0.0.1:6379> info replication

# Replication

role:master

connected_slaves:1

slave0:ip=172.25.254.30,port=6379,state=online,offset=64205,lag=0

master_failover_state:no-failover

master_replid:565c461a7c6b2d21d16bf2ffe97485d0e9512131

master_replid2:0d65657f58823cef4fbd11aed042e838fd67013f

master_repl_offset:64219

second_repl_offset:45967

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:64219

恢复10

[root@redis-node1 redis]# /etc/init.d/redis_6379 start

Starting Redis server...

20和30上会显示以下信息,表示10上线成为20的slave

61855:X 25 Aug 2024 23:27:54.804 # -sdown slave 172.25.254.10:6379 172.25.254.10 6379 @ mymaster 172.25.254.20 6379

再看20的主从信息

127.0.0.1:6379> info replication

# Replication

role:master

connected_slaves:2

slave0:ip=172.25.254.30,port=6379,state=online,offset=72349,lag=1

slave1:ip=172.25.254.10,port=6379,state=online,offset=72349,lag=0

master_failover_state:no-failover

master_replid:565c461a7c6b2d21d16bf2ffe97485d0e9512131

master_replid2:0d65657f58823cef4fbd11aed042e838fd67013f

master_repl_offset:72349

second_repl_offset:45967

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:72349

如果想要sentinal哨兵在后台运行不在前台显示可以在sentinal配置文件中daemonize yes

[root@redis-node1 redis]# vim sentinel.conf

[root@redis-node1 redis]# redis-sentinel sentinel.conf

66626:X 25 Aug 2024 23:36:06.750 # 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 vm.max_map_count growing steadily when vm.overcommit_memory is 2 · Issue #1328 · jemalloc/jemalloc · GitHub. 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.

优化防止数据丢失

由于master出故障时数据可能还会一直写入导致数据丢失情况出现

在master上临时更改,表示当master有两个slave时才能写入数据

127.0.0.1:6379> CONFIG GET min-slaves-to-write

1) "min-slaves-to-write"

2) "0"

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"

永久更改需要编辑配置文件

[root@redis-node2 redis]# vim /etc/redis/6379.conf

min-slaves-to-write 2  添加参数

四、Redis cluster(无中心化设计)

4.1Redis Cluster工作原理

Redis Cluster特点:

1. 所有Redis节点使用(PING机制)互联
2. 集群中某个节点的是否失效,是由整个集群中超过半数的节点监测都失效,才能算真正的失效
3. 客户端不需要proxy即可直接连接redis,应用程序中需要配置有全部的redis服务器IP
4. redis cluster把所有的redis node 平均映射到 0-16383个槽位(slot)上,读写需要到指定的redis node上进行操作,因此有多少个redis node相当于redis 并发扩展了多少倍,每个redis node 承担 16384/N个槽位
5. Redis cluster预先分配16384个(slot)槽位,当需要在redis集群中写入一个key -value的时候,会使 用CRC16(key) mod 16384之后的值,决定将key写入值哪一个槽位从而决定写入哪一个Redis节点 上,从而有效解决单机瓶颈。

Redis cluster 主从架构:

Redis cluster的架构虽然解决了并发的问题,但是又引入了一个新的问题,每个Redis master的高可用 如何解决? 那就是对每个master 节点都实现主从复制,从而实现 redis 高可用性

Redis Cluster部署架构说明:

4.2创建redis cluster的前提

1.每个redis node节点采用相同的硬件配置、相同的密码、相同的redis版本。

2.每个节点必须开启的参数

cluster-enabled yes        #必须开启集群状态,开启后redis进程会有cluster显示

cluster-config-file nodes-6380.conf        #此文件有redis cluster集群自动创建和维护,不需要任何手 动操作

3.所有redis服务器必须没有任何数据
4.先启动为单机redis且没有任何key value

4.3rpm包安装redis及集群配置 

三台10 20 30卸载源码安装的redis重新rpm安装

[root@redis-node3 redis]# ps aux | grep redis——查看redis进程

root       35174  0.4  0.6 348796 12196 ?        Ssl  22:43   0:17 /usr/local/bin/redis-server *:6379

root       38830  0.0  0.1 221664  2232 pts/2    S+   23:45   0:00 grep --color=auto redis

[root@redis-node3 redis]# killall -9 redis-server——将redis进程全部结束掉

[root@redis-node3 redis]# dnf install gcc -y——安装工具方便卸载编译安装的redis

[root@redis-node3 redis-7.4.0]# make uninstall——卸载

[root@redis-node3 redis-7.4.0]# yum install redis -y——yum源安装

[root@redis-node3 redis-7.4.0]# vim /etc/redis/redis.conf——编辑配置文件

486  masterauth "123456"——集群主从认证

903  requirepass "123456"——redis登录密码 redis-cli -a 命令连接数据库

1387  cluster-enabled yes——开启集群功能

1395  cluster-config-file nodes-6379.conf——指定集群配置文件

75 bind * -::*——设置为所有端口

[root@redis-node1 ~]# systemctl enable --now redis——启动redis

Created symlink /etc/systemd/system/multi-user                                                   .target.wants/redis.service → /usr/lib/systemd                                                   /system/redis.service.

[root@redis-node1 ~]# which redis-cli——可以看到命令文件

/usr/bin/redis-cli

在新克隆出来的三台主机上安装redis

[root@redis-node110 &120&130~]# yum install redis -y

在node1上验证一下配置

[root@redis-node1 ~]# redis-cli

127.0.0.1:6379> keys *

(error) NOAUTH Authentication required.

127.0.0.1:6379> auth 123456

OK

将配置文件拷贝到其他5台主机上

[root@redis-node1 ~]# for i in 20 30 110 120 130

> do

> scp /etc/redis/redis.conf root@172.25.254.$i:/etc/redis/redis.conf

> done

创建集群

[root@redis-node1 ~]# redis-cli --cluster create -a 123456 \

> 172.25.254.10:6379 172.25.254.20:6379 172.25.254.30:6379 \

> 172.25.254.110:6379 172.25.254.120:6379 172.25.254.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.254.120:6379 to 172.25.254.10:6379

Adding replica 172.25.254.130:6379 to 172.25.254.20:6379

Adding replica 172.25.254.110:6379 to 172.25.254.30:6379

M: 94334ee417e6536aaae592a95dfce014e60cf95f 172.25.254.10:6379

   slots:[0-5460] (5461 slots) master

M: c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a 172.25.254.20:6379

   slots:[5461-10922] (5462 slots) master

M: 157195f57cd549409676209e18b4881146aedf3e 172.25.254.30:6379

   slots:[10923-16383] (5461 slots) master

S: b33f211967dfea61399f275dc0c632cf28d18cc6 172.25.254.110:6379

   replicates 157195f57cd549409676209e18b4881146aedf3e

S: db431728d7b1658ed50cbece7bb91287b80952ad 172.25.254.120:6379

   replicates 94334ee417e6536aaae592a95dfce014e60cf95f

S: 3ad4a43dd7e33933862f28e7a78bacad02d8d50c 172.25.254.130:6379

   replicates c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a

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.254.10:6379)

M: 94334ee417e6536aaae592a95dfce014e60cf95f 172.25.254.10:6379

   slots:[0-5460] (5461 slots) master

   1 additional replica(s)

M: 157195f57cd549409676209e18b4881146aedf3e 172.25.254.30:6379

   slots:[10923-16383] (5461 slots) master

   1 additional replica(s)

M: c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a 172.25.254.20:6379

   slots:[5461-10922] (5462 slots) master

   1 additional replica(s)

S: 3ad4a43dd7e33933862f28e7a78bacad02d8d50c 172.25.254.130:6379

   slots: (0 slots) slave

   replicates c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a

S: b33f211967dfea61399f275dc0c632cf28d18cc6 172.25.254.110:6379

   slots: (0 slots) slave

   replicates 157195f57cd549409676209e18b4881146aedf3e

S: db431728d7b1658ed50cbece7bb91287b80952ad 172.25.254.120:6379

   slots: (0 slots) slave

   replicates 94334ee417e6536aaae592a95dfce014e60cf95f

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

查看集群信息

[root@redis-node2 ~]# redis-cli -a 123456 --cluster check 172.25.254.20:6379

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

172.25.254.20:6379 (c362d17f...) -> 1 keys | 5462 slots | 1 slaves.

172.25.254.10:6379 (94334ee4...) -> 0 keys | 5461 slots | 1 slaves.

172.25.254.30:6379 (157195f5...) -> 0 keys | 5461 slots | 1 slaves.

[OK] 1 keys in 3 masters.

0.00 keys per slot on average.

>>> Performing Cluster Check (using node 172.25.254.20:6379)

M: c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a 172.25.254.20:6379

   slots:[5461-10922] (5462 slots) master

   1 additional replica(s)

S: b33f211967dfea61399f275dc0c632cf28d18cc6 172.25.254.110:6379

   slots: (0 slots) slave

   replicates 157195f57cd549409676209e18b4881146aedf3e

S: db431728d7b1658ed50cbece7bb91287b80952ad 172.25.254.120:6379

   slots: (0 slots) slave

   replicates 94334ee417e6536aaae592a95dfce014e60cf95f

S: 3ad4a43dd7e33933862f28e7a78bacad02d8d50c 172.25.254.130:6379

   slots: (0 slots) slave

   replicates c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a

M: 94334ee417e6536aaae592a95dfce014e60cf95f 172.25.254.10:6379

   slots:[0-5460] (5461 slots) master

   1 additional replica(s)

M: 157195f57cd549409676209e18b4881146aedf3e 172.25.254.30:6379

   slots:[10923-16383] (5461 slots) master

   1 additional replica(s)

[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

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 jcl

(error) MOVED 5798 172.25.254.20:6379——可以看到它指引你去20master上写入数据

127.0.0.1:6379> exit

[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> set name jcl

OK——20上成功写入

注:

如果redis-cli不能用该bash配置添加命令文件

[root@redis-node1 ~]# vim ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/bin

[root@redis-node2 ~]# source ~/.bash_profile

4.2集群扩容

安装redis软件

[root@redis-node40&140 ~]# dnf install redis -y

[root@redis-node40 &140~]# systemctl start redis

查看集群

[root@redis-node2 ~]# redis-cli -a 123456 --cluster check 172.25.254.20:6379

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

172.25.254.20:6379 (c362d17f...) -> 1 keys | 5462 slots | 1 slaves.

172.25.254.10:6379 (94334ee4...) -> 0 keys | 5461 slots | 1 slaves.

172.25.254.30:6379 (157195f5...) -> 0 keys | 5461 slots | 1 slaves.

[OK] 1 keys in 3 masters.

0.00 keys per slot on average.

>>> Performing Cluster Check (using node 172.25.254.20:6379)

M: c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a 172.25.254.20:6379

   slots:[5461-10922] (5462 slots) master

   1 additional replica(s)

S: b33f211967dfea61399f275dc0c632cf28d18cc6 172.25.254.110:6379

   slots: (0 slots) slave

   replicates 157195f57cd549409676209e18b4881146aedf3e

S: db431728d7b1658ed50cbece7bb91287b80952ad 172.25.254.120:6379

   slots: (0 slots) slave

   replicates 94334ee417e6536aaae592a95dfce014e60cf95f

S: 3ad4a43dd7e33933862f28e7a78bacad02d8d50c 172.25.254.130:6379

   slots: (0 slots) slave

   replicates c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a

M: 94334ee417e6536aaae592a95dfce014e60cf95f 172.25.254.10:6379

   slots:[0-5460] (5461 slots) master

   1 additional replica(s)

M: 157195f57cd549409676209e18b4881146aedf3e 172.25.254.30:6379

   slots:[10923-16383] (5461 slots) master

   1 additional replica(s)

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

添加集群

[root@redis-node2 ~]# redis-cli -a 123456 --cluster add-node 172.25.254.40:6379 172.25.254.20:6379

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

>>> Adding node 172.25.254.40:6379 to cluster 172.25.254.20:6379

>>> Performing Cluster Check (using node 172.25.254.20:6379)

M: c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a 172.25.254.20:6379

   slots:[5461-10922] (5462 slots) master

   1 additional replica(s)

S: b33f211967dfea61399f275dc0c632cf28d18cc6 172.25.254.110:6379

   slots: (0 slots) slave

   replicates 157195f57cd549409676209e18b4881146aedf3e

S: db431728d7b1658ed50cbece7bb91287b80952ad 172.25.254.120:6379

   slots: (0 slots) slave

   replicates 94334ee417e6536aaae592a95dfce014e60cf95f

S: 3ad4a43dd7e33933862f28e7a78bacad02d8d50c 172.25.254.130:6379

   slots: (0 slots) slave

   replicates c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a

M: 94334ee417e6536aaae592a95dfce014e60cf95f 172.25.254.10:6379

   slots:[0-5460] (5461 slots) master

   1 additional replica(s)

M: 157195f57cd549409676209e18b4881146aedf3e 172.25.254.30:6379

   slots:[10923-16383] (5461 slots) master

   1 additional replica(s)

[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.254.40:6379 to make it join the cluster.

[OK] New node added correctly.

给master40分配槽位

[root@redis-node2 ~]# redis-cli -a 123456 --cluster reshard 172.25.254.40: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.254.40:6379)

M: 48f2f7aaf79ca9a0076d3f2e77722bf7d1bc1936 172.25.254.40:6379

   slots: (0 slots) master

M: 94334ee417e6536aaae592a95dfce014e60cf95f 172.25.254.10:6379

   slots:[0-5460] (5461 slots) master

   1 additional replica(s)

M: c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a 172.25.254.20:6379

   slots:[5461-10922] (5462 slots) master

   1 additional replica(s)

S: b33f211967dfea61399f275dc0c632cf28d18cc6 172.25.254.110:6379

   slots: (0 slots) slave

   replicates 157195f57cd549409676209e18b4881146aedf3e

S: db431728d7b1658ed50cbece7bb91287b80952ad 172.25.254.120:6379

   slots: (0 slots) slave

   replicates 94334ee417e6536aaae592a95dfce014e60cf95f

M: 157195f57cd549409676209e18b4881146aedf3e 172.25.254.30:6379

   slots:[10923-16383] (5461 slots) master

   1 additional replica(s)

S: 3ad4a43dd7e33933862f28e7a78bacad02d8d50c 172.25.254.130:6379

   slots: (0 slots) slave

   replicates c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a

[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? 48f2f7aaf79ca9a0076d3f2e77722bf7d1bc1936 ——40ID

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.

Source node #1: all

给40添加slave

[root@redis-node2 ~]# redis-cli -a 123456 --cluster add-node 172.25.254.140:6379 172.25.254.20:6379 --cluster-slave --cluster-master-id 48f2f7aaf79ca9a0076d3f2e77722bf7d1bc1936——这里的ID是40的

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

>>> Adding node 172.25.254.140:6379 to cluster 172.25.254.20:6379

>>> Performing Cluster Check (using node 172.25.254.20:6379)

M: c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a 172.25.254.20:6379

   slots:[6827-10922] (4096 slots) master

   1 additional replica(s)

S: b33f211967dfea61399f275dc0c632cf28d18cc6 172.25.254.110:6379

   slots: (0 slots) slave

   replicates 157195f57cd549409676209e18b4881146aedf3e

M: 48f2f7aaf79ca9a0076d3f2e77722bf7d1bc1936 172.25.254.40:6379

   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master

S: db431728d7b1658ed50cbece7bb91287b80952ad 172.25.254.120:6379

   slots: (0 slots) slave

   replicates 94334ee417e6536aaae592a95dfce014e60cf95f

S: 3ad4a43dd7e33933862f28e7a78bacad02d8d50c 172.25.254.130:6379

   slots: (0 slots) slave

   replicates c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a

M: 94334ee417e6536aaae592a95dfce014e60cf95f 172.25.254.10:6379

   slots:[1365-5460] (4096 slots) master

   1 additional replica(s)

M: 157195f57cd549409676209e18b4881146aedf3e 172.25.254.30:6379

   slots:[12288-16383] (4096 slots) master

   1 additional replica(s)

[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.254.140:6379 to make it join the cluster.

Waiting for the cluster to join

>>> Configure node as replica of 172.25.254.40:6379.

[OK] New node added correctly.

查看集群可以看到四主四从

[root@redis-node2 ~]# redis-cli -a 123456 --cluster check 172.25.254.20:6379                     Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

172.25.254.20:6379 (c362d17f...) -> 0 keys | 4096 slots | 1 slaves.

172.25.254.40:6379 (48f2f7aa...) -> 1 keys | 4096 slots | 1 slaves.

172.25.254.10:6379 (94334ee4...) -> 0 keys | 4096 slots | 1 slaves.

172.25.254.30:6379 (157195f5...) -> 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.254.20:6379)

M: c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a 172.25.254.20:6379

   slots:[6827-10922] (4096 slots) master

   1 additional replica(s)

S: ae6378ba83e2d927f63a56d286dd9b41e6361bff 172.25.254.140:6379

   slots: (0 slots) slave

   replicates 48f2f7aaf79ca9a0076d3f2e77722bf7d1bc1936

S: b33f211967dfea61399f275dc0c632cf28d18cc6 172.25.254.110:6379

   slots: (0 slots) slave

   replicates 157195f57cd549409676209e18b4881146aedf3e

M: 48f2f7aaf79ca9a0076d3f2e77722bf7d1bc1936 172.25.254.40:6379

   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master

   1 additional replica(s)

S: db431728d7b1658ed50cbece7bb91287b80952ad 172.25.254.120:6379

   slots: (0 slots) slave

   replicates 94334ee417e6536aaae592a95dfce014e60cf95f

S: 3ad4a43dd7e33933862f28e7a78bacad02d8d50c 172.25.254.130:6379

   slots: (0 slots) slave

   replicates c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a

M: 94334ee417e6536aaae592a95dfce014e60cf95f 172.25.254.10:6379

   slots:[1365-5460] (4096 slots) master

   1 additional replica(s)

M: 157195f57cd549409676209e18b4881146aedf3e 172.25.254.30:6379

   slots:[12288-16383] (4096 slots) master

   1 additional replica(s)

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

4.3集群维护

删除集群

[root@redis-node2 ~]# redis-cli -a 123456 --cluster del-node 172.25.254.140:6379 ae6378ba83e2d927f63a56d286dd9b41e6361bff

将槽位分配给10

[root@redis-node2 ~]# redis-cli -a 123456 --cluster reshard 172.25.254.20:6379

How many slots do you want to move (from 1 to 16384)? 4096

What is the receiving node ID? 94334ee417e6536aaae592a95dfce014e60cf95f10ID

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.

Source node #1: 48f2f7aaf79ca9a0076d3f2e77722bf7d1bc193640ID

Source node #2: done

删除master

[root@redis-node2 ~]# redis-cli -a 123456 --cluster del-node 172.25.254.40:6379 48f2f7aaf79ca9a0076d3f2e77722bf7d1bc1936

再查看集群

[root@redis-node2 ~]# redis-cli -a 123456 --cluster check 172.25.254.20:6379                     Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

172.25.254.20:6379 (c362d17f...) -> 1 keys | 8192 slots | 1 slaves.

172.25.254.10:6379 (94334ee4...) -> 0 keys | 6144 slots | 1 slaves.

172.25.254.30:6379 (157195f5...) -> 0 keys | 2048 slots | 1 slaves.

[OK] 1 keys in 3 masters.

0.00 keys per slot on average.

>>> Performing Cluster Check (using node 172.25.254.20:6379)

M: c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a 172.25.254.20:6379

   slots:[0-3412],[5461-10239] (8192 slots) master

   1 additional replica(s)

S: b33f211967dfea61399f275dc0c632cf28d18cc6 172.25.254.110:6379

   slots: (0 slots) slave

   replicates 157195f57cd549409676209e18b4881146aedf3e

S: db431728d7b1658ed50cbece7bb91287b80952ad 172.25.254.120:6379

   slots: (0 slots) slave

   replicates 94334ee417e6536aaae592a95dfce014e60cf95f

S: 3ad4a43dd7e33933862f28e7a78bacad02d8d50c 172.25.254.130:6379

   slots: (0 slots) slave

   replicates c362d17f7aaed4a7c1dbeb2eca262ba9dad4d80a

M: 94334ee417e6536aaae592a95dfce014e60cf95f 172.25.254.10:6379

   slots:[3413-5460],[10240-14335] (6144 slots) master

   1 additional replica(s)

M: 157195f57cd549409676209e18b4881146aedf3e 172.25.254.30:6379

   slots:[14336-16383] (2048 slots) master

   1 additional replica(s)

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2079784.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【yarn publish : 报错 passed folder/tarball doesn‘t exist 】

当执行yarn publish 时报错,具体命令类似 yarn publish --new-version ${NEW_VERSION} ${my-node-moudle-path}/my-node-modules 报错内容, 网上搜了一圈,基本没有这个报错的相关内容,最后分析并解决了,这里记录分享下…

NoSql数据库 - Redis Cluster集群详解及案例实现

Redis Cluster集群(无中心化设计) 1.1 Redis Cluster 工作原理 在哨兵sentinel机制中,可以解决redis高可用问题,即当master故障后可以自动将slave提升为master,从而可以保证redis服务的正常使用,但是无法…

查看exe文件所需要依赖库的方法

Windows 1.dumpbin /dependendsv [file_path]; 2.Qt windeployqt.exe打包 在exe的同一目录下生成需要的文件和库;如果不是qt程序结果如下:

发那科机床设备数据 转IEC61850项目案例

目录 1 案例说明 1 2 VFBOX网关工作原理 1 3 准备工作 2 4 网关采集发那科机床数据 2 5 用IEC61850协议转发数据 5 6 网关使用多个逻辑设备和逻辑节点的方法 7 7 案例总结 8 1 案例说明 设置网关采集发那科机床数据把采集的数据转成IEC61850协议转发给其他系统。 2 VFBOX网关…

Google Search Console:完整教程

Google 提供了各种工具来收集和分析网站数据,其中最有价值的工具之一是 Google Search Console (GSC)。前身为 Google Webmaster Tools,它为 SEO 提供了对网站性能的宝贵见解。自 2015 年推出以来,该平台取得了长足的发…

分库分表学习笔记(一)

图源(鹅厂技术架构师公众号) MySQL执行顺序: FROM:确定数据来源。JOIN:执行表之间的连接操作。WHERE:过滤记录。GROUP BY:对记录进行分组。HAVING:对分组结果进行过滤。SELECT&#…

如何用Java SpringBoot+Vue搭建美容美发管理系统?实战解析

🎓 作者:计算机毕设小月哥 | 软件开发专家 🖥️ 简介:8年计算机软件程序开发经验。精通Java、Python、微信小程序、安卓、大数据、PHP、.NET|C#、Golang等技术栈。 🛠️ 专业服务 🛠️ 需求定制化开发源码提…

47.【C语言】指针(重难点)(J)

目录 26.自制排序函数(★★) *分析 *代码 往期推荐 26.自制排序函数 *分析 之前在42.【C语言】冒泡排序写过一个排序函数&#xff0c;可以将此自制一个类似qsort的函数 画圈的地方是需要修改的 #include <stddef.h> void bubble_sort(void* base, size_t num,size_t w…

Mac Cocos2d-x工程通过xcode编译时,提示无法找到SDK的解决办法

经过对整个macOS的升级&#xff0c;发现原来的Cocos2d-x4.0可编译的工程&#xff0c;无法运行。 Xcode错误提示 mac cocos2d-x 4 Showing All Messages unable to find sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.…

2024年不可错过的7款最佳UI和UX设计工具推荐

在数字产品的成功中&#xff0c;用户界面 (UI) 和用户体验 (UX) 都起着至关重要的作用。UI 和 UX 是网页设计中相互补充的两个重要方面。UI 主要关注用户界面的设计&#xff0c;而 UX 则涵盖用户与产品或服务互动时的整体体验。在本文中&#xff0c;我们将深入探讨 UX 和 UI 的…

vc矩阵计算(转置,点乘,逆矩阵)

vc计算矩阵的转置,矩阵的点乘,矩阵的逆矩阵,参考网上的例子 矩阵点乘的例子: 矩阵逆矩阵计算例子: #include "stdafx.h" #include <math.h> //#include<complex.h> #include <iostream> #include <complex> #include <cstdli…

短视频SDK解决方案,代码逻辑结构清晰,接入便捷

美摄科技凭借其在多媒体处理领域的深厚积累&#xff0c;推出了高效、易用的短视频SDK解决方案&#xff0c;为开发者及内容创作者提供了一站式的短视频创作与编辑工具&#xff0c;让每一份灵感都能轻松转化为引人入胜的视觉盛宴。 一、技术领先&#xff0c;打造极致体验 美摄科…

非局部均值降噪算法(NLM)原理及实现

文章目录 一、概述二、算法原理三、算法流程四、MATLAB实现五、C实现参考文献 一、概述 在日常生活中&#xff0c;最常见的 CT 图像噪声是高斯白噪声。目前&#xff0c;针对高斯白噪声的处理方法&#xff0c;主要有空间域中的以平滑为基本思想的均值滤波、高斯滤波、局部滤波等…

案例研究丨MaxKB+Ollama:深圳市公共信用中心探索信用服务创新

深圳市公共信用中心隶属于深圳市市场监督管理局&#xff0c;主要负责对外提供深圳市企业公共信用信息报告查询和深圳市企业注册登记档案查询等服务。作为深圳市信用信息的权威发布机构&#xff0c;深圳市公共信用中心一直致力于为公众提供准确、及时的信用信息服务。 深圳信用…

2024年医疗行业关键词:精益管理

随着医疗技术的飞速发展、患者需求的日益多元化以及医疗资源的日益紧张&#xff0c;精益管理作为一种高效、科学的管理模式&#xff0c;正逐步成为医疗行业转型升级的关键驱动力。具体表现如深圳天行健企业管理咨询公司下文所述&#xff1a; 1. 优化服务流程 首先&#xff0c;…

Windows电脑本地安装跨平台文生音乐AI应用MusicGPT详细教程

文章目录 前言1. 本地部署2. 使用方法介绍3. 内网穿透工具下载安装4. 配置公网地址5. 配置固定公网地址 前言 今天和大家分享一下在Windows系统电脑上本地快速部署一个文字生成音乐的AI创作服务MusicGPT&#xff0c;并结合cpolar内网穿透工具实现随时随地远程访问使用进行AI音…

(一) 初入MySQL 【认识和部署】

前置资源 一、数据库概述 1.1、数据库基本概念 数据(Data) 描述事物的符号记录称为数据。数字、文字、图形、图像、声音、档案记录等都是数据。数据是以“记录”的形式按照统一的格式进行存储的&#xff0c;而不是杂乱无章的。 相同格式和类型的数据统一存放在一起&#xff0…

阿里云OSS文件存储

文章目录 参考准备创建bucketendpoint 和 bucket域名的访问路径AccessKey和OSS的开发文档 Springboot整合OSS引入依赖AliyunOssConfigAliyunOssPropertiesapplicatioin.yml简单上传和下载使用签名URL进行临时授权访问生成以PUT方法访问的签名URL来上传文件通过签名URL临时授权简…

WIFI 配网

配网:指的是外部向WiFi模块提供SSID和密码&#xff0c;以便Wi-Fi模块可以连接指定的热点 常见的配网方式有:-键配网smart config、SoftAP配网、蓝牙配网、屏幕配网。 1.0 一键配网 2.0 蓝牙配网 一键配网的模式对应的厂加模式 3.0 状态机WIFI模组物联网 4.0 创建枚举结构体 ty…

女性权益之镜:印度侵害事件分析

1.项目背景 近年来&#xff0c;印度社会关于女性权利的讨论日益频繁&#xff0c;然而&#xff0c;女性受侵害的违法事件仍层出不穷&#xff0c;这些事件不仅威胁到女性的生命安全&#xff0c;还深刻影响了社会的稳定与发展&#xff0c;尽管印度政府在法律和政策层面采取了一系…