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就可以摆脱从身份

相关推荐
广师大-Wzx3 小时前
一篇文章看懂MySQL数据库(下)
java·开发语言·数据结构·数据库·windows·python·mysql
hef2884 小时前
golang如何使用range over func_golang range over func迭代器使用方法
jvm·数据库·python
qq_380619165 小时前
html如何查看windows
jvm·数据库·python
爱学习的小邓同学5 小时前
MySQL --- MySQL数据库基础
数据库·mysql
wgzrmlrm746 小时前
如何加固SQL环境部署_删除默认安装的示例数据库
jvm·数据库·python
雨墨✘6 小时前
golang如何实现设备指纹识别_golang设备指纹识别实现详解
jvm·数据库·python
程序员大辉6 小时前
没想到!一直要开会员的Navicat 终于有免费版了
数据库
数厘7 小时前
2.15 sql基础查询(SELECT、FROM、字段别名、常量与表达式)
数据库·sql·oracle
可观测性用观测云7 小时前
观测云数据转发和存档最佳实践
数据库