当前位置:网站首页>Redis哨兵机制及配置过程
Redis哨兵机制及配置过程
2022-07-21 05:16:00 【weixin_46685039】
一.什么是哨兵机制
Redis的哨兵(sentinel) 系统用于管理多个 Redis 服务器,该系统执行以下三个任务:
- 监控(Monitoring): 哨兵(sentinel) 会不断地检查你的Master和Slave是否运作正常(心跳)。
- 提醒(Notification):当被监控的某个 Redis出现问题时, 哨兵(sentinel) 可以通过 API 向管理员或者其他应用程序发送通知。
- 自动故障迁移(Automatic failover):当一个Master不能正常工作时,通过投票机制,选举出新的master。
哨兵(sentinel) 视为一个单独的可执行文件 redis-sentinel ,但实际上它只是一个 运行在特殊模式下的 Redis 服务器。
二.哨兵模式配置
1.准备工作
准备三台虚拟机,一台主机,两台从机。并且都实现了主从复制(我上一篇有写怎么配置redis的主从复制)
2.哨兵模式配置
两台从机都配置哨兵。
我的主机端口号:192.168.137.68
现在配置第一台从机的哨兵。(第二从机哨兵配置模仿第一台,但是要把从机名改一下,比如把mymaster1 改为 mymaster2)
2.1 修改sentinel.conf配置文件
sentinel monitor mymaster1 192.168.137.68 6379 1
#主节点 名称 IP 端口号 选举次数这个主服务器判断为失效至少需要 1 个 Sentinel同意
sentinel auth-pass mymaster1 root
2.2修改 Sentinel 认为服务器已经断线所需的毫秒数
sentinel down-after-milliseconds mymaster1 30 (原值为30000 30毫秒)
2.3配置多少个从服务器同时对新的主服务器进行同步
sentinel parallel-syncs mymaster1 2
2.4启动哨兵模式
./redis-server ../sentinel.conf --sentinel &
好了,到了这里哨兵已经配置完成了
三.验证哨兵(杀死主机,从机上位)
2.5杀死主机master
主机操作:
查看redis进程:lsof -i:6379
杀死进程:kill -9 redis进程号
2.6两台从机投票选举,30毫秒后其中一台从机成为主机。
1.其中一台从机变主机
查看进程:lsof -i:6379
2.查看另外一台从机
备注:
1.主从切换无追加密码问题
Master配置文件相较原始配置文件需要修改以下地方
Slave配置文件相较原始配置文件需要修改以下地方
2.停止哨兵模式
查看进程号:ps -aux | grep '6379'
杀死进程: kill -9 哨兵进程号
边栏推荐
- In depth analysis of multiple knapsack problem (Part 2)
- 029: Tao Tao picks apples
- n factorial
- 004: print characters
- 029:陶陶摘苹果
- Paoding solves the fiboracci sequence and knapsack problem - analyze the optimization process of the two problems in detail, and take you to understand dynamic programming from the most basic problem!
- Heap - principle to application - heap sorting, priority queue
- 第三周ACM训练报告
- 西瓜书第二章笔记-性能度量
- 第十周ACM训练报告
猜你喜欢
In depth analysis of multiple knapsack problem (Part 2)
844. Compare strings with backspace
108. Convert an ordered array into a binary search tree
Vs2019+opencv installation and configuration tutorial
QT初学者
438. 找到字符串中所有字母异位词
What impact does the Internet of things have on the development of enterprises?
74. Search two-dimensional matrix
What are the functions and application industries of testing equipment development?
Blockbuster: the domestic ide was released and developed by Alibaba. It is completely open source (high performance + high customization)
随机推荐
卡牌
Characteristics and differences between PCB and integrated circuit
机器学习-频率派vs贝叶斯派
234. 回文链表
148. 排序链表
004:打印字符
取石子
994. 腐烂的橘子
438. 找到字符串中所有字母异位词
2020普及组总结
328. Parity linked list
016:简单计算器
What is PCBA? What is the importance of PCBA testing?
三类基于贪心思想的区间覆盖问题
第八周ACM训练报告
Quick sort
In depth analysis of LinkedList source code
如何用数组模拟栈(超简易代码)
第三周ACM训练报告
What is the difference between embedded hardware and software in embedded development?