ITPub博客

首页 > Linux操作系统 > Linux操作系统 > mysql HA 方案(2):MHA

mysql HA 方案(2):MHA

原创 Linux操作系统 作者:aaqwsh 时间:2012-04-16 16:00:21 0 删除 编辑

以下摘录自(http://code.google.com/p/mysql-master-ha/wiki/Overview

MHA performs automating master failover and slave promotion with minimal downtime, usually within 10-30 seconds. MHA prevents replication consistency problems and saves on expenses of having to acquire additional servers. All this with zero performance degradation, no complexity (easy-to-install) and requiring no change to existing deployments.

MHA also provides scheduled online master switching, safely changing the currently running master to a new master, within mere seconds (0.5-2 seconds) of downtime (blocking writes only).

MHA provides the following functionality, and can be useful in many deployments in which high availability, data integrity and near non-stop master maintenance are required.

。。。。。。。。。。

 

应用要考虑的问题:
应用架构要考虑两个问题(在一个特定的集群下):
1
自动识别masterslave的问题(master机器可能会切换)
2
负载均衡的问题(我们可以定义大概的读写比例,每台机器可承担的负载比例,当有机器离开集群时,需要考虑这个)

比如说下面的场景:
From:
db-181 (current master)
+–db-183
+–db-184

To:
db-183 (new master)
+–db-184

这个方案需要机器至少4台(1 master+ 3 slaves(其中一个专门作为备份))。

以下是我的测试过程:

准备,机器安排,db-182为管理机:

db-181 (current master)

 +--db-183

 +--db-184

 

准备工作,配置ssh:

mkdir ~/.ssh

 chmod 700 ~/.ssh

 ssh-keygen -t rsa

 ssh-keygen -t dsa

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

 

ssh db-181 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

ssh db-181 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

ssh db-183 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

ssh db-183 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

ssh db-184 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

ssh db-184 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

 

scp ~/.ssh/authorized_keys db-181:~/.ssh/authorized_keys

scp ~/.ssh/authorized_keys db-183:~/.ssh/authorized_keys

scp ~/.ssh/authorized_keys db-184:~/.ssh/authorized_keys

 

1 所有机器安装DBD-mysql-4.020

 

mkdir /tmp/mysql-static  

cp /usr/lib64/mysql/*.a /tmp/mysql-static  

perl Makefile.PL --libs="-L/tmp/mysql-static -lmysqlclient"  

make  

make test  

make install  

 

2  所有机器Installing MHA Node

 

You can also install MHA Node from source. 

## Install DBD::mysql if not installed  

 

tar -zxf mha4mysql-node-0.53.tar.gz

cd mha4mysql-node-0.53

perl Makefile.PL

make

make install

 

3 管理机Installing MHA Manager

## Install DBD::mysql if not installed  

rpm -ivh perl-Config-Tiny-2.12-1.el5.rf.noarch.rpm

rpm -ivh perl-Params-Validate-0.95-1.el5.rf.x86_64.rpm

rpm -ivh  perl-Log-Dispatch-2.26-1.el5.rf.noarch.rpm

rpm -ivh perl-Parallel-ForkManager-0.7.5-2.2.el5.rf.noarch.rpm

 

tar -zxf mha4mysql-manager-0.53.tar.gz

cd mha4mysql-manager-0.53

perl Makefile.PL

make

make install

 

 

4 配置文件

[server default]

manager_workdir=/masterha/app1

manager_log=/masterha/app1/manager.log

user=root

password=123zzz

ssh_user=root

repl_user=rep

repl_password=123zzz

ping_interval=1

 

[server1]

hostname=db-181

master_binlog_dir=/data/mysql

candidate_master=1

[server2]

hostname=db-183

master_binlog_dir=/data/mysql

candidate_master=1

[server3]

hostname=db-184

master_binlog_dir=/data/mysql

 

5 root 的权限及MASTER_HOSTvip待试验)

 

CHANGE MASTER TO

 MASTER_HOST='192.168.99.181',

 MASTER_USER='rep',

MASTER_PASSWORD='xxx',

 MASTER_LOG_FILE='mysql-bin.000004',

 MASTER_LOG_POS=107;

 

db-181
mysql> grant all privileges on *.* to 'root'@'db-182' identified by 'xxx';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'db-181' identified by 'xxx'; 
Query OK, 0 rows affected (0.00 sec)

mysql>  grant all privileges on *.* to 'root'@'192.168.99.182' identified by 'xxx';
Query OK, 0 rows affected (0.00 sec)


db-183
mysql>  grant all privileges on *.* to 'root'@'192.168.99.182' identified by 'xxx';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'db-182' identified by 'xxx';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'db-183' identified by 'xxx'; 
Query OK, 0 rows affected (0.01 sec)

db-184
mysql>  grant all privileges on *.* to 'root'@'192.168.99.182' identified by 'xxx';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'db-182' identified by 'xxx';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'db-184' identified by 'xxx'; 
Query OK, 0 rows affected (0.00 sec)
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/758322/viewspace-721331/,如需转载,请注明出处,否则将追究法律责任。

上一篇: mysql HA 方案(1)
请登录后发表评论 登录
全部评论

注册时间:2010-11-24

  • 博文量
    132
  • 访问量
    258069