redis哨兵模式

1禁止aof:

复制代码
vim  redis.conf 将 appendonly yes 改为 appendonly no。
(其中daemonize yes这是设置redis,后台启动。)

2.创建多个redis主、从配置文件:

复制代码
vim redis-6379.conf
内容:

include /root/myredis/redis.conf   #redis使用的文件夹。(因为配置环境变量后,只有复制redis.conf就可以在不同文件下创建redis)

pidfile /var/run/redis_6379.pid
port 6379  #端口号,不同端口号视为不同redis服务。
dbfilename dump6379.rdb # rdb文件名,即6379这个redis的数据文件。

vim redis-6380.conf
内容:

include /root/myredis/redis.conf  #redis使用的文件夹。(因为配置环境变量后,只有复制redis.conf就可以在不同文件下创建redis)

pidfile /var/run/redis_6380.pid
port 6380  #端口号,不同端口号视为不同redis服务。
dbfilename dump6380.rdb # rdb文件名,即6380这个redis的数据文件。

vim redis-6381.conf
内容:

include /root/myredis/redis.conf    #redis使用的文件夹。(因为配置环境变量后,只有复制redis.conf就可以在不同文件下创建redis)

pidfile /var/run/redis_6381.pid
port 6381  #端口号,不同端口号视为不同redis服务。
dbfilename dump6381.rdb # rdb文件名,即6381这个redis的数据文件。

············

3.开启服务:

复制代码
redis-server redis-6379.conf
redis-server redis-6380.conf
redis-server redis-6381.conf

4.为哨兵模式准备配置文件:

4-1在redis使用目录下新建sentinel.conf 配置文件中放入如下内容

复制代码
sentinel monitor xxxx 127.0.0.1 6379 1   #xxx为哨兵名字   IP地址   redis服务端口号 哨兵个数(一个文件一个哨兵)

5.启动哨兵

5-1在redis使用目录下使用哨兵

复制代码
redis-sentinel sentinel.conf

6.这样就完成哨兵,在主从模式下主机down机会自动在子机中选出新主机。待旧主机复活后成为子机。其中 在主从配置中添加replica-priority 10意思为0-100 哨兵模式下,选举的时候,有用!谁的值小谁优先级高!谁当主机 !!(可以不设置)

相关推荐
CoderYanger几秒前
Java EE 进阶:12.Spring AOP(第二弹)
java·前端·数据库·spring boot·spring·java-ee·mybatis
云上工程笔记13 分钟前
企业大模型调用数据安全与合规怎么保障:2026 年等保、数据留存、密钥与 IP 白名单清单
数据库·网络协议·tcp/ip
真上帝的左手1 小时前
4. 关系型数据库-MySQL-实战-索引治理
数据库·mysql·index
Joy T2 小时前
MySQL Outbox、Redis Streams 与 LangGraph——如何构建可靠的异步 AI Agent
数据库·redis·mysql·任务队列·redis streams·mysql outbox
FungLeo2 小时前
FengCMS · PHP+MySQL 升级实录· 回归测试从 69 项到 478 项:HTTP/数据库回归套件怎么搭
数据库·mysql·php·回归测试·fengcms
captain3762 小时前
Redis简单使用
数据库·redis·缓存
代码不停3 小时前
Redis基本数据类型
数据库·redis
aifannihao3 小时前
ON CONFLICT 冲突后返回空:sqlite3 实测 get-or-create
数据库·python·postgresql·sqlite3·标准库
得物技术3 小时前
Computer Use与Browser Use:揭秘Agent如何操作电脑和浏览器|得物技术
数据库·github·ai编程
IT规划师3 小时前
Redis 核心机制 | Pipeline 与 Batch:降低网络 RTT
redis·pipeline·batch·rtt·.net10