mha安装部署

mha概念:http://blog.csdn.net/aoerqileng/article/details/51800212
假设4台机器,master 在host1, slave在host2,host3,mha manager在host4
1部署主从结构
2安装mha node
mha node有些脚本和独立的perl模块,主要是做下面的事情:

  1. save_binary_logs,保存和拷贝死去的master的二进制日志
  2. apply_diff_relay_logs:标识relay log事件的增量,应用所有必要的log事件
  3. purge_relay_logs:清除relay log文件
    需要在所有的mysql服务器上安装node,在manager上也需要安装node,安装
    yum install perl-DBD-MySQL
    rpm -ivh mha4mysql-node-X.Y-0.noarch.rpm
    在源码中安装node
    ## Install DBD::mysql if not installed
    tarzxfmha4mysqlnodeX.Y.tar.gz perl Makefile.PL
    make sudo make install
    安装mha manager
  ## Install dependent Perl modules
  # yum install perl-DBD-MySQL
  # yum install perl-Config-Tiny
  # yum install perl-Log-Dispatch
  # yum install perl-Parallel-ForkManager

## Install MHA Node, since MHA Manager uses some modules provided by MHA Node.
# rpm -ivh mha4mysql-node-X.Y-0.noarch.rpm

## Finally you can install MHA Manager
# rpm -ivh mha4mysql-manager-X.Y-0.noarch.rpm
3创建配置文件
cat /etc/app1.cnf

[server default]
# mysql user and password
user=root
password=mysqlpass
ssh_user=root
# working directory on the manager
manager_workdir=/var/log/masterha/app1
# working directory on MySQL servers
remote_workdir=/var/log/masterha/app1

[server1]
hostname=host1

[server2]
hostname=host2

[server3]
hostname=host3
检查ssh连通性
masterha_check_ssh –conf=/etc/app1.cnf
检查复制配置
masterha_check_repl –conf=/etc/app1.cnf
启动manager
masterha_manager –conf=/etc/app1.cnf
默认是前端运行的
检查manager状态
检查manager状态
masterha_check_status –conf=/etc/app1.cnf
停止manager
masterha_stop –conf=/etc/app1.cnf
测试master故障转移
killall -9 mysqld mysqld_safe
在故障转移完毕后,mha的manager会停止,如果想要永久运行manager,使用运行在后台的方式运行manager
nohup masterha_manager –conf=/etc/app1.cnf < /dev/null > /var/log/masterha/app1/app1.log 2>&1 &
用daemontools以守护进程的方式运行
yum install daemontools
mkdir /service/masterha_app1
cat /service/masterha_app1/run
#!/bin/sh
exec masterha_manager –conf=/etc/app1.cnf –wait_on_monitor_error=60 –wait_on_failover_error=60 >> /var/log/masterha/app1/app1.log 2>&1
chmod 755 /service/masterha_app1/run
使用daemontools启动关闭
## stopping monitoring
manager_host# svc -d /service/masterha_app1

## starting monitoring
manager_host# svc -u /service/masterha_app1

如果想要在mha中管理很多的master-slave结构,配置一个全局的配置文件,在对每个复制环境创建单独的应用配置文件
全局配置文件可以放在任何位置,默认情况是/etc/masterha_default.cnf,放在别的位置的时候,需要在使用命令的时候,通过–global_conf参数指定全局配置文件的位置
全局配置文件:/etc/masterha_default.cnf
[server default]
user=root
password=rootpass
ssh_user=root
master_binlog_dir= /var/lib/mysql
remote_workdir=/data/log/masterha
secondary_check_script= masterha_secondary_check -s remote_host1 -s remote_host2
ping_interval=3
master_ip_failover_script=/script/masterha/master_ip_failover
shutdown_script= /script/masterha/power_manager
report_script= /script/masterha/send_master_failover_mail
应用1
cat /etc/app1.cnf

[server default]
manager_workdir=/var/log/masterha/app1
manager_log=/var/log/masterha/app1/app1.log

[server1]
hostname=host1
candidate_master=1

[server2]
hostname=host2
candidate_master=1

[server3]
hostname=host3

[server4]
hostname=host4
no_master=1
应用2
cat /etc/app2.cnf

[server default]
manager_workdir=/var/log/masterha/app2
manager_log=/var/log/masterha/app2/app2.log

[server1]
hostname=host11
candidate_master=1

[server2]
hostname=host12
candidate_master=1

[server3]
hostname=host13

[server4]
hostname=host14
no_master=1
启动manager
# masterha_manager –conf=/etc/conf/masterha/app1.cnf
# masterha_manager –conf=/etc/conf/masterha/app2.cnf
对于多master及三层复制的注意问题,参考:
https://code.google.com/p/mysql-master-ha/wiki/Requirements
https://code.google.com/p/mysql-master-ha/wiki/UseCases#Three_tier_replication
定时清理relay_log
cat /etc/cron.d/purge_relay_logs
# purge relay logs at 5am
0 5 * * * app /usr/bin/purge_relay_logs –user=root –password=PASSWORD –disable_relay_log_purge >> /var/log/masterha/purge_relay_logs.log 2>&1

你可能感兴趣的:(MYSQL)