当前位置:网站首页>redis集群(cluster)+哨兵模式+主从(replicas)
redis集群(cluster)+哨兵模式+主从(replicas)
2022-06-12 01:38:00 【柔情柴少】
柴少制作,值得收藏
一、redis版本redis版本从2.4到2.6:
1、服务端支持lua脚本
2、键的过期时间支持毫秒
3、从节点只支持读功能
4、基于浮点数自增命令: incrbyfloat 和 hincrbyfloat
5、redis-cli可以使用--eval参数实现lua脚本执行
6、sort命令优化
7、重构大量代码,所有集群相关代码去掉,cluster功能将是3.0版本亮点
redis3.0
1、最大改动就是添加Redis分布式实现Redis Cluster (历时4年)
2、lru算法大幅提升
3、migrate连接缓存,大幅提升键迁移速度,migrate命令两个新参数 copy 和 replace
4、config set 设置maxmemory时,可以设置不同的单位(之前 只能是字节)
5、incr命令性能提升
redis5.0
1、新的流数据类型,(Stream data type)(支持多播的可持久化消息队列)
2、新的redis模块API:定时器、集群、字典API(Times,Cluster and Dictionary APIs)
3、RDB增加LFU和LRU信息
4、集群管理从Ruby(Redis-trib.rb)移植到了redis-cli中的c语言代码
5、新的有序集合(sorted set)命令:ZPOPMIN/MAX和阻塞变体(blocking variants)
6、客户端频繁连接和断开连接,性能表现更好
7、升级Jemalloc至5.1版本
8、引入 CLIENT UNBLOCK 和 CLIENT ID
9、新增 LOLWUT命令 地址
10、在不存在需要保持向后兼容性的地方,弃用“slave”术语
11、网络层中的差异优化lua相关的改进
12、引入动态的HZ(Dynamic HZ)以平衡空闲CPU使用率和响应性
13、对Redis核心代码进行了重构并在许多方面进行了改进
Redis6.0
1、多线程IO(Threaded I/O)
2、众多新模块(modules)API
3、更好的过期循环
4、支持SSL
5、ACLs权限控制
6、RESP3协议
7、客户端缓存(Client side caching)
8、无盘复制&PSYNC2
9、Redis-benchmark 支持集群
10、Redis-cli优化、重写Systemd支持
11、Redis 集群代理 于Redis6一通发布(在不同repo)
12、RDB更快加载
13、SPANDMEMBER和类似的命令具有更高的分布
14、STRALGO 命令
15、带有超时的Redis命令更易用
二、以上是简单对几个常用redis版本的总结,接下来,本人对于
Windows系统 redis3.0版本以及Linux系统redis6.0版本搭建
三主三从 服务集群 总结 以及注意事项1、Windows redis3版本 3主3从 服务集群搭建
(1) 复制6分redis文件

(2)注意:Windows中,redis配置文件为根目录下 redis.windows.conf Linux系统下,redis 配置文件为 redis.conf
为了方便,写个bat启动脚本,因为后面,需要频繁开启关闭redis服务端,而有了bat脚本,在Windows上,双击即可开启redis服务
新建txt文件 写入内容
title redis-6373
redis-server.exe redis.windows.conf关闭txt 重命名(随便起)后缀改为bat
----------------->>>>>
双击后效果
(3)开始修改6份redis的配置文件
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information.翻译:
# AOF和RDB持久性可以同时启用,不会有问题。
#如果AOF在启动时启用,Redis会加载AOF,也就是文件
#具有更好的耐用性保证。
#
#请查看http://redis.io/topics/persistence了解更多信息。
appendonly yes
.
中间有其他配置。。。
.
# Normal Redis instances can't be part of a Redis Cluster; only nodes that are
# started as cluster nodes can. In order to start a Redis instance as a
# cluster node enable the cluster support uncommenting the following:
#翻译:
#普通的Redis实例不能成为Redis集群的一部分; 只有节点
#作为集群节点启动。 为了启动一个Redis实例作为一个
# cluster node启用集群支持取消注释:
cluster-enabled yes
# Every cluster node has a cluster configuration file. This file is not
# intended to be edited by hand. It is created and updated by Redis nodes.
# Every Redis Cluster node requires a different cluster configuration file.
# Make sure that instances running in the same system do not have
# overlapping cluster configuration file names.
#翻译:
#每个集群节点都有一个集群配置文件。 这个文件不是
#用于手工编辑。 它由Redis节点创建和更新。
#每个Redis Cluster节点都需要一个不同的Cluster配置文件
#确保在同一系统中运行的实例没有
#重叠的集群配置文件名称。
cluster-config-file nodes-6378.conf
# Cluster node timeout is the amount of milliseconds a node must be unreachable
# for it to be considered in failure state.
# Most other internal time limits are multiple of the node timeout.翻译:
#集群节点超时是一个节点不可达的毫秒数
#表示它处于故障状态。
#大多数其他内部时间限制是节点超时的倍数。
cluster-node-timeout 15000
注意事项:
#requirepass 123456 (建议Linux服务器实际业务,设置密码,Windows上,柴少暂时不设置)
设置该redis密码
# masterauth <master-password>
设置主节点访问密码 (如果是主节点,不需要设置,如果主节点设置了密码,从节点需要设置该项,否则主从不会同步,因为没有密码,无法连接,查看节点信息,连接信息会显示down,如果连接上,显示up)
redis.windows.conf 配置文件内有端口号,需要把6379改掉,每个节点一个端口号
如果是单纯主从同步,不搭建集群 可以使用redis3.0版本的slaveof参数
从设置:slaveof 主机ip 端口
主不设置
如果主机有密码 masterauth 密码
2个参数,设置完成,即可实现主从同步
(4)redis3.0版本,或者说redis5.0版本以前,redis集群搭建是用ruby脚本编写,所以系统需要有ruby环境,下载地址
https://rubyinstaller.org/downloads/


安装时 3个选项全√
(5)安装Redis的Ruby驱动redis-xxxx.gem
下载地址 http:// https://rubygems.org/pages/download

注意:下载网络卡顿,可能会出现(下载失败,需要授权字样),所以需要有个好的网络,多试几次,能成功
下载解压后,切换到解压目录 如:E:\rubygems-3.3.15 执行命令 ruby setup.rb
再用GEM安装redis:切换到redis安装目录,需要在命令行中 执行 gem install redis
(6)下载集群脚本redis-trib
连接 http://newdouban.chaishao.xyz/redis-trib.rb
把该脚本放到 比如我的6378文件夹下 也就是任意一个redis文件夹下 终端切换到该目录 执行以下命令
redis-trib.rb create --replicas 1 127.0.0.1:6378 127.0.0.1:6377 127.0.0.1:6376 127.0.0.1:6375 127.0.0.1:6374 127.0.0.1:6373
(7) 以上 Windows上的redis3版本的redis集群3主3从 搭建成功 请看以下效果图


RedisDesktopManager 显示效果

注意:如果是集群 尽量不要在管理工具添加数据测试 因为 redis集群会根据添加数据的哈希槽,采用CRC16算法 (公式:index = hash(key)%N)算出新添数据,该往哪个主节点添加,这样会导致,在桌面管理工具添加时,如果不该添加在当前redis中,会重定向到另一个节点,从而导致,该节点连接失败,因为其他节点已经连接 (亲自试一下就知道了)
至此 Windows redis集群搭建完毕
下面 开始Linux集群
2、Linux 系统上 redis集群搭建 redis采用6.0版本
因为5.0版本以上,redis-cli继承了redis-trib.rb的C源码,还有相关命令,所以下载下来,直接拿来用,用redis-cli即可 创建集群的命令会有些许改变,整体相差不多
(1)下载redis http://download.redis.io/releases/
版本自己选 我选了6.0.5版本
编译安装

注意事项:
1、当前目录的redis.conf 是配置文件 启动服务和客户端的redis-server和redis-cli在src目录里面
2、打开src你会发现 redis-trib.rb仍然有,既然redis-cli集成了redis-trib.rb的C源码,为什么还有这个?可以深入探究一番,留给大家思考
3、redis6版本的使用,需要Linux的gcc升级到9版本以上,具体原因,可以深入探究
升级gcc到9版本的命令:
yum -y install centos-release-scl scl-utils-build
yum -y install -y devtoolset-8-toolchain
scl enable devtoolset-8 bash4、
redis源码编译安装 需要用到Linux的内存分配器 有3种: jemalloc(默认 更优) tcmalloc libc
所以我们使用jemalloc这种内存分配器
这种分配器是默认,所以不用安装时 不用添加参数等
5、第4条,如果你在redis目录下直接编译安装,会报错,jemalloc找不到,经过柴少测试,需要进入src目录下安装,他就能找到deps目录下的jemalloc了
6、当集群启动后,创建成功,每个redis目录下,会多出3个文件,分别为:dump.rdb appendonly.aof nodes-6378.conf
由此可见,数据存入到了rdb快照和aof里面,nodes-6378.conf肯定是节点配置文件,而且里面存了哈希槽位的多少,具体信息
算了,打开看一眼:
7、配置,还是Windows上的几个配置,Linux上不再多说,写一下对于主从节点的增加
删除,直接kill掉进程即可
本来3主3从 接下来 再增加一组主从 并且从其他3个主节点,给第4个主节点,分配哈希槽位
哈希槽位置 一共16384个 目前 6378节点5462个槽位 6377和6376分别都是5461个槽位
目前是4个主节点 16384/4=4096 从其他3个主节点平均分配过来一共4096节点
1、启动redis服务
2、查看全部redis进程
3、配置一下 启动2个redis服务 (切记 redis.conf里面的port配置改掉)
随便找个集群节点,进入src目录 登录节点服务 6378为例 redis-cli -c -h 127.0.0.1 -p 6378 -a 123456
-c 切入节点
-h ip
-a 密码
4、查看全部节点
5、 执行命令 cluster meet 127.0.0.1 6371 可以将6371redis服务加入节点 6372同样如此
6、再次执行 cluster nodes 可以看到新的节点已经加入(柴少之所以里面有6371和6372,是因为提前做好了)
7、把6372当做主节点 把6371当做从节点
先给6372分配槽位 4096个
命令: redis-cli --cluster reshard 127.0.0.1 6372 -a 123456
填写4096 那个all写错了 因为下一步需要写all
ID那里填写 6372主节点对应的节点ID
然后 会询问你 从哪里分配槽位 写 all 集群会平均地从其他几个主节点取一部分槽位,分配给6372主节点4096个
下一步 把6371节点 分配给6372为从节点
切入到6371文件夹 启动6371节点 将该节点分配给6372主节点
命令 cluster replicate (主节点ID)
再次cluster nodes 查看一下各个节点信息 你会发现 大功告成
完成
但是还没完 下面说一下(哨兵模式)
三、redis哨兵模式边栏推荐
- Matlab foundation 04 - detailed analysis of the use and complex application of colon operator ":"
- Don't write about the full screen explosion, try the decorator mode, this is the elegant way!!
- Analysis report on demand status and Prospect Forecast of global and Chinese remote control helicopter industry 2022-2028
- Creating a flutter high performance rich text editor - rendering
- "C'est plus sûr d'apprendre une technologie!" Hangzhou Campus Little Brother transfer software test, Hi - Ti 10K + double break!
- State Administration of market supervision and state Internet Information Office: carry out data security management certification
- Jmeter接口测试之常用断言
- 一文get,最容易碰上的接口自动化测试问题汇总
- Point cloud perception algorithm interview knowledge points (II)
- pca从0到1
猜你喜欢
![[n32g457] remote monitoring of graffiti cloud based on RT thread and n32g457](/img/c3/5c9970d7e77afce925814d0ecd3b96.jpg)
[n32g457] remote monitoring of graffiti cloud based on RT thread and n32g457

感知机从0到1
![[project training] verification notes](/img/bd/fa6111d967da6258bc53d6755cc3a2.png)
[project training] verification notes

Jmeter接口测试之常用断言

pca从0到1

“還是學一門技術更保險!”杭州校區小哥哥轉行軟件測試,喜提10K+雙休!

联调这夜,我把同事打了...
![MySQL training report [with source code]](/img/c2/46bdc2f8c522d2c8881e532b6f3f49.png)
MySQL training report [with source code]

I worked as a software testing engineer in a large factory and wrote "one day's complete workflow"

How to access the traifik proxy dashboard using the rancher desktop
随机推荐
Analysis report on operation trends and development strategies of global and Chinese plastic adhesive industry 2022-2028
Redis startup and shutdown commands
Article 3: Design of multifunctional intelligent trunk following control system | undergraduate graduation project - [defense ppt]
The 14th five year plan and investment feasibility study report of global and Chinese hydraulic ester base oil industry 2022 ~ 2028
Point cloud perception algorithm interview knowledge points (II)
Article 4: Design of multifunctional intelligent trunk following control system | undergraduate graduation project - [data search skills + reference resource integration]
Vue3+ts+node creates personal blog (database design)
Annotate your own point cloud dataset with labelcloud open source tool as a tutorial of Kitti annotation format (support PCD and bin point clouds)
Kill, pkill, killall, next, what I brought to you in the last issue is how to end the process number and rush!
Matlab foundation 04 - detailed analysis of the use and complex application of colon operator ":"
Interviewer: do you understand redis' shared object pool?
Weekly CTF 第一周:神奇的磁带
Blue Bridge Cup - 2012b Group real question 3 specific drinking capacity
Program environment and pretreatment
2022-06-11: note that in this document, graph is not the meaning of adjacency matrix, but a bipartite graph. In the adjacency matrix with length N, there are n points. Matrix[i][j] represents the dist
Such a change in people's understanding of the industrial Internet is not achieved overnight
Don't write about the full screen explosion, try the decorator mode, this is the elegant way!!
"It's safer to learn a skill!" The little brother of Hangzhou campus changes to software testing, and likes to mention 10k+ weekend!
Recursive and non recursive transformation
[project training] wechat official account template message push







