Sentinel系统监控Redis主从节点
author:JevonWei
版权声明:原创作品
blog:http://119.23.52.191/
构建Sentinel监控Redis的主节点架构
拓扑结构结构
拓扑环境
master 172.16.252.82
slave1 172.16.252.184
slave2 172.16.252.67
sentinl1 172.16.252.82
sentinl2 172.16.252.184
sentinl3 172.16.252.67
实现Redis的主从复制
各节点安装redis(epel)
[root@master ~]# yum -y install redis
[root@master ~]# setenforce 0
[root@master ~]# iptables -F
[root@master ~]# systemctl start redis
[root@slave1 ~]# yum -y install redis
[root@slave1 ~]# setenforce 0
[root@slave1 ~]# iptables -F
[root@slave1 ~]# systemctl start redis
[root@slave2 ~]# yum -y install redis
[root@slave2 ~]# setenforce 0
[root@slave2 ~]# iptables -F
配置redis
master
[root@slave1 ~]# vim /etc/redis.conf
bind 172.16.252.82 \\监听本地IP
requirepass "danran" 添加认证密码
[root@slave1 ~]# systemctl restart redis
[root@slave1 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 172.16.252.184:6379 *:*
slave1
[root@slave1 ~]# vim /etc/redis.conf
bind 172.16.252.184 \\监听本地IP
[root@slave1 ~]# systemctl restart redis
[root@slave1 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 172.16.252.184:6379 *:*
[root@slave1 ~]# redis-cli -h 172.16.252.184
172.16.252.184:6379> SLAVEOF 172.16.252.82 6379 设置成为172.16.252.82的从数据库
OK
172.16.252.184:6379> CONFIG SET masterauth danran 设置master主服务端的认证密码
OK
172.16.252.184:6379> CONFIG REWRITE 保存到配置文件永久生效
OK
slave2
[root@slave2 ~]# vim /etc/redis.conf
bind 172.16.252.67 \\监听本地IP
slaveof 172.16.252.82 6379
masterauth "danran"
修改REPLICAION配置段的slaveof和masterauth参数设置从节点
[root@slave2 ~]# systemctl start redis
[root@slave2 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 172.16.252.67:6379 *:*
master查看主从节点信息
[root@master ~]# redis-cli -h 172.16.252.82
172.16.252.82:6379> AUTH danran
OK
172.16.252.82:6379> INFO Replication
# Replication
role:master
connected_slaves:2
slave0:ip=172.16.252.184,port=6379,state=online,offset=652,lag=0 \\lag表示与master节点同步延时时长
slave1:ip=172.16.252.67,port=6379,state=online,offset=652,lag=0
master_repl_offset:652
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:651
测试数据同步
master
[root@master ~]# redis-cli -h 172.16.252.82
172.16.252.82:6379> AUTH danran
OK
172.16.252.82:6379> ZADD colors 1 red 2 bulue 6 green 4 gray
(integer) 4
slave1
[root@slave1 ~]# redis-cli -h 172.16.252.184
172.16.252.184:6379> ZRANGE colors 0 5
1) "red"
2) "bulue"
3) "gray"
4) "green"
slave2
[root@slave2 ~]# redis-cli -h 172.16.252.67
172.16.252.67:6379> ZRANGE colors 0 5
1) "red"
2) "bulue"
3) "gray"
4) "green"
配置Sentinel系统
sentinel1
[root@sentinel ~]# vim /etc/redis-sentinel.conf
bind 172.16.252.82 监听IP
sentinel monitor mymaster 172.16.252.82 6379 2 mymaster为master的标识符,监控172.16.252.82主机的6379端口,至少2个主机投票推举方可推举出主节点
sentinel auth-pass mymaster danran sentinel认证密码,建议所有节点的密码认证一致
sentinel down-after-milliseconds mymaster 5000 当超出5s连接不到主节点时,则表示主节点故障,重新推选出主节点
[root@sentinel ~]# systemctl start redis-sentinel
[root@sentinel ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:26379 *:*
sentinel2
[root@sentine2 ~]# vim /etc/redis-sentinel.conf
bind 172.16.252.184 监听地址
sentinel monitor mymaster 172.16.252.82 6379 2 mymaster为master的标识符,监控172.16.252.82主机的6379端口,至少2个主机投票推举方可推举出主节点
sentinel auth-pass mymaster danran sentinel认证密码,建议所有节点的密码认证一致
sentinel down-after-milliseconds mymaster 5000 当超出5s连接不到主节点时,则表示主节点故障,重新推选出主节点
[root@sentine2 ~]# systemctl start redis-sentinel
[root@sentine2 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:26379 *:*
sentinel3
[root@sentine3 ~]# vim /etc/redis-sentinel.conf
bind 172.16.252.67 监听IP
sentinel monitor mymaster 172.16.252.82 6379 2 mymaster为master的标识符,监控172.16.252.82主机的6379端口,至少2个主机投票推举方可推举出主节点
sentinel auth-pass mymaster danran sentinel认证密码,建议所有节点的密码认证一致
sentinel down-after-milliseconds mymaster 5000 当超出5s连接不到主节点时,则表示主节点故障,重新推选出主节点
[root@sentine3 ~]# systemctl start redis-sentinel
[root@sentine3 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:26379 *:*
sentinel查看主从节点信息并测试主从节点切换
[root@sentinel ~]# redis-cli -h 172.16.252.82 -p 26379
172.16.252.82:26379> SENTINEL masters 显示主节点的属性信息,主节点为172.16.252.82
1) 1) "name"
2) "mymaster" 主节点名称
3) "ip"
4) "172.16.252.82"
5) "port"
6) "6379"
7) "runid"
8) "2847d8ceda8d3a03f0df814091fc5174921f57ea"
9) "flags"
10) "master"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "198"
19) "last-ping-reply"
20) "198"
21) "down-after-milliseconds"
22) "3000"
23) "info-refresh"
24) "4299"
25) "role-reported"
26) "master"
27) "role-reported-time"
28) "4305"
29) "config-epoch"
30) "0"
31) "num-slaves"
32) "2"
33) "num-other-sentinels"
34) "2"
35) "quorum"
36) "2"
37) "failover-timeout" 超时时间
38) "180000"
39) "parallel-syncs"
40) "1"
172.16.252.82:26379> SENTINEL slave mymaster 显示主节点为mymaster的从节点属性信息
(error) ERR Unknown sentinel subcommand 'slave'
172.16.252.82:26379> SENTINEL slaves mymaster
1) 1) "name"
2) "172.16.252.184:6379"
3) "ip"
4) "172.16.252.184"
5) "port"
6) "6379"
7) "runid"
8) ""
9) "flags"
10) "s_down,slave"
11) "link-pending-commands"
12) "14"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "233250"
17) "last-ok-ping-reply"
18) "233250"
19) "last-ping-reply"
20) "233250"
21) "s-down-time"
22) "230233"
23) "down-after-milliseconds"
24) "3000"
25) "info-refresh"
26) "1505553054438"
27) "role-reported"
28) "slave"
29) "role-reported-time"
30) "233250"
31) "master-link-down-time"
32) "0"
33) "master-link-status"
34) "err"
35) "master-host"
36) "?"
37) "master-port"
38) "0"
39) "slave-priority"
40) "100"
41) "slave-repl-offset"
42) "0"
2) 1) "name"
2) "172.16.252.67:6379"
3) "ip"
4) "172.16.252.67"
5) "port"
6) "6379"
7) "runid"
8) "fc91077ac51c954817a85922908320f7f70e2d61"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "374"
19) "last-ping-reply"
20) "374"
21) "down-after-milliseconds"
22) "3000"
23) "info-refresh"
24) "2509"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "233250"
29) "master-link-down-time"
30) "0"
31) "master-link-status"
32) "ok"
33) "master-host"
34) "172.16.252.82"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "186072"
172.16.252.82:26379> SENTINEL failover mymaster 手动切换主节点
OK
172.16.252.82:26379> SENTINEL masters 主节点由172.16.252.82切换到了172.16.252.67
1) 1) "name"
2) "mymaster"
3) "ip"
4) "172.16.252.67"
5) "port"
6) "6379"
7) "runid"
8) "fc91077ac51c954817a85922908320f7f70e2d61"
9) "flags"
10) "master"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "37"
19) "last-ping-reply"
20) "37"
21) "down-after-milliseconds"
22) "3000"
23) "info-refresh"
24) "8118"
25) "role-reported"
26) "master"
27) "role-reported-time"
28) "27140"
29) "config-epoch"
30) "1"
31) "num-slaves"
32) "2"
33) "num-other-sentinels"
34) "2"
35) "quorum"
36) "2"
37) "failover-timeout"
38) "180000"
39) "parallel-syncs"
40) "1"
172.16.252.82:26379> SENTINEL slaves mymaster 显示主节点名称为mymaster的从节点属性信息
1) 1) "name"
2) "172.16.252.184:6379"
3) "ip"
4) "172.16.252.184"
5) "port"
6) "6379"
7) "runid"
8) ""
9) "flags"
10) "s_down,slave"
11) "link-pending-commands"
12) "9"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "138676"
17) "last-ok-ping-reply"
18) "138676"
19) "last-ping-reply"
20) "138676"
21) "s-down-time"
22) "135668"
23) "down-after-milliseconds"
24) "3000"
25) "info-refresh"
26) "1505553462755"
27) "role-reported"
28) "slave"
29) "role-reported-time"
30) "138676"
31) "master-link-down-time"
32) "0"
33) "master-link-status"
34) "err"
35) "master-host"
36) "?"
37) "master-port"
38) "0"
39) "slave-priority"
40) "100"
41) "slave-repl-offset"
42) "0"
2) 1) "name"
2) "172.16.252.82:6379"
3) "ip"
4) "172.16.252.82"
5) "port"
6) "6379"
7) "runid"
8) "2847d8ceda8d3a03f0df814091fc5174921f57ea"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "363"
19) "last-ping-reply"
20) "363"
21) "down-after-milliseconds"
22) "3000"
23) "info-refresh"
24) "65"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "118575"
29) "master-link-down-time"
30) "1505553462000"
31) "master-link-status"
32) "err"
33) "master-host"
34) "172.16.252.67"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "1"
模拟主节点172.16.252.67故障,则主节点完成切换
[root@slave2 ~]# killall redis-server
172.16.252.82:26379> SENTINEL masters 主节点由172.16.252.67切换成了172.16.252.184
1) 1) "name"
2) "mymaster"
3) "ip"
4) "172.16.252.184"
5) "port"
6) "6379"
7) "runid"
8) ""
9) "flags"
10) "s_down,o_down,master"
11) "link-pending-commands"
12) "100"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "9613"
17) "last-ok-ping-reply"
18) "9613"
19) "last-ping-reply"
20) "9613"
21) "s-down-time"
22) "6611"
23) "o-down-time"
24) "5466"
25) "down-after-milliseconds"
26) "3000"
27) "info-refresh"
28) "14593"
29) "role-reported"
30) "master"
31) "role-reported-time"
32) "9613"
33) "config-epoch"
34) "2"
35) "num-slaves"
36) "2"
37) "num-other-sentinels"
38) "2"
39) "quorum"
40) "2"
41) "failover-timeout"
42) "180000"
43) "parallel-syncs"
44) "1"
使故障的172.16.252.67上线
[root@slave2 ~]# systemctl start redis
再次查看mymaster主节点的从节点信息
172.16.252.82:26379> SENTINEL slaves mymaster
1) 1) "name"
2) "172.16.252.67:6379"
3) "ip"
4) "172.16.252.67"
5) "port"
6) "6379"
7) "runid"
8) "a8be66745daee322e5c2a2796a5a07623e6ab25d"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "102"
19) "last-ping-reply"
20) "102"
21) "down-after-milliseconds"
22) "3000"
23) "info-refresh"
24) "785"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "91331"
29) "master-link-down-time"
30) "1505554185000"
31) "master-link-status"
32) "err"
33) "master-host"
34) "172.16.252.184"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "1"
2) 1) "name"
2) "172.16.252.82:6379"
3) "ip"
4) "172.16.252.82"
5) "port"
6) "6379"
7) "runid"
8) "2847d8ceda8d3a03f0df814091fc5174921f57ea"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "913"
19) "last-ping-reply"
20) "913"
21) "down-after-milliseconds"
22) "3000"
23) "info-refresh"
24) "572"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "306685"
29) "master-link-down-time"
30) "1505554185000"
31) "master-link-status"
32) "err"
33) "master-host"
34) "172.16.252.184"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "1"
切换过程注意查看sentinel的日志信息
[root@slave1 ~]# tail /var/log/redis/sentinel.log
Sentinel系统监控Redis主从节点的更多相关文章
- Grafana Prometheus系统监控Redis服务
Grafana Prometheus系统监控Redis服务 一.Grafana Prometheus系统监控Redis服务 1.1流程 1.2安装redis_exporter 1.3配置prometh ...
- (六)Redis主从自动恢复-sentinel
原文地址,转载请注明出处: http://blog.csdn.net/qq_34021712/article/details/72026313 ©王赛超 准备工作:(1个master,2个sl ...
- redis 主从哨兵02
一.为什么要复制 1.实现数据的多副本存储,从而可以实现服务的高可用 2.提供更好的读性能,分担读请求 二.复制技术的关键点及难点 1.如何指定被复制对象 2.增量还是全量,以及如何实现增量 3.复制 ...
- Redis主从&哨兵集群搭建
主从集群 在搭建主从集群前,我们先把Redis安装起来: #解压Redis压缩包 [root@master lf]# tar -zxvf redis-6.2.1.tar.gz -- #安装gcc [r ...
- Redis主从原理及哨兵模式
1.Redis主从搭建 主从的搭建很简单,主节点设置连接密码,从节点的配置上主节点的ip和端口,以及密码,一般从节点我们都设置只读模式. 主节点配置: 主节点密码: requirepass xxx 从 ...
- redis主从+ 哨兵模式(sentinel)+漂移VIP实现高可用系统
原文:https://www.jianshu.com/p/c2ab606b00b7 客户端程序 客户端程序(如PHP程序)连接redis时需要ip和port,但redis-server进行故障转移时, ...
- redis单点、redis主从、redis哨兵sentinel,redis集群cluster配置搭建与使用
目录 redis单点.redis主从.redis哨兵 sentinel,redis集群cluster配置搭建与使用 1 .redis 安装及配置 1.1 redis 单点 1.1.2 在命令窗口操作r ...
- spring集成redis——主从配置以及哨兵监控
Redis主从模式配置: Redis的主从模式配置是非常简单的,首先我们需要有2个可运行的redis环境: master node : 192.168.56.101 8887 slave node: ...
- Redis Sentinel(哨兵)主从高可用方案
环境搭建 三台服务器: 192.168.126.100(master) 192.168.126.110(slaver) 192.168.126.120(slaver) 拷贝192.168.126.10 ...
随机推荐
- 简析平衡树(二)——Treap
前言 学完了替罪羊树,我决定再去学一学\(Treap\).一直听说\(Treap\)很难,我也花了挺久才学会. 简介 \(Treap\)这个名字真的挺有内涵: \(\color{red}{Tree}\ ...
- mongodb索引 全文索引之相似度查询
我们在百度搜索中,可以看到与自己搜索度内容越相关度,排在越前面,这个需求可以在mongodb中很简单度实现,mongodb的全文索引不仅可以返回相匹配的查询结果,而且可以告诉你查询结果与你的查询条件多 ...
- 2017.12.9 Java中的排序---冒泡排序、快速排序、选择排序
//冒泡排序 public class demo{ public static void main(String[] args) { int[] sum={2,9,10,1,5,88}; System ...
- python_66_生成器2
import time def consumer(name): print('%s准备吃包子 '%name) while True: baozi=yield print('包子[%s]来了,被[%s] ...
- matlab一次读取多张图片
实验平台:matlab R2010Rb 读取C:\Users\KCl\Documents\MATLAB\SRCNN\Set5文件夹下所有bmp文件,并存储到im字典中 clear all clc im ...
- JQuery的checkbox全选与全不选操作
最主要是:子选择框要与总选择框的状态一致,即当选择总选择框时,向子选择框添加属性,使用jquery中的attr属性 例: html中的代码 <input type="checkbox& ...
- CentOS 7+ 环境下安装MySQL
在CentOS中默认安装有MariaDB,但是我们需要的是MySQL,安装MySQL可以覆盖MariaDB MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 ...
- JS学习笔记-构造函数篇
创建实例 funtion Fn (){ var num = 10; this.x = 100; this.getX = function(){ cons ...
- js测试密码的强度
测试密码的强度.js //网站也会根据输入密码的字符特点给出相应的提示,如密码过短.强度差.强度中等.强度强等. //这又是怎么实现的呢?看下面代码: <input type="pas ...
- 关于使用Java开发Mis系统
如何使用Java开发一个小型的信息管理系统,首先我们应该知道要使用什么样的方法. 1.Java基础 2.JSP+Servlet+JavaBean JSP是服务器端的编程语言,见得比较多的是在一些网站上 ...