redis哨兵模式

redis持久化

Redis的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上(这称为"半持久化模式"RDB);也可以把每一次数据变化都写入到一个 append only file(AOF)里面(这称为"全持久化模式")。

下载redis: yum install -y redis
启动redis:systemctl start redis
编译文件:vim /etc/redis.conf (搜索APPEND)

编译文件:vim /etc/redis.conf

重启redis服务:systemctl restart redis

在/etc/下复制文件:cp redis.conf redis_6379.conf

更改文件内309行

355行 改成自己文件名

cp redis_6379.conf redis_6380.conf

编辑文件 vim redis_6380.conf(改自己文件名,两处)

端口号138行

533行 写主的IP端口号

创建目录:mkdir /etc/redis

mv redis_63* redis

创建6381:cp redis_6379.conf redis_6381.conf

更改6381文件:sed -i 's/6379/6381/' redis_6381.conf

启动所有redis服务:for i in 6379 6380 6381; do redis-server /etc/redis/redis_${i}.conf;done
注意!!!其他IP地址改从同理

创建哨兵文件:mkdir redis_sentinel

cp /etc/redis-sentinel.conf /etc/redis_sentinel/

mv redis-sentinel.conf redis-sentinel_26379.conf (更改3处)

再复制两个文件

cp redis-sentinel_26379.conf redis-sentinel_26380.conf

cp redis-sentinel_26379.conf redis-sentinel_26381.conf

sed -i 's/6379/6380/' redis-sentinel_26380.conf

sed -i 's/6379/6381/' redis-sentinel_26381.conf

sed -i 's/127.0.0.1 6379/192.168.11.133 6379/' redis-sentinel_26379.conf

sed -i 's/127.0.0.1 6380/192.168.11.133 6379/' redis-sentinel_26380.conf

sed -i 's/127.0.0.1 6381/192.168.11.133 6379/' redis-sentinel_26381.conf

验证

grep -r '192.168.11.133 6379' ./

轮个登录指向主:

redis-cli -h 192.168.11.133 -p 6380

slaveof 192.168.11.133 6379

redis-cli -h 192.168.11.133 -p 6381

slaveof 192.168.11.133 6379

验证:

开启哨兵:

redis-sentinel /etc/redis_sentinel/redis-sentinel_26379.conf

redis-sentinel /etc/redis_sentinel/redis-sentinel_26380.conf

redis-sentinel /etc/redis_sentinel/redis-sentinel_26381.conf

关闭主

验证:


在从的redis-cli中写入slaveof no one就可以摆脱从身份

相关推荐
小小龙学IT9 分钟前
Qt 元对象系统(Meta-Object System)深度解析:从 MOC 到反射式编程
数据库·qt
想带你从多云到转晴37 分钟前
MySQL重点梳理
数据库·mysql
胖头鱼的鱼缸(尹海文)1 小时前
胖头鱼的技术专栏-465 数据库能力上移还是下沉:库变弱了,应用就变重了(20260828)
数据库
2601_962181961 小时前
Redis Redis介绍、安装 - Redis客户端
数据库·redis·postman
2601_962062942 小时前
Spring Boot入门——Spring Boot项目的创建
java·数据库·spring boot
冰暮流星2 小时前
mysql之外键约束
数据库·mysql
茶栀(*´I`*)2 小时前
数据库零基础入门指南:从基本概念到 SQL 实战
数据库·sql
ERD Online2 小时前
Cursor 连上 MCP:读一张 ER 图,提交一版建议
数据库·后端·开源·cursor·mcp
foolishlee2 小时前
openGauss postmaster退出流程
数据库
叫我:松哥3 小时前
基于flask仿小米商城管理系统,使用flask开的一个商场网站
数据库·后端·python·flask