部署redis-cluster
1、环境准备

☆ 每个Redis 节点采用相同的相同的Redis版本、相同的密码、硬件配置
☆ 所有Redis服务器必须没有任何数据
#所有主从节点执行:
[root@ubuntu2004 ~]#bash install_redis.sh
#脚本参考:https://blog.51cto.com/dayu/5805274
2、启用 redis cluster 配置
#所有主从节点执行:
#每个节点修改redis配置,必须开启cluster功能的参数
[root@master-1 ~]#vim /apps/redis/etc/redis.conf
bind 0.0.0.0
masterauth 123456 #建议配置,否则后期的master和slave主从复制无法成功,还需再配置
requirepass 123456
cluster-enabled yes #取消此行注释,必须开启集群,开启后 redis 进程会有cluster标识
cluster-config-file nodes-6379.conf #取消此行注释,此为集群状态数据文件,记录主从关系及slot范围信息,由redis cluster 集群自动创建和维护
cluster-require-full-coverage no #默认值为yes,设为no可以防止一个节点不可用导致整个cluster不可用
#验证当前Redis服务状态:
[root@master-1 ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 511 0.0.0.0:6379 0.0.0.0:*
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 511 0.0.0.0:16379 0.0.0.0:*
LISTEN 0 511 [::1]:6379 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 511 [::1]:16379 [::]:*
#开启了16379的cluster的端口,实际的端口=redis port + 10000
3、创建集群
#10.0.0.101:
[root@master-1 ~]#redis-cli -a 123456 --cluster create 10.0.0.101:6379 10.0.0.102:6379 10.0.0.103:6379 10.0.0.18:6379 10.0.0.28:6379 10.0.0.38:6379 --cluster-replicas 1
#命令redis-cli的选项 --cluster-replicas 1 表示每个master对应一个slave节点
4、验证集群
#查看主从状态
[root@master-1 ~]#redis-cli -a 123456 -c info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:1
slave0:ip=10.0.0.28,port=6379,state=online,offset=602,lag=0
......
#查看对应关系
[root@master-1 ~]#redis-cli -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
c58b6d30550a3d6d682d2a4f7563efabf470bd82 10.0.0.38:6379@16379 slave 139317befd252551e1135b27d32ce557133ec71a 0 1667098745948 2 connected
......
#验证集群状态
[root@master-1 ~]#redis-cli -a 123456 cluster info
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
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 #三个集群
......
#查看任意节点的集群状态
[root@slave-1 ~]#redis-cli -a 123456 --cluster info 10.0.0.38:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.0.0.102:6379 (139317be...) -> 0 keys | 5462 slots | 1 slaves.
10.0.0.101:6379 (98df8874...) -> 0 keys | 5461 slots | 1 slaves.
10.0.0.103:6379 (8d72bbb5...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
[root@slave-1 ~]#redis-cli -a 123456 --cluster check 10.0.0.38:6379
5、测试写入数据
[root@master-1 ~]#redis-cli -a 123456 -h 10.0.0.102 set k1 wang
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
(error) MOVED 12706 10.0.0.103:6379 #槽位不在当前node所以无法写入
[root@master-1 ~]#redis-cli -a 123456 -h 10.0.0.103 set k1 wang
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
OK
[root@slave-1 ~]#redis-cli -a 123456 -h 10.0.0.103 get k1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
"wang"
[root@master-1 ~]#redis-cli -a 123456 -h 10.0.0.103 get k1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
"wang"
#使用选项-c 以集群模式连接
[root@master-1 ~]#redis-cli -c -h 10.0.0.18 -a 123456 --no-auth-warning
10.0.0.18:6379> cluster keyslot test
(integer) 6918
10.0.0.18:6379> set test mylove
-> Redirected to slot [6918] located at 10.0.0.102:6379
OK
10.0.0.102:6379> get test
"mylove"
10.0.0.102:6379> exit
[root@master-1 ~]#redis-cli -h 10.0.0.102 -a 123456 --no-auth-warning get test
"mylove"
部署redis-cluster的更多相关文章
- 部署Redis Cluster 6.0 集群并开启密码认证 和 Redis-cluster-proxy负载
部署Redis Cluster集群并开启密码认证 如果只想简单的搭建Redis Cluster,不需要设置密码和公网访问,可以参考官方文档. 节点介绍 Cluster模式推荐最少有6个节点,本次实验搭 ...
- K8S部署Redis Cluster集群
kubernetes部署单节点redis: https://www.cnblogs.com/zisefeizhu/p/14282299.html Redis 介绍 • Redis代表REmote DI ...
- K8S部署Redis Cluster集群(三主三从模式) - 部署笔记
一.Redis 介绍 Redis代表REmote DIctionary Server是一种开源的内存中数据存储,通常用作数据库,缓存或消息代理.它可以存储和操作高级数据类型,例如列表,地图,集合和排序 ...
- 在 K8S 中快速部署 Redis Cluster & Redisinsight
Redis Cluster 部署 使用 Bitnami helm chart 在 K8S redis 命名空间中一键部署 Redis cluster . helm repo add bitnami h ...
- 如何用docker部署redis cluster
前言 由于本人是个docker控,不喜欢安装各种环境,而且安装redis-trib也有点繁琐,索性用docker来做redis cluster. 本文用的是伪集群,真正的集群放到不同的机器即可.端口是 ...
- 手把手教你部署 Redis Cluster
环境准备 阿里云申请3台ECS,如下: 序号 内网IP OS A 172.16.190.78 CentOS 7.6 B 172.16.242.36 CentOS 7.6 C 172.16.190.77 ...
- 第七章· Redis Cluster 核心技术
Redis Cluster 分布式集群 Redis Cluster 安装部署 Redis Cluster 集群管理操作(核心)
- window下使用Redis Cluster部署Redis集群
日常的项目很多时候都需要用到缓存.redis算是一个比较好的选择.一般情况下做一个主从就可以满足一些比较小的项目需要.在一些并发量比较大的项目可能就需要用到集群了,redis在Windows下做集群可 ...
- Redis Cluster部署、管理和测试
背景: Redis 3.0之后支持了Cluster,大大增强了Redis水平扩展的能力.Redis Cluster是Redis官方的集群实现方案,在此之前已经有第三方Redis集群解决方案,如Twen ...
- Redis Cluster的搭建与部署,实现redis的分布式方案
前言 上篇Redis Sentinel安装与部署,实现redis的高可用实现了redis的高可用,针对的主要是master宕机的情况,我们发现所有节点的数据都是一样的,那么一旦数据量过大,redi也会 ...
随机推荐
- 读取图片文件MetaFile放入Windows剪切板
前言 前段时间群里有个小伙在工作中遇到一个问题,透明的图片存入剪切板在粘贴到adobe PDF中出现不透明问题但是粘贴到Excel可以,还有就是从excel复制再粘贴到PDF也是可以.小伙在群里发了两 ...
- Shell第一章《变量》
shell前言 什么是shell shell-'壳' 命令解释器,一种应用程序 shell语言特点 SHELL语言是指UNIX操作系统的命令语言,同时又是该命令语言的解释程序的简称. Shell本身是 ...
- 大家都能看得懂的源码 - ahooks 是怎么处理 DOM 的?
本文是深入浅出 ahooks 源码系列文章的第十三篇,该系列已整理成文档-地址.觉得还不错,给个 star 支持一下哈,Thanks. 本篇文章探讨一下 ahooks 对 DOM 类 Hooks 使用 ...
- 【Traefik二次开发】服务 Service 开发
Service 定义 https://doc.traefik.io/traefik/routing/services/ The Services are responsible for configu ...
- 【读书笔记】C#高级编程 第十四章 内存管理和指针
(一)后台内存管理 1.值数据类型 Windows使用一个虚拟寻址系统,该系统把程序可用的内存地址映射到硬件内存中的实际地址,该任务由Windows在后台管理(32位每个进程可使用4GB虚拟内存,64 ...
- torch.sort 和 torch.argsort
定义 torch.sort(input,dim,descending) torch.argsort(input,dim,descending) 用法 torch.sort:对输入数据排序,返回两个值, ...
- Windows 10 Technical Preview 屏幕亮度
下载了 Windows 10 Technical Preview 安装好之后都挺正常的,就是显卡驱动没有, 联上网络, 自动找到驱动,看起来一切都挺好的. 但是重启之后,屏幕就变得特别暗了, 亮 ...
- 用compose安装tp框架提示警告putenv
PHP Warning: putenv() has been disabled for security reasons in phar://C:/ProgramData/ComposerSetup ...
- 利用Kafka的Assign模式实现超大群组(10万+)消息推送
引言 IM即时通信场景下,最重要的一个能力就是推送:在线的直接通过长连接网关服务转发,离线的通过APNS或者极光等系统进行推送. 本文主要是针对在线用户推送场景来进行总结和探讨:如何利用Kafka ...
- Elasticsearch:Cluster备份 Snapshot及Restore API
Elasticsearch提供了replica解决方案,它可以帮我们解决了如果有一个或多个node失败了,那么我们的数据还是可以保证完整的情况,并且搜索还可以继续进行.但是,有一种情况是我们的所有的n ...