启动keepalived:/usr/local/sbin/keepalived -D -d -S 0

master ip:192.168.32.6

master:/root/sbin# cat /etc/keepalived/keepalived.conf
global_defs {
router_id MySQL-ha
} vrrp_instance VI_1{
# 在初始化状态下定义为主设备
state BACKUP
# 注意网卡接口
interface eth1
virtual_router_id 71
# 优先级,另一台改为90
priority 100
advert_int 1
# 不主动抢占资源
nopreempt
authentication {
# 认证方式,可以是PASS或AH两种认证方式
auth_type PASS
# 认证密码
auth_pass 1111
} virtual_ipaddress {
# 虚拟IP地址,随着state的变化而增加删除
192.168.32.66
}
} virtual_server 192.168.32.66 3306 {
# 每个2秒检查一次real_server状态
delay_loop 2
# LVS算法
lb_algo wrr
# LVS模式
lb_kind DR
# 会话保持时间
persistence_timeout 60
protocol TCP real_server 192.168.32.6 3306 {
# 权重
weight 3
# 检测到服务down后执行的脚本
notify_down /etc/keepalived/keepalived.sh
TCP_CHECK {
# 连接超时时间
connect_timeout 10
# 重连次数
nb_get_retry 3
# 重连间隔时间
delay_before_retry 3
# 健康检查端口
connect_port 3306
}
}
} slave ip: 192.168.32.116 slave:/root/sbin# cat /etc/keepalived/keepalived.conf
global_defs {
router_id MySQL-ha
} vrrp_instance VI_1{
# 在初始化状态下定义为主设备
state BACKUP
# 注意网卡接口
interface eth1
virtual_router_id 71
# 优先级,另一台改为90
priority 90
advert_int 1
# 不主动抢占资源
nopreempt
authentication {
# 认证方式,可以是PASS或AH两种认证方式
auth_type PASS
# 认证密码
auth_pass 1111
} virtual_ipaddress {
# 虚拟IP地址,随着state的变化而增加删除
192.168.32.66
}
} virtual_server 192.168.32.66 3306 {
# 每个2秒检查一次real_server状态
delay_loop 2
# LVS算法
lb_algo wrr
# LVS模式
lb_kind DR
# 会话保持时间
persistence_timeout 60
protocol TCP real_server 192.168.32.116 3306 {
# 权重
weight 3
# 检测到服务down后执行的脚本
notify_down /etc/keepalived/keepalived.sh
TCP_CHECK {
# 连接超时时间
connect_timeout 10
# 重连次数
nb_get_retry 3
# 重连间隔时间
delay_before_retry 3
# 健康检查端口
connect_port 3306
}
}
} mysql 主从切换; master: test:/root/sbin# ps -ef | grep mysql
root 29199 1 0 22:31 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data01/mysql --pid-file=/data01/mysql/test.pid
mysql 29531 29199 0 22:31 pts/0 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data01/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/mysqld.log --pid-file=/data01/mysql/test.pid --socket=/data01/mysql/mysql.sock
root 29597 27487 0 22:34 pts/0 00:00:00 grep mysql
test:/root/sbin# ps -ef | grep keep
root 29573 1 0 22:31 ? 00:00:00 /usr/local/sbin/keepalived -D -d -S 0
root 29574 29573 0 22:31 ? 00:00:00 /usr/local/sbin/keepalived -D -d -S 0
root 29575 29573 0 22:31 ? 00:00:00 /usr/local/sbin/keepalived -D -d -S 0
root 29599 27487 0 22:34 pts/0 00:00:00 grep keep
test:/root/sbin# ip add | grep inet
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
inet 192.168.32.6/24 brd 192.168.32.255 scope global eth1
inet 192.168.32.66/32 scope global eth1
inet6 8001::20c:29ff:febf:dce8/64 scope global dynamic
inet6 fe80::20c:29ff:febf:dce8/64 scope link slave: slave:/root# ps -ef | grep mysql
root 9083 1 0 22:34 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data01/mysql --pid-file=/var/run/mysqld/mysqld.pid
mysql 9451 9083 4 22:34 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data01/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/data01/mysql/mysql.sock
root 9493 5676 0 22:34 pts/1 00:00:00 grep mysql
slave:/root# ps -ef | grep keep
root 7928 7907 0 22:23 pts/0 00:00:00 tail -f /var/log/keepalived/keepalived.log
root 9485 1 0 22:34 ? 00:00:00 /usr/local/sbin/keepalived -D -d -S 0
root 9486 9485 0 22:34 ? 00:00:00 /usr/local/sbin/keepalived -D -d -S 0
root 9487 9485 0 22:34 ? 00:00:00 /usr/local/sbin/keepalived -D -d -S 0
root 9514 5676 0 22:35 pts/1 00:00:00 grep keep
slave:/root# ip add | grep inet
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
inet 192.168.32.116/24 brd 192.168.32.255 scope global eth1
inet6 8001::20c:29ff:fec2:2682/64 scope global dynamic
inet6 fe80::20c:29ff:fec2:2682/64 scope link master 停掉数据库后:
test:/root/sbin# service mysql stop
Shutting down MySQL... [ OK ]
You have mail in /var/spool/mail/root
test:/root/sbin# ip add | grep inet
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
inet 192.168.32.6/24 brd 192.168.32.255 scope global eth1
inet6 8001::20c:29ff:febf:dce8/64 scope global dynamic
inet6 fe80::20c:29ff:febf:dce8/64 scope link
test:/root/sbin# ps -ef | grep mysql
root 29676 27487 0 22:36 pts/0 00:00:00 grep mysql
test:/root/sbin# ps -ef | grep keep
root 29678 27487 0 22:36 pts/0 00:00:00 grep keep slave上: slave:/root# ip add | grep inet
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
inet 192.168.32.116/24 brd 192.168.32.255 scope global eth1
inet 192.168.32.66/32 scope global eth1
inet6 8001::20c:29ff:fec2:2682/64 scope global dynamic
inet6 fe80::20c:29ff:fec2:2682/64 scope link 此时地址过来了: 当监测到端口down后执行的脚本;
slave:/root/sbin# cat /etc/keepalived/keepalived.sh
. ~/.bash_profile
pkill keepalived
perl /root/sbin/smail.pl keepalived 监测到3306 mysql服务后;
Jul 16 22:02:12 slave Keepalived_healthcheckers[5816]: TCP connection to [192.168.32.116]:3306 success.
Jul 16 22:02:12 slave Keepalived_healthcheckers[5816]: Adding service [192.168.32.116]:3306 to VS [192.168.32.66]:3306
Jul 16 22:02:12 slave Keepalived_healthcheckers[5816]: Gained quorum 1+0=1 <= 3 for VS [192.168.32.66]:3306 关闭Mysql: Jul 16 22:03:00 slave Keepalived_healthcheckers[5816]: TCP connection to [192.168.32.116]:3306 failed !!!
Jul 16 22:03:00 slave Keepalived_healthcheckers[5816]: Removing service [192.168.32.116]:3306 from VS [192.168.32.66]:3306
Jul 16 22:03:00 slave Keepalived_healthcheckers[5816]: Executing [/etc/keepalived/keepalived.sh] for service [192.168.32.116]:3306 in VS [192.168.32.66]:3306
Jul 16 22:03:00 slave Keepalived_healthcheckers[5816]: Lost quorum 1-0=1 > 0 for VS [192.168.32.66]:3306

keepalived 结合mysql 自动切换的更多相关文章

  1. Redis主从配置及通过Keepalived实现Redis自动切换高可用

    Redis主从配置及通过Keepalived实现Redis自动切换高可用 [日期:2014-07-23] 来源:Linux社区  作者:fuquanjun [字体:大 中 小]   一:环境介绍: M ...

  2. 使用keepalived实现mysql主从复制的自动切换

    最近测试了一下mysql+keepalived实现主从自动切换,主从都需要安装keepalived,使用vip漂移实现主从自动切换,这里主要记录的是keepalived的文件配置. 这里mysql搭建 ...

  3. 【转】双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计

    架构简介 前几天网友来信说帮忙实现这样一个架构:只有两台机器,需要实现其中一台死机之后另一台能接管这台机器的服务,并且在两台机器正常服务时,两台机器都能用上.于是设计了如下的架构.此架构主要是由kee ...

  4. 0120Keeplived实现自动切换Mysql服务

    转自http://biancheng.dnbcw.info/mysql/381020.html Keepalived+mysql 自动切换网络结构:VIP 192.168.88.200mysq11 1 ...

  5. 基于keepalived搭建MySQL的高可用集群

    MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,MMM,Heartbeat+DRBD,PXC,Galera Cluster 比较常用的是keepalived+双主,MHA和 ...

  6. 基于keepalived搭建MySQL高可用集群

    MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,MMM,Heartbeat+DRBD,PXC,Galera Cluster 比较常用的是keepalived+双主,MHA和 ...

  7. (转)基于keepalived搭建MySQL的高可用集群

    基于keepalived搭建MySQL的高可用集群  原文:http://www.cnblogs.com/ivictor/p/5522383.html MySQL的高可用方案一般有如下几种: keep ...

  8. mysql主从备份+keepalived自动切换

    数据库这一层需要做到避免单点故障可以是主从备份和主主备份,主主备份可能有性能损耗和数据同步的问题.这里记录下主从备份, mysql进行备份之前确保mysql的版本是一样的,我这里用的都是mysql5. ...

  9. Keepalived与MySQL互为主从自动切换配置

    为解决Mysql数据库单点问题,实现两台MySQL数据库互为主备,双向replication.当一Master出现问题,则将Slave切换为Master继续工作. 环境说明 系统版本:CentOS L ...

随机推荐

  1. Oracle存储过程Procedure语法及案例

    create or replace procedure replace(desstr in varchar2, replacestr in varchar2, tablename in varchar ...

  2. 基本属性 - iOS中的本地通知

    本地通知的基本使用 创建本地通知 设置属性 调度通知(添加通知到本地通知调度池) 注册用户通知权限(只需一次, 可以单独放在Appdelegate中, 或者别的地方) —> iOS8以后必须, ...

  3. (" use strict")Javascript 严格模式详解

    Javascript 严格模式详解 转载别人的博客内容,浏览了一遍,没有全部吸收,先保存一下链接 http://www.ruanyifeng.com/blog/2013/01/javascript_s ...

  4. mbed 初试(LinkNode 板卡)(2016-04-21)

    前言 感谢论坛,感谢 LinkSrite,论坛活动申请了一个 LinkNode,体验了一下 mbed. 翻看完官方 wiki,大概了解了一下 mbed 的开发,然后做了 blink 和 pwm 的测试 ...

  5. 我常用的iphone开发学习网站[原创]

    引用地址:http://www.cnblogs.com/fuleying/archive/2011/08/13/2137032.html Google 翻译 Box2d 托德的Box2D的教程! Bo ...

  6. 杭电oj An easy problem

    </pre><h1 style="color: rgb(26, 92, 200);">An easy problem</h1><stron ...

  7. Android 开发笔记 “Android 的消息队列模型”

    Android是参考Windows的消息循环机制来实现Android自身的消息循环的. Android通过Looper.Handler来实现消息循环机制,Android消息循环是针对线程的(每个线程都 ...

  8. Lake Counting(poj 2386)

    题目描述: Description Due to recent rains, water has pooled in various places in Farmer John's field, wh ...

  9. jquery 几点注意事项

    jquery触发hover事件 使用 mouseenter/mouseleave/mouseover/mouseout

  10. 隐藏APK在Launcher中的启动图标 android开发教程

    隐藏APK在Launcher中的启动图标: APK的AndroidManifest.xml文件的主Activity中删除 intent-filter 中的 <category android:n ...