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 ...
随机推荐
- tableviewcell折叠问题,(类似qq列表展开形式) 多个cell同时展开,OC版 和 Swift
之前没有用到过这块,但是今天看到,就试了试,但是发现,网上的有的方法不能多个cell同时展开,只能一个一个的展开. 我就尝试用用数组记录展开的标记的方法,功能实现了, 直接上代码: // // Vie ...
- MFC-[转]基于MFC的ActiveX控件开发
作者:lidan | 出处:博客园 | 2012/3/13 16:10:34 | 阅读22次 ActiveX 控件是基于组件对象模型 (COM) 的可重用软件组件,广泛应用于桌面及Web应用中.在VC ...
- 关于HTML(含HTML5)的块级元素和行级(内联)元素总结
1.首先我们要知道什么是块级元素和行级(内联)元素? 块级(block)元素的特点: ①总是在新行上开始: ②高度,行高以及外边距和内边距都可控制: ③宽度缺省是它的容器的100%,除非设定一个宽度: ...
- ios swift 里面关于变量 常量 可选类型 控制流的一些心得
//swift 里面没有头文件和实现文件.只有一个.swift文件 //swift 里面没有main的概念,程序从main.swift开始执行 //swift 每一条执行语句可以不用分号结束,多条语句 ...
- PAT 乙级 1017
题目 题目地址:PAT 乙级 1017 题解 粗看是一道大数除法题,实际上只不过是通过字符数组模拟除法过程,理解之后还是比较简单的: 具体分析一下本题: 因为题设中的除数(n)是一位整数,因此大幅简化 ...
- yum 安装percona mysql 5.7
Mysql5.7安装准备 1.基础信息: (1)可参考官方文档[https://www.percona.com/doc/percona-server/5.7/installation/yum_repo ...
- hive数据的导入导出方式
导入方式 1.load方式 load data local inpath 'local_path' into table tb_name; 从本地复制了文件到表的路径下 应用场景:大部分的使用,文件几 ...
- Louis Armstrong【路易斯·阿姆斯特朗】
Louis Armstrong Louis Armstrong had two famous nicknames. 路易斯·阿姆斯特朗有两个著名的绰号. Some people called him ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- 《鸟哥的Linux私房菜》学习笔记(5)——权限管理
一.权限的基本概念 权限:访问计算机资源或服务的访问能力. Linux中,每一个资源或者服务的权限, ...