首页 > 数据库 >部署redis-cluster

部署redis-cluster

时间:2022-10-30 12:01:03浏览次数:52  
标签:10.0 6379 部署 0.0 redis cluster root


1、环境准备

部署redis-cluster _redis

☆ 每个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"


标签:10.0,6379,部署,0.0,redis,cluster,root
From: https://blog.51cto.com/dayu/5807495

相关文章

  • redis-dump 工具安装
    说明redis-dump是一个第三方的工具,这就意味着需要安装才能使用,它依赖与ruby。经过踩坑发现对ruby版本还是有要求的,Centos7.+使用yuminforuby发现版本为2.0.0.+,这个时候......
  • 部署redis-cluster
     1、环境准备☆每个Redis节点采用相同的相同的Redis版本、相同的密码、硬件配置☆所有Redis服务器必须没有任何数据#所有主从节点执行:[root@ubuntu2004~]#......
  • redisson分布式限流[RRateLimiter]源码分析
    接下来在讲一讲平时用的比较多的限流模块--RRateLimiter1.简单使用publicstaticvoidmain(String[]args)throwsInterruptedException{RRateLimiterrateLimit......
  • 多语言在线客服系统源码-自动识别中英环境-私有化部署完美支持跨境电商网站
    如果您的客户遍布全球,客户沟通就必须跨越语言障碍。用客户当地的语言跟他们交谈,可以帮助您在客户生命周期的所有阶段建立信任,当然也包括服务支持。 具体做法,看看这四点......
  • 这样讲Redis Cluster的工作原理,或许你真的能听懂~
    什么是Redis集群?Redis从3.0开始就支持集群,节点之间使用gossip协议进行通信,实现了去中心化,集群中支持动态的添加和删除节点,动态迁移数据以及自动执行故障转移。什么是数据Sh......
  • 这样讲Redis哨兵机制Sentinel的工作原理,或许你真的能听懂~
    什么是哨兵机制?Sentinel是Redis官方提出的一个高可用解决方案。它由一个或多个sentinel实例构成sentinel系统。为什么要用哨兵机制?我们都知道Redis具备主从复制的功能,......
  • windows下安装redis服务
    下载地址:Releases·microsoftarchive/redis·GitHubRedis支持32位和64位。这个需要根据你系统平台的实际情况选择,这里我们下载Redis-x64-xxx.zip压缩包到D盘......
  • 【Redis高手修炼之路】③持久化
    持久化​​1.RDB​​​​1.1自动备份​​​​1.2手动备份​​​​1.3与RDB相关的配置​​​​2.AOF​​​​2.1开启AOF​​​​2.2共存?谁优先?​​​​2.3与AOF相关......
  • VS2017 IIS 部署.net core web项目
    直接上内容: 安装IIS这个不在重复,可百度搜索到。 点击IIS查看模块:查看是否安装了AspNetCoreModule模块,如果没有安装可下载:​​http://download.microsoft.com/downlo......
  • 宝塔面板部署vue项目
    一、安装宝塔面板在宝塔面板官网,找到linux安装命令大全 https://www.bt.cn/new/btcode.html ,使用一下命令安装宝塔面板 找到服务器实例为实例建立远程连接,在连接......