mysql-MHA预发布环境架构分享(五)之keepalived安装

安装keepalive

tar zxf keepalived-1.2.2.tar.gz

cd keepalived-1.2.2

./configure --sysconf=/etc --with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-x86_64

sudo make

sudo make install

sudo cp /usr/local/sbin/keepalived /sbin/keepalived

service keepalived start

service keepalived stop

make时报错如下:

解决方法:

进入源码目录

cd keepalived-1.2.2

vi keepalived/libipvs-2.6/ip_vs.h

找到下面一行:

#include <linux/types.h>        /* For __beXX types in userland */

把他放到如下一行的下面:

#include <sys/types.h>

接下来顺利make了。

-----------编辑keepalived资源配置文件-----------

vim/etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

router_id MYSQL-ha

}

vrrp_script check_running {

script"/etc/keepalived/keepalived_check_mysql.sh"

interval 5

}

vrrp_instance PWRD_1 {

state BACKUP

interface bond0

virtual_router_id 88

priority 150 #[另一台是100]

advert_int 1

nopreempt #[另一台不加]

authentication{

auth_type PASS

auth_pass 99999

}

virtual_ipaddress {

10.142.132.49

}

track_script {

check_running

}

notify_master/etc/keepalived/master.sh

notify_backup/etc/keepalived/slave.sh

notify_fault/etc/keepalived/notify_fault.sh

notify_stop/etc/keepalived/down.sh

}

vikeepalived_check_mysql.sh

#!/bin/bash

MYSQL=/app/mysql/bin/mysql

MYSQL_HOST=localhost

MYSQL_USER=root

MYSQL_PASSWORD=mysql

CHECK_COUNTS=3

#mysql is working MYSQL_OK is 0 , mysql isnot working MYSQL_OK is 1

MYSQL_OK=0

function check_Mysql_Runing (){

$MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p${MYSQL_PASSWORD}-e "show grants;" >/dev/null 2>&1

if [ $? = 0 ] ;then

MYSQL_OK=0

else

MYSQL_OK=1

fi

return $MYSQL_OK

}

while [ $CHECK_COUNTS -ne 0 ]

do

let"CHECK_COUNTS -= 1"

check_Mysql_Runing

if [ $MYSQL_OK= 0 ] ; then

echo "mysql is runing!"

exit 0

fi

if [ $MYSQL_OK-eq 1 ] && [ $CHECK_COUNTS -eq 0 ]

then

echo "mysql is not runing!"

exit 1

fi

sleep 1

done

vim/etc/keepalived/master.sh

#!/bin/bash

echo "#`date +"%Y-%m-%d%H:%M"` change master status!!! " >> /etc/keepalived/change.log

vim/etc/keepalived/slave.sh

#!/bin/bash

echo "#`date +"%Y-%m-%d%H:%M"` change slave status!!!" >> /etc/keepalived/change.log

vim/etc/keepalived/notify_fault.sh

#!/bin/bash

echo "#`date +"%Y-%m-%d%H:%M"` change notify_fault status!!!" >>/etc/keepalived/change.log

sleep 3

echo "#`date +"%Y-%m-%d%H:%M"` try startup mysql!!!" >> /etc/keepalived/change.log

service mysql start

vim/etc/keepalived/down.sh

#!/bin/bash

echo "#`date +"%Y-%m-%d%H:%M"` keepalived is down!!!" >> /etc/keepalived/change.log

chmod +x keepalived_check_mysql.sh

chmod +x /etc/keepalived/master.sh

chmod +x /etc/keepalived/slave.sh

chmod +x /etc/keepalived/notify_fault.sh

chmod +x /etc/keepalived/down.sh

mysql -h10.142.132.49 -ulipengfei-plipengfei

测试

SHOW VARIABLES LIKE ‘server_id‘;【查看当前是哪个mysql主机】

时间: 2024-10-07 20:15:37

mysql-MHA预发布环境架构分享(五)之keepalived安装的相关文章

mysql-MHA预发布环境架构分享(六)之mha安装

MHA由Node和Manager组成,Node运行在每一台MySQL服务器上,也就是说,不管是MySQL主服务器.从服务器.还MHA管理机器,都要安装Node!MHA管理节点模块内部依赖MHA节点模块:MHA管理节点通过ssh连接管理mysql服务器和执行MHA节点脚本. 步骤一.IP划分: 主库:10.142.132.52 [keepalived] 从库1:10.142.132.51  [keepalived 备主] 从库2:10.142.132.47 从库3:10.142.132.48 mh

mysql-MHA预发布环境架构分享(七)之mha缺点之修复

1.修复当AB故障切换一次后,mha-manager会自动退出 [只是基本实现,可以在我的基础上修改] [nohup 后台一直执行] vi /app/masterha/monitor.sh #!/bin/bash while : do mhapid=`ps -ef|grep -v grep|grep masterha_manager |wc -l` echo "mhapid:" $mhapid if [ $mhapid -eq 0 ];then masterha_stop --conf

mysql-MHA预发布环境架构分享(二)之mysql源码安装

安装mysql源码包: (1).安装cmake (mysql5.5以后是通过cmake来编译的) 下载解压cmake-2.8.5.tar.gz tar zxf cmake-2.8.12.2.tar.gz -C /usr/local/src cd /usr/local/src/cmake-2.8.12.2 ./configure --prefix=/usr/local/cmake make && make install export PATH=/usr/local/cmake/bin:$P

mysql-MHA预发布环境架构分享(一)之架构草图、正式图展示

   [草图] 简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于 Facebook公司)开发,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件.在MySQL故障切换过程中,MHA能做到在 0~30秒之内自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一致性,以达到真正意义上的高可用. 该软件由两部分组成:MHA M

mysql-MHA预发布环境架构分享(八)之relay log的清除

(1)设置relay log的清除方式(在每个slave节点上): mysql -e 'set global relay_log_purge=0' 注意: MHA在发生切换的过程中,从库的恢复过程中依赖于relay log的相关信息,所以这里要将relay log的自动清除设置为OFF,采用手动清除relay log的方式.在默认情况下,从服务器上的中继日志会在SQL线程执行完毕后被自动删除.但是在MHA环境中,这些中继日志在恢复其他从服务器时可能会被 用到,因此需要禁用中继日志的自动删除功能.

mysql-MHA预发布环境架构分享(四)之Atlas读写分离

rpm -ivh Atlas-2.2.1.el5.x86_64.rpm   [rpm包直接安装] rpm -ql Atlas [查看安装路径] grep -v '^#' /usr/local/mysql-proxy/conf/test.cnf  |grep -v '^$'  > lipengfei  [过滤垃圾提示符] mv test.cnf test.cnf.old cat lipengfei > test.cnf /usr/local/mysql-proxy/bin/encrypt mys

mysql-MHA预发布环境架构分享(三)之AB复制

[主:10.142.132.52 mysql配置文件] [mysqld] datadir=/app/mysql/data socket =/app/mysql/data/mysql.sock lower_case_table_names=1 character-set-server=utf8 collation-server=utf8_general_ci server_id =1 wait_timeout=360000 log-bin=binlog log-bin-index=binlog.i

理解预发布环境和项目部署流程

题外话: 终于又提笔了.一直都记得博客园,偶尔看到评论,偶尔也会翻看旧的文章.一直没有写是因为这段时间里有些忙碌,学习测试方法分析,自动化编程,发布流程环境管理,测试提效,学习和积累是一个漫长的过程,以及暂时没有找到可以单独成文写出来的内容. 这次文章讲到的内容,是如何从一个测试角度看待发布流程和环境管理这些在功能测试前应该先了解的基础. 一.环境 开发环境: 通常表示最低环境,由代码开发人员直接使用和维护,是代码最超前版本的一个环境. 测试环境: 开发人员确认代码分支在开发环境自测没有问题后,

MySQL MHA高可用环境部署

一,安装MHA基本环境 安装MHA节点 (1)基本环境说明 角色IP地址主机名 ========================================= 主机192.168.1.121节点1 从机192.168.1.122节点2 从机192.168.1.123节点3 监视主机192.168.1.125节点5 (2)在node1,node2,node3,node5中操作: #vi / etc / hosts 192.168.1.121 node1 192.168.1.122 node2