MHA+Lvs+Keepalived实现MySQL的高可用及读负载均衡_3(MHA)

MHA+Lvs+Keepalived实现MySQL的高可用及读负载均衡_3(MHA)

实现MySQL高可用的MHA安装及配置

MHA项目:http://code.google.com/p/mysql-master-ha/wiki/TableOfContents?tm=6

Perl的相关模块下载:http://search.cpan.org/

 

一、安装masterha-node

客户端——4台MySQL服务器、服务端——2台Lvs服务器均需安装masterha-node结点

 

1 安装相关的perl模块

1.1 DBI

[[email protected] xxm 18:26:04]#tar xf DBI-1.633.tar.gz 

[[email protected] xxm 18:26:19]#cd DBI-1.633

[[email protected] DBI-1.633 18:26:22]#perl Makefile.PL

[[email protected] DBI-1.633 18:27:07]#make

[[email protected] DBI-1.633 18:27:42]#make install

[[email protected] xxm 18:32:22]#perl -e "use DBI" ->无返回值,说明正确安装

 

1.2 DBD-mysql

[[email protected] xxm 18:34:53]#tar xf DBD-mysql-4.029.tar.gz 

[[email protected] DBD-mysql-4.029 18:35:10]#perl Makefile.PL

[[email protected] DBD-mysql-4.029 18:35:40]#make

[[email protected] DBD-mysql-4.029 18:35:56]#make install

[[email protected] DBD-mysql-4.029 18:36:15]#perl -e "use DBD::mysql"

 

安装masterha-node

[[email protected] xxm 19:15:04]#tar xf mha4mysql-node-0.56.tar.gz 

[[email protected] xxm 19:15:34]#cd mha4mysql-node-0.56

[[email protected] mha4mysql-node-0.56 19:15:37]#perl Makefile.PL 

[[email protected] mha4mysql-node-0.56 19:16:04]#make

[[email protected] mha4mysql-node-0.56 19:17:18]#make install

 

二、安装masterha-manager

仅在服务端——2Lvs服务器上安装

 

1 安装相关的perl模块

1.1 Config::Tiny

[[email protected] xxm 19:48:57]#gunzip Config-Tiny-2.20.tgz 

[[email protected] xxm 19:49:01]#tar xf Config-Tiny-2.20.tar 

[[email protected] xxm 19:49:05]#cd Config-Tiny-2.20

[[email protected] Config-Tiny-2.20 19:49:48]#perl Makefile.PL

 

1.2 Log::Dispatch

这个模块单独编译安装的话,所需要的依赖包太多,还是使用CPAN方式简易些。使用CPAN方式,需网络正常。下列方式,一路yes即可。

[[email protected] xxm 20:09:36]# perl -MCPAN -e "install Log::Dispatch"

 

1.3 Parallel::ForkManager

[[email protected] xxm 20:58:33]#perl -MCPAN -e "install Parallel::ForkManager"

 

安装masterha-manager

[[email protected] xxm 21:07:56]#tar xf mha4mysql-manager-0.56.tar.gz 

[[email protected] xxm 21:08:15]#cd mha4mysql-manager-0.56

[[email protected] mha4mysql-manager-0.56 21:08:17]#perl Makefile.PL 

[[email protected] mha4mysql-manager-0.56 21:08:21]#make

[[email protected] mha4mysql-manager-0.56 21:08:40]#make install

 

三、配置及测试

1 masterha-manager的配置文件

1.1 在给MHA创建配置文件

cat << EOF >> /etc/app1.cnf

[server default]

#mysql user and password

user=mha_manager

password=123456

port=36677

 

#replication user and password

repl_user=repl

repl_password=123456

 

#ssh user and port

ssh_user=root

ssh_port=2777

 

#binlog directory

master_binlog_dir=/opt/data/log

 

#working directory on the manager

manager_workdir=/var/log/masterha/app1

 

#manager log file

manager_log=/var/log/masterha/app1/app1.log

 

#working directory on MySQL servers

remote_workdir=/var/log/masterha/app1

 

#If MySQL command line utilities are installed under a non-standard directory, use this option to set the directory. 

client_bindir=/usr/local/mysql/bin

 

#If MySQL libraries are installed under a non-standard directory, use this option to set the directory. 

client_libdir=/usr/local/mysql/lib

 

#To check by connecting/disconnecting every time, because it's more strict and it can detect TCP connection level failure more quickly. 

ping_type=CONNECT

 

#To fully control the order of priority (i.e. host2->host3->host4..)

latest_priority=0

 

# IP address failover solution

master_ip_failover_script=/usr/local/scripts/master_ip_failover

 

#Send a report (i.e. e-mail) when failover has completed or ended with errors

report_script=/usr/local/scripts/send_report

 

[server-Master1]

hostname=192.168.15.11

candidate_master=1

 

[server-Master2]

hostname=192.168.15.12

candidate_master=1

 

[server-Slave1]

hostname=192.168.15.13

 

[server-Slave2]

hostname=192.168.15.14

EOF

 

1.2 master_ip_failover脚本

cat  /usr/local/scripts/master_ip_failover

#!/bin/bash

#--------------第一部分:变量及函数定义-----------------#

###Begin Variables define###

ssh_port=2777

cmd=/sbin/ifconfig

vip=192.168.15.31

device=eth0:0

netmk=255.255.255.0

start_vip="${cmd} ${device} ${vip} netmask ${netmk} up"

stop_vip="${cmd} ${device} ${vip} netmask ${netmk} down"

###End Variables define###

 

###Begin Status Funciont###

status()

{

exit 0

}

###End Status Funciont###

 

###Begin Stop Or Stopssh Funciont###

stop()

{

exit 0

}

###End Stop Or Stopssh Funciont###

 

###Begin Start Funciont###

start()

{

/usr/bin/ssh -p ${ssh_port} ${ssh_user}@${orig_master_host} ""${stop_vip}"" 

/usr/bin/ssh -p ${ssh_port} ${ssh_user}@${new_master_host} ""${start_vip}""

/usr/bin/ssh -p ${ssh_port} ${ssh_user}@${new_master_host} "/etc/init.d/lvsrs stop"

exit 0

}

###End Start Funciont###

#--------------第一部分:变量及函数定义-----------------#

 

#--------------第二部分:命令行参数-----------------#

###Begin Get The Command-Line Parameters###

###eval set -- "`getopt -a -q -o n -l command::,ssh_user:,orig_master_host:,orig_master_ip:,orig_master_port:,new_master_host:,new_master_ip:,new_master_port:,new_master_user:,new_master_password: -- "$@"`"

eval set -- "`getopt -a -q -o n -l command::,ssh_user:,orig_master_host:,orig_master_ip:,new_master_host:,new_master_ip: -- "$@"`"

 

if [ $? != 0 ] ; then echo "Terminating..." >&2 ;exit 1;fi

 

while true

do

case "$1" in

--command)

command="${2}";

shift;;

--ssh_user)

ssh_user="${2}";

shift;;

--orig_master_host)

orig_master_host="${2}";

shift;;

--orig_master_ip)

orig_master_ip="${2}";

shift;;

--new_master_host)

new_master_host="${2}";

shift;;

--new_master_ip)

new_master_ip="${2}";

shift;;

--)

shift;

break;;

esac

shift

done

###End Get The Command-Line Parameters###

#--------------第二部分:命令行参数-----------------#

 

#--------------第三部分:函数调用-----------------#

if [ "${command}" == "status" ];

then

status;

fi

if [ "${command}" == "stop" ] || [ "${command}" == "stopssh" ] ;

then

stop;

fi

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值