基于keepalived对redis做高可用配置---转载
关于keepalived的详细介绍,请移步本人相关博客:http://wangfeng7399.blog.51cto.com/3518031/1405785
功能 | ip地址 | 安装软件 |
主redis | 10.13.6.13 | redis,keepalived |
从redis | 10.13.6.16 | redis,keepalived |
VIP | 10.13.6.17 |
一、redis主从搭建
1.redis安装
本文通过yum源的安装方式来安装(需要配置epel源),也可以通过源码编译的方式来安装
1
2
|
[root@P2Pp_Red01 ~] # yum install -y redis [root@P2Pp_Red02 ~] # yum install -y redis |
2.修改配置文件
①、主redis需要修改的文件及内容
1
2
3
|
[root@P2Pp_Red01 ~] # vi /etc/redis.conf bind 0.0.0.0 其余都可以安装默认状态 |
②、从redis需要修改的文件及内容
1
2
3
|
[root@P2Pp_Red02 ~] # vi /etc/redis.conf bind 0.0.0.0 slaveof 10.13.6.13 6379 // 指定主redis的地址与端口 |
3.查看主从状态
1
2
3
4
5
6
7
8
9
|
[root@P2Pp_Red01 ~] # redis-cli INFO |grep role -A 3 role:master slave0:10.13.6.16,45270,online db0:keys=6,expires=0 [root@P2Pp_Red02 ~] # redis-cli INFO |grep role -A 3 role:slave master_host:10.13.6.13 master_port:6379 master_link_status:up |
二、使用keepalived对redis做高可用
1.安装keepalived,两台机器都需要安装
1
2
|
[root@P2Pp_Red01 ~] # yum install -y keepalived [root@P2Pp_Red02 ~] # yum install -y keepalived |
2.准备配置文件
①、主redis的配置文件,关于各行代表的意思,请移步我的另外一篇文档,链接见文章开头
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
[root@P2Pp_Red01 scripts] # vi /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 10.13.4.17 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_redis { script "killall -0 redis-server" interval 2 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 100 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.13.6.17 } track_script { chk_redis } notify_master /etc/keepalived/scripts/redis_master .sh notify_backup /etc/keepalived/scripts/redis_backup .sh notify_fault /etc/keepalived/scripts/redis_fault .sh notify_stop /etc/keepalived/scripts/redis_stop .sh } ~[root@P2Pp_Red01 ~] # vi /etc/keepalived/scripts/redis_master.sh #!/bin/bash REDISCLI= "/usr/bin/redis-cli" LOGFILE= "/var/log/keepalived-redis-state.log" echo "[master]" >> $LOGFILE date >> $LOGFILE echo "Being master...." >> $LOGFILE 2>&1 echo "Run SLAVEOF cmd ..." >> $LOGFILE $REDISCLI SLAVEOF 10.13.4.13 6379 >> $LOGFILE 2>&1 sleep 10 #延迟10秒以后待数据同步完成后再取消同步状态 echo "Run SLAVEOF NO ONE cmd ..." >> $LOGFILE $REDISCLI SLAVEOF NO ONE >> $LOGFILE 2>&1 ~ [root@P2Pp_Red01 ~] # vi /etc/keepalived/scripts/redis_backup.sh #!/bin/bash REDISCLI= "/usr/bin/redis-cli" LOGFILE= "/var/log/keepalived-redis-state.log" echo "[backup]" >> $LOGFILE date >> $LOGFILE echo "Being slave...." >> $LOGFILE 2>&1 sleep 15 #延迟15秒待数据被对方同步完成之后再切换主从角色 echo "Run SLAVEOF cmd ..." >> $LOGFILE $REDISCLI SLAVEOF 10.13.4.13 6379 >> $LOGFILE 2>&1 [root@P2Pp_Red01 scripts] # vi /etc/keepalived/scripts/redis_stop.sh #!/bin/bash LOGFILE= /var/log/keepalived-redis-state .log echo "[stop]" >> $LOGFILE date >> $LOGFILE [root@P2Pp_Red01 scripts] # vi /etc/keepalived/scripts/redis_fault.sh #!/bin/bash GFILE= /var/log/keepalived-redis-state .log echo "[fault]" >> $LOGFILE date >> $LOGFILE ~ |
②、准备从redis的配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
[root@P2Pp_Red02 ~] # vi /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 10.13.4.13 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_redis { script "killall -0 redis-server" interval 1 } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 100 priority 99 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.13.6.17 } #track_script { # chk_redis #} # notify_master /etc/keepalived/scripts/redis_master.sh # notify_backup /etc/keepalived/scripts/redis_backup.sh # notify_fault /etc/keepalived/scripts/redis_fault.sh # notify_stop /etc/keepalived/scripts/redis_stop.sh [root@P2Pp_Red02 ~] # vi /etc/keepalived/scripts/redis_master.sh #!/bin/bash REDISCLI= "/usr/bin/redis-cli" LOGFILE= "/var/log/keepalived-redis-state.log" echo "[master]" >> $LOGFILE date >> $LOGFILE echo "Being master...." >> $LOGFILE 2>&1 echo "Run SLAVEOF cmd ..." >> $LOGFILE $REDISCLI SLAVEOF 10.13.6.13 6379 >> $LOGFILE 2>&1 sleep 10 #延迟10秒以后待数据同步完成后再取消同步状态 echo "Run SLAVEOF NO ONE cmd ..." >> $LOGFILE $REDISCLI SLAVEOF NO ONE >> $LOGFILE 2>&1 ~ [root@P2Pp_Red02 ~] # vi /etc/keepalived/scripts/redis_backup.sh #!/bin/bash REDISCLI= "/usr/bin/redis-cli" LOGFILE= "/var/log/keepalived-redis-state.log" echo "[backup]" >> $LOGFILE date >> $LOGFILE echo "Being slave.... sleep 15 #延迟15秒待数据被对方同步完成之后再切换主从角色 echo "Run SLAVEOF cmd ..." >> $LOGFILE $REDISCLI SLAVEOF 10.13.6.13 6379 >> $LOGFILE 2>&1 其余的两个文件跟主redis是一样的 |
本处将不再给模拟故障,但是测试时通过的,现在已经在生产环境中使用
本文出自 “IT民工--小枫” 博客,请务必保留此出处http://wangfeng7399.blog.51cto.com/3518031/1591275
基于keepalived对redis做高可用配置---转载的更多相关文章
- (转)基于keepalived搭建MySQL的高可用集群
基于keepalived搭建MySQL的高可用集群 原文:http://www.cnblogs.com/ivictor/p/5522383.html MySQL的高可用方案一般有如下几种: keep ...
- 基于keepalived搭建MySQL的高可用集群
MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,MMM,Heartbeat+DRBD,PXC,Galera Cluster 比较常用的是keepalived+双主,MHA和 ...
- Nginx+keepalived实现负载均衡高可用配置
1. 什么是负载均衡高可用 nginx作为负载均衡器,所有请求都到了nginx,可见nginx处于非常重点的位置,如果nginx服务器宕机后端web服务将无法提供服务,影响严重. 为了屏蔽负载均衡服务 ...
- nginx+keepalived互为主主高可用配置
和nginx主从安装配置都一样 就是配置文件 多加个vip 里面具体要改的 请看下面的配置文件 直接master1上keepalived.conf配置文件内容: ! Configuration ...
- Redis Sentinel高可用配置及C#访问
本文环境如下: 操作系统:ubuntu-14.04.1-desktop-amd64 Redis:2.8.19 如果使用虚拟机则将每台的网络设置为桥接,否则他们之间能连上,局域网连不上. 系统设计如图: ...
- MySQL基于域名做高可用切换(Consul初试)
一,Consul功能介绍 服务发现 - Consul的客户端可用提供一个服务,比如 api 或者mysql ,另外一些客户端可用使用Consul去发现一个指定服务的提供者.通过DNS或者HTTP应用程 ...
- Keepalived+Nginx搭建主从高可用并带nginx检测
应用环境:部分时候,WEB访问量一般,或者测试使用,利用Keepalived给Nginx做高可用即可满足要求. 测试环境: 搭建步骤: 1. 安装软件 在Nginx-A和Nginx-B上: ~]# ...
- MariaDB+Keepalived双主高可用配置MySQL-HA
利用keepalived构建高可用MySQL-HA,保证两台MySQL数据的一致性,然后用keepalived实现虚拟VIP,通过keepalived自带的服务监控功能来实现MySQL故障时自动切换. ...
- lvs+keepalived做高可用方案1
本文我们主要讲解的是LVS通过keepalived来实现负载均衡和高可用,而不是我们第三篇文章介绍的通过手动的方式来进行配置.通过脚本的方式来显示RS节点的健康检查和LVS的故障切换.此文会通过一个实 ...
随机推荐
- Server-Side Access Control
Firefox 3.5 implements the W3C Access Control specification. As a result, Firefox 3.5 sends specifi ...
- OpenIOC
http://wenku.it168.com/d_926300.shtml OpenIOC http://safe.it168.com/a2015/1208/1790/000001790446.sht ...
- Json 返回日期格式转换
//日期转换 function ChangeDateFormat(time) { if (time != null) { var date = new Date(parseInt(time.repla ...
- 视频硬解api介绍
在一个gpu如此强大的时代,视频解码怎么能少了gpu厂商的参加.为了用硬件加速视频解码,厂商定义了一些api. 好吧,一旦和硬件打交道,就会有os的参加,有了硬件与os参加,api肯定会变成很凌乱,看 ...
- RTSP
相关博客: RTSP 很详细的英文文档 RTSP交互命令简介及过程参数描述 RTSP协议 http://blog.csdn.net/andyweike/article/details/621071 ...
- 在Azure中使用Load Runner测试TCP最大并发连接数
对于Azure中的每一台虚机,它所能支持的TCP最大并发连接数是50万(参考微软官网: http://azure.microsoft.com/en-us/documentation/articles/ ...
- poj 2586 Y2K Accounting Bug
http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...
- HDU-1716 排列2 (DFS)
排列2 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- lfs遇到的一些问题--后续阶段
1.安装GPM-1.20.7,make install出错: prog/display-buttons.c:39:57: 致命错误:gpm.h:没有那个文件或目录 #include <gpm.h ...
- win8下在microsoft visual studio 2012利用ODP.NET连接ORACLE 12c
老板要求我搭个ASP.NET框架,并且连接上ORACLE数据库,听起来好像挺简单的,但就是连第一步连接ORACLE我都搞了两天╮(╯▽╰)╭ 首先,项目书上要求用ORACLE 10G,可我自己的本本装 ...