MHA配置

规划实施

主机名      系统版本        物理IP      集群角色         MySQL版本                server_id

manager     CentOS 6.5    10.10.38.201  MHM管理端  5.6.24-72.2-log Percona Server   无

rac2         同上         10.10.38.40  主master可读、可写   同上                    10

rac3         同上         10.10.38.221 备Master可读、可写   同上                    20

rac4         同上         10.10.38.196 Slave节点     可读   同上                    30

rac5         同上         10.10.38.197 Slave节点     可读   同上                    40

MHM双主双从应用架构对应的读、写分离IP列表

虚拟IP              IP角色            功能描述

192.168.12.231    Writer Reader IP    应用程序配置中的写入VIP,仅支持单点写入

 

SSH配置

vim /etc/ssh/sshd_config 

开启

Port 22

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile      .ssh/authorized_keys

service sshd restart  重启服务


/etc/hosts文件  --所有主机添加

10.10.38.40  rac2

10.10.38.221 rac3

10.10.38.196 rac4

10.10.38.197 rac5

10.10.38.201 manager


ssh-keygen  -t dsa   --所有主机执行

下面只在40主机执行即可。

cd .ssh

cat id_dsa.pub  > authorized_keys

scp 10.10.38.40:/root/.ssh/id_dsa.pub 40

scp 10.10.38.221:/root/.ssh/id_dsa.pub 221

scp 10.10.38.196:/root/.ssh/id_dsa.pub 196

scp 10.10.38.197:/root/.ssh/id_dsa.pub 197

scp 10.10.38.201:/root/.ssh/id_dsa.pub 201

cat 40 221 196 197 201 >> authorized_keys 

scp authorized_keys 10.10.38.40:/root/.ssh/ 

scp authorized_keys 10.10.38.221:/root/.ssh/

scp authorized_keys 10.10.38.196:/root/.ssh/

scp authorized_keys 10.10.38.197:/root/.ssh/

scp authorized_keys 10.10.38.201:/root/.ssh/

所有主机执行

ssh rac2 date

ssh rac3 date

ssh rac4 date

ssh rac4 date

ssh manager date



1. MHM套件的安装

 

yum -y install perl iproute perl-Algorithm-Diff perl-DBI perl-Class-Singleton perl-DBD-MySQL perl-Log-Log4perl perl-Log-Dispatch perl-Proc-Daemon perl-MailTools perl-Time-HiRes perl-Mail-Sendmail perl-Mail-Sender perl-Email-Date-Format perl-MIME-Lite perl-Net-Ping

201主机

# tar xvf mha4mysql-manager-0.56.tar.gz  -C /usr/local/

# cd /usr/local/mha4mysql-manager-0.56/

# perl Makefile.PL 

*** Module::AutoInstall version 1.03

*** Checking for Perl dependencies...

[Core Features]

- DBI                   ...loaded. (1.609)

- DBD::mysql            ...loaded. (4.013)

- Time::HiRes           ...loaded. (1.9721)

- Config::Tiny          ...loaded. (2.12)

- Log::Dispatch         ...loaded. (2.26)

- Parallel::ForkManager ...loaded. (0.7.9)

- MHA::NodeConst        ...loaded. (0.56)

*** Module::AutoInstall configuration finished.

Checking if your kit is complete...

Looks good

Writing Makefile for mha4mysql::manager

 

# echo $?

0

# make

# make install

Appending installation info to /usr/lib64/perl5/perllocal.pod

 

# echo $?

0

 

40/221/196/197主机:在各数据节点安装mha node

# tar xvf mha4mysql-node-0.56.tar.gz 

# cd mha4mysql-node-0.56

# perl Makefile.PL

*** Module::AutoInstall version 1.03

*** Checking for Perl dependencies...

[Core Features]

- DBI        ...loaded. (1.609)

- DBD::mysql ...loaded. (4.013)

*** Module::AutoInstall configuration finished.

Writing Makefile for mha4mysql::node

 

# echo $?

0

# make

# make install

Appending installation info to /usr/lib64/perl5/perllocal.pod

# echo $?

(1)  

创建OS用户:设置密码

useradd -u 556 -g mysql -G mysql,users -d /home/ mysusr01 -m mysusr01

passwd mysusr01

端口统一为 39326

(2) 创建mysql需要用到的账号

A. 同步账号

在所有节点创建相同的用户

mysql> use mysql; 

mysql> desc user; 

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456"; 

mysql> update mysql.user set Password = password('123456') where User='root'; 

mysql> select Host,User,Password    from mysql.user where User='root'; 

mysql> flush privileges; 

grant all privileges on *.* to root1@'10.10.38.%' identified by 'system';

grant all privileges on *.* to root1@'%' identified by 'system';

grant all privileges on *.* to root1@'localhost' identified by 'system';

 

grant replication slave,replication client on *.* to repl_user@'10.10.38.%' identified by 'repl_user1';

grant replication slave,replication client on *.* to repl_user@'%' identified by 'repl_user1';

grant replication slave,replication client on *.* to repl_user@'localhost' identified by 'repl_user1';

 

grant all privileges on *.* to root@'10.10.38.%' identified by '123456';

grant all privileges on *.* to root@'%' identified by '123456';

flush privileges;

(3) 配置主从同步

40和221互为双主

在40上 show master status;

在221/196/197

change master to master_host='10.10.38.40',master_port=39326,master_user='repl_user',master_password='repl_user1',master_log_file='mysql-bin-rac2-39326.000004',master_log_pos=2018;

> start slave;

在221上 show master status;

     在40上执行:

> change master to master_host='10.10.38.221',master_port=39326,master_user='repl_user',master_password='repl_user1',master_log_file='mysql-bin-rac3-39326.000004',master_log_pos=2018;

说明:其中两个slave指向10.10.38.40主节点同步。

(4) 半同步设置

# 所有mysql数据库服务器,安装半同步插件(semisync_master.so,semisync_slave.so)  

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';      

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';

添加参数

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000

rpl_semi_sync_slave_enabled=1

 

mysql> show variables like '%sync%';  

# 查看半同步状态:  

mysql> show status like '%sync%';  

# 有几个状态参数值得关注的:  

rpl_semi_sync_master_status:显示主服务是异步复制模式还是半同步复制模式  

rpl_semi_sync_master_clients:显示有多少个从服务器配置为半同步复制模式  

rpl_semi_sync_master_yes_tx:显示从服务器确认成功提交的数量  

rpl_semi_sync_master_no_tx:显示从服务器确认不成功提交的数量  

rpl_semi_sync_master_tx_avg_wait_time:事务因开启semi_sync,平均需要额外等待的时间  

rpl_semi_sync_master_net_avg_wait_time:事务进入等待队列后,到网络平均等待时间  

 

(5) 参数添加

40添加

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000

rpl_semi_sync_slave_enabled=1

relay_log_purge=0

read_only=0

replicate_wild_ignore_table = mysql.%

replicate_wild_ignore_table = information_schema.%

replicate_wild_ignore_table = performance_schema.%

log-slave-updates=1

 

auto_increment_offset=1

auto_increment_increment=2

221添加

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000

rpl_semi_sync_slave_enabled=1

relay_log_purge=0

read_only=1

replicate_wild_ignore_table = mysql.%

replicate_wild_ignore_table = information_schema.%

replicate_wild_ignore_table = performance_schema.%

log-slave-updates=1

 

auto_increment_offset=2

auto_increment_increment=2

196/197添加

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000

rpl_semi_sync_slave_enabled=1

# relay_log_purge=0

read_only=1

replicate_wild_ignore_table = mysql.%

replicate_wild_ignore_table = information_schema.%

replicate_wild_ignore_table = performance_schema.%

log-slave-updates=1

 

(6) 测试脚本  可以不做这一步

测试脚本

> more ins.sh 

#!/bin/bash

while true

do

mysql -uroot -p123456 –h10.10.38.230 -e "insert into wilson.t2 values($RANDOM);"

usleep 5000

done

 

2. MHM集群套件的配置

只在201主机配置

# mkdir –p /var/log/masterha/app1

# mkdir -p /etc/mysqlmha

# cd /etc/mysqlmha/

# cp -a /usr/local/mha4mysql-manager-0.56/samples/* .

# cd /etc/mysqlmha/conf

# vim mha.cnf 

[server default]

user=root1           

password=system

ssh_user=root

repl_user=repl_user   

repl_password=repl_user1

ping_interval=1 

 

manager_workdir=/var/log/masterha/app1

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

remote_workdir=/var/log/masterha/app1

ping_interval=1

secondary_check_script= masterha_secondary_check -s 10.10.38.221 -s 10.10.38.196 -s 10.10.38.197

master_ip_failover_script=/etc/mysqlmha/scripts/master_ip_failover

[server1]

hostname=10.10.38.40

ssh_port=22

port=39326

master_binlog_dir=/Data/users/mysusr02/mysql/mylog/

candidate_master=1

 

[server2]

hostname=10.10.38.221

ssh_port=22

port=39326

master_binlog_dir=/Data/users/mysusr02/mysql/mylog/

candidate_master=1

 

[server3]

hostname=10.10.38.196

ssh_port=22

port=39326

master_binlog_dir=/Data/users/mysusr02/mysql/mylog/

no_master=1

 

[server4]

hostname=10.10.38.197

ssh_port=22

port=39326

master_binlog_dir=/Data/users/mysusr02/mysql/mylog/

no_master=1

 

监控主机配置201部署

[root@manager scripts]# pwd

/etc/mysqlmha/scripts

more master_ip_failover

#!/usr/bin/env perl

use strict;

use warnings FATAL => 'all';

use Getopt::Long;

my (

$command, $ssh_user, $orig_master_host, $orig_master_ip,

$orig_master_port, $new_master_host, $new_master_ip, $new_master_port

);

my $vip = '10.10.38.230'; # Virtual IP

my $gateway = '10.10.38.2';#Gateway IP

my $interface = 'eth3';

my $key = "1";

my $ssh_start_vip = "/sbin/ifconfig $interface:$key $vip;/sbin/arping -I $interface -c 3 -s $vip $gateway >/

dev/null 2>&1";

my $ssh_stop_vip = "/sbin/ifconfig $interface:$key down";

GetOptions(

'command=s' => \$command,

'ssh_user=s' => \$ssh_user,

'orig_master_host=s' => \$orig_master_host,

'orig_master_ip=s' => \$orig_master_ip,

'orig_master_port=i' => \$orig_master_port,

'new_master_host=s' => \$new_master_host,

'new_master_ip=s' => \$new_master_ip,

'new_master_port=i' => \$new_master_port,

);

exit &main();

sub main {

print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";

if ( $command eq "stop" || $command eq "stopssh" ) {

# $orig_master_host, $orig_master_ip, $orig_master_port are passed.

# If you manage master ip address at global catalog database,

# invalidate orig_master_ip here.

my $exit_code = 1;

eval {

print "Disabling the VIP on old master: $orig_master_host \n";

&stop_vip();

$exit_code = 0;

};

if ($@) {

warn "Got Error: $@\n";

exit $exit_code;

}

exit $exit_code;

}

elsif ( $command eq "start" ) {

# all arguments are passed.

# If you manage master ip address at global catalog database,

# activate new_master_ip here.

# You can also grant write access (create user, set read_only=0, etc) here.

my $exit_code = 10;

eval {

print "Enabling the VIP - $vip on the new master - $new_master_host \n";

&start_vip();

$exit_code = 0;

};

if ($@) {

warn $@;

exit $exit_code;

}

exit $exit_code;

}

elsif ( $command eq "status" ) {

print "Checking the Status of the script.. OK \n";

`ssh $ssh_user\@$orig_master_host \" $ssh_start_vip \"`;

exit 0;

}

else {

&usage();

exit 1;

}

}

# A simple system call that enable the VIP on the new master

sub start_vip() {

`ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;

}

# A simple system call that disable the VIP on the old_master

sub stop_vip() {

`ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;

}

sub usage {

print

"Usage: master_ip_failover --command=start|stop|stopssh|status --orig_master_host=host --orig_master_ip

=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port\n";

}

意:修改VIP、网关以及网卡eth3  脚本是MHA自带的


201主机检测ssh是否ping通

[root@manager conf]# masterha_check_ssh  --conf=/etc/mysqlmha/conf/mha.cnf

Wed Oct 28 17:55:31 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Wed Oct 28 17:55:31 2015 - [info] Reading application default configuration from /etc/mysqlmha/conf/mha.cnf..

Wed Oct 28 17:55:31 2015 - [info] Reading server configuration from /etc/mysqlmha/conf/mha.cnf..

Wed Oct 28 17:55:31 2015 - [info] Starting SSH connection tests..

Wed Oct 28 17:55:34 2015 - [debug] 

Wed Oct 28 17:55:31 2015 - [debug]  Connecting via SSH from root@10.10.38.40(10.10.38.40:22) to root@10.10.38.221(10.10.38.221:22)..

Wed Oct 28 17:55:31 2015 - [debug]   ok.

Wed Oct 28 17:55:31 2015 - [debug]  Connecting via SSH from root@10.10.38.40(10.10.38.40:22) to root@10.10.38.196(10.10.38.196:22)..

Wed Oct 28 17:55:32 2015 - [debug]   ok.

Wed Oct 28 17:55:32 2015 - [debug]  Connecting via SSH from root@10.10.38.40(10.10.38.40:22) to root@10.10.38.197(10.10.38.197:22)..

Wed Oct 28 17:55:33 2015 - [debug]   ok.

Wed Oct 28 17:55:35 2015 - [debug] 

Wed Oct 28 17:55:32 2015 - [debug]  Connecting via SSH from root@10.10.38.197(10.10.38.197:22) to root@10.10.38.40(10.10.38.40:22)..

Wed Oct 28 17:55:33 2015 - [debug]   ok.

Wed Oct 28 17:55:33 2015 - [debug]  Connecting via SSH from root@10.10.38.197(10.10.38.197:22) to root@10.10.38.221(10.10.38.221:22)..

Wed Oct 28 17:55:34 2015 - [debug]   ok.

Wed Oct 28 17:55:34 2015 - [debug]  Connecting via SSH from root@10.10.38.197(10.10.38.197:22) to root@10.10.38.196(10.10.38.196:22)..

Wed Oct 28 17:55:35 2015 - [debug]   ok.

Wed Oct 28 17:55:35 2015 - [debug] 

Wed Oct 28 17:55:31 2015 - [debug]  Connecting via SSH from root@10.10.38.221(10.10.38.221:22) to root@10.10.38.40(10.10.38.40:22)..

Wed Oct 28 17:55:32 2015 - [debug]   ok.

Wed Oct 28 17:55:32 2015 - [debug]  Connecting via SSH from root@10.10.38.221(10.10.38.221:22) to root@10.10.38.196(10.10.38.196:22)..

Wed Oct 28 17:55:33 2015 - [debug]   ok.

Wed Oct 28 17:55:33 2015 - [debug]  Connecting via SSH from root@10.10.38.221(10.10.38.221:22) to root@10.10.38.197(10.10.38.197:22)..

Wed Oct 28 17:55:34 2015 - [debug]   ok.

Wed Oct 28 17:55:35 2015 - [debug] 

Wed Oct 28 17:55:32 2015 - [debug]  Connecting via SSH from root@10.10.38.196(10.10.38.196:22) to root@10.10.38.40(10.10.38.40:22)..

Wed Oct 28 17:55:32 2015 - [debug]   ok.

Wed Oct 28 17:55:32 2015 - [debug]  Connecting via SSH from root@10.10.38.196(10.10.38.196:22) to root@10.10.38.221(10.10.38.221:22)..

Wed Oct 28 17:55:33 2015 - [debug]   ok.

Wed Oct 28 17:55:33 2015 - [debug]  Connecting via SSH from root@10.10.38.196(10.10.38.196:22) to root@10.10.38.197(10.10.38.197:22)..

Wed Oct 28 17:55:34 2015 - [debug]   ok.

Wed Oct 28 17:55:35 2015 - [info] All SSH connection tests passed successfully.

检测配置复制情况

[root@manager conf]# masterha_check_repl  --conf=/etc/mysqlmha/conf/mha.cnf

Wed Oct 28 17:55:58 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Wed Oct 28 17:55:58 2015 - [info] Reading application default configuration from /etc/mysqlmha/conf/mha.cnf..

Wed Oct 28 17:55:58 2015 - [info] Reading server configuration from /etc/mysqlmha/conf/mha.cnf..

Wed Oct 28 17:55:58 2015 - [info] MHA::MasterMonitor version 0.56.

Wed Oct 28 17:55:59 2015 - [info] GTID failover mode = 0

Wed Oct 28 17:55:59 2015 - [info] Dead Servers:

Wed Oct 28 17:55:59 2015 - [info] Alive Servers:

Wed Oct 28 17:55:59 2015 - [info]   10.10.38.40(10.10.38.40:39326)

Wed Oct 28 17:55:59 2015 - [info]   10.10.38.221(10.10.38.221:39326)

Wed Oct 28 17:55:59 2015 - [info]   10.10.38.196(10.10.38.196:39326)

Wed Oct 28 17:55:59 2015 - [info]   10.10.38.197(10.10.38.197:39326)

Wed Oct 28 17:55:59 2015 - [info] Alive Slaves:

Wed Oct 28 17:55:59 2015 - [info]   10.10.38.40(10.10.38.40:39326)  Version=5.6.24-72.2-log (oldest major version between slaves) log-bin:enabled

Wed Oct 28 17:55:59 2015 - [info]     Replicating from 10.10.38.221(10.10.38.221:39326)

Wed Oct 28 17:55:59 2015 - [info]     Primary candidate for the new Master (candidate_master is set)

Wed Oct 28 17:55:59 2015 - [info]   10.10.38.196(10.10.38.196:39326)  Version=5.6.24-72.2-log (oldest major version between slaves) log-bin:enabled

Wed Oct 28 17:55:59 2015 - [info]     Replicating from 10.10.38.221(10.10.38.221:39326)

Wed Oct 28 17:55:59 2015 - [info]     Not candidate for the new Master (no_master is set)

Wed Oct 28 17:55:59 2015 - [info]   10.10.38.197(10.10.38.197:39326)  Version=5.6.24-72.2-log (oldest major version between slaves) log-bin:enabled

Wed Oct 28 17:55:59 2015 - [info]     Replicating from 10.10.38.221(10.10.38.221:39326)

Wed Oct 28 17:55:59 2015 - [info]     Not candidate for the new Master (no_master is set)

Wed Oct 28 17:55:59 2015 - [info] Current Alive Master: 10.10.38.221(10.10.38.221:39326)

Wed Oct 28 17:55:59 2015 - [info] Checking slave configurations..

Wed Oct 28 17:55:59 2015 - [info]  read_only=1 is not set on slave 10.10.38.40(10.10.38.40:39326).

Wed Oct 28 17:55:59 2015 - [info] Checking replication filtering settings..

Wed Oct 28 17:55:59 2015 - [info]  binlog_do_db= , binlog_ignore_db= 

Wed Oct 28 17:55:59 2015 - [info]  Replication filtering check ok.

Wed Oct 28 17:55:59 2015 - [info] GTID (with auto-pos) is not supported

Wed Oct 28 17:55:59 2015 - [info] Starting SSH connection tests..

Wed Oct 28 17:56:04 2015 - [info] All SSH connection tests passed successfully.

Wed Oct 28 17:56:04 2015 - [info] Checking MHA Node version..

Wed Oct 28 17:56:06 2015 - [info]  Version check ok.

Wed Oct 28 17:56:06 2015 - [info] Checking SSH publickey authentication settings on the current master..

Wed Oct 28 17:56:06 2015 - [info] HealthCheck: SSH to 10.10.38.221 is reachable.

Wed Oct 28 17:56:07 2015 - [info] Master MHA Node version is 0.56.

Wed Oct 28 17:56:07 2015 - [info] Checking recovery script configurations on 10.10.38.221(10.10.38.221:39326)..

Wed Oct 28 17:56:07 2015 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/Data/users/mysusr02/mysql/mylog/ --output_file=/var/log/masterha/app1/save_binary_logs_test --manager_version=0.56 --start_file=mysql-bin-rac3-39326.000004 

Wed Oct 28 17:56:07 2015 - [info]   Connecting to root@10.10.38.221(10.10.38.221:22).. 

  Creating /var/log/masterha/app1 if not exists..    ok.

  Checking output directory is accessible or not..

   ok.

  Binlog found at /Data/users/mysusr02/mysql/mylog/, up to mysql-bin-rac3-39326.000004

Wed Oct 28 17:56:07 2015 - [info] Binlog setting check done.

Wed Oct 28 17:56:07 2015 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..

Wed Oct 28 17:56:07 2015 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='root1' --slave_host=10.10.38.40 --slave_ip=10.10.38.40 --slave_port=39326 --workdir=/var/log/masterha/app1 --target_version=5.6.24-72.2-log --manager_version=0.56 --relay_log_info=/Data/users/mysusr02/mysql/mydata/relay-log.info  --relay_dir=/Data/users/mysusr02/mysql/mydata/  --slave_pass=xxx

Wed Oct 28 17:56:07 2015 - [info]   Connecting to root@10.10.38.40(10.10.38.40:22).. 

  Checking slave recovery environment settings..

    Opening /Data/users/mysusr02/mysql/mydata/relay-log.info ... ok.

    Relay log found at /Data/users/mysusr02/mysql/mydata, up to mysql-rac2-39326-relay-bin.000004

    Temporary relay log file is /Data/users/mysusr02/mysql/mydata/mysql-rac2-39326-relay-bin.000004

    Testing mysql connection and privileges.. done.

    Testing mysqlbinlog output.. done.

    Cleaning up test file(s).. done.

Wed Oct 28 17:56:08 2015 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='root1' --slave_host=10.10.38.196 --slave_ip=10.10.38.196 --slave_port=39326 --workdir=/var/log/masterha/app1 --target_version=5.6.24-72.2-log --manager_version=0.56 --relay_log_info=/Data/users/mysusr02/mysql/mydata/relay-log.info  --relay_dir=/Data/users/mysusr02/mysql/mydata/  --slave_pass=xxx

Wed Oct 28 17:56:08 2015 - [info]   Connecting to root@10.10.38.196(10.10.38.196:22).. 

  Checking slave recovery environment settings..

    Opening /Data/users/mysusr02/mysql/mydata/relay-log.info ... ok.

    Relay log found at /Data/users/mysusr02/mysql/mydata, up to mysql-rac4-39326-relay-bin.000002

    Temporary relay log file is /Data/users/mysusr02/mysql/mydata/mysql-rac4-39326-relay-bin.000002

    Testing mysql connection and privileges.. done.

    Testing mysqlbinlog output.. done.

    Cleaning up test file(s).. done.

Wed Oct 28 17:56:09 2015 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='root1' --slave_host=10.10.38.197 --slave_ip=10.10.38.197 --slave_port=39326 --workdir=/var/log/masterha/app1 --target_version=5.6.24-72.2-log --manager_version=0.56 --relay_log_info=/Data/users/mysusr02/mysql/mydata/relay-log.info  --relay_dir=/Data/users/mysusr02/mysql/mydata/  --slave_pass=xxx

Wed Oct 28 17:56:09 2015 - [info]   Connecting to root@10.10.38.197(10.10.38.197:22).. 

  Checking slave recovery environment settings..

    Opening /Data/users/mysusr02/mysql/mydata/relay-log.info ... ok.

    Relay log found at /Data/users/mysusr02/mysql/mydata, up to mysql-rac5-39326-relay-bin.000002

    Temporary relay log file is /Data/users/mysusr02/mysql/mydata/mysql-rac5-39326-relay-bin.000002

    Testing mysql connection and privileges.. done.

    Testing mysqlbinlog output.. done.

    Cleaning up test file(s).. done.

Wed Oct 28 17:56:09 2015 - [info] Slaves settings check done.

Wed Oct 28 17:56:09 2015 - [info] 

10.10.38.221(10.10.38.221:39326) (current master)

 +--10.10.38.40(10.10.38.40:39326)

 +--10.10.38.196(10.10.38.196:39326)

 +--10.10.38.197(10.10.38.197:39326)

 

Wed Oct 28 17:56:09 2015 - [info] Checking replication health on 10.10.38.40..

Wed Oct 28 17:56:09 2015 - [info]  ok.

Wed Oct 28 17:56:09 2015 - [info] Checking replication health on 10.10.38.196..

Wed Oct 28 17:56:09 2015 - [info]  ok.

Wed Oct 28 17:56:09 2015 - [info] Checking replication health on 10.10.38.197..

Wed Oct 28 17:56:09 2015 - [info]  ok.

Wed Oct 28 17:56:09 2015 - [info] Checking master_ip_failover_script status:

Wed Oct 28 17:56:09 2015 - [info]   /etc/mysqlmha/scripts/master_ip_failover --command=status --ssh_user=root --orig_master_host=10.10.38.221 --orig_master_ip=10.10.38.221 --orig_master_port=39326 

 

 

IN SCRIPT TEST====/sbin/ifconfig eth3:1 down==/sbin/ifconfig eth3:1 10.10.38.230;/sbin/arping -I eth3 -c 3 -s 10.10.38.230 10.10.38.2 >/dev/null 2>&1===

 

Checking the Status of the script.. OK 

Wed Oct 28 17:56:13 2015 - [info]  OK.

Wed Oct 28 17:56:13 2015 - [warning] shutdown_script is not defined.

Wed Oct 28 17:56:13 2015 - [info] Got exit code 0 (Not master dead).

 

MySQL Replication Health is OK.

启动mha

nohup masterha_manager --conf=/etc/mysqlmha/conf/mha.cnf > /tmp/mha_manager.log  < /dev/null 2>&1 &

查看状态

[root@manager conf]# masterha_check_status --conf=/etc/mysqlmha/conf/mha.cnf

mha (pid:13691) is running(0:PING_OK), master:10.10.38.221

如果停止40主机mysql服务;则虚IP 230会转移到221 mysql主机;而且196和197两个slave都会指向221主机mysql。

 

ifconfig

eth3      Link encap:Ethernet  HWaddr 00:50:56:87:6F:0B  

          inet addr:10.10.38.221  Bcast:10.10.38.255  Mask:255.255.255.0

          inet6 addr: fe80::250:56ff:fe87:6f0b/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:1195144 errors:0 dropped:1455 overruns:0 frame:0

          TX packets:411040 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:819807844 (781.8 MiB)  TX bytes:45872378 (43.7 MiB)

 

eth3:1    Link encap:Ethernet  HWaddr 00:50:56:87:6F:0B  

          inet addr:10.10.38.230  Bcast:10.255.255.255  Mask:255.0.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

 

3.  客户端登陆

mysql -uroot -p123456 -h10.10.38.230


后期会将显示部署的MHA+lvs+keepalived分享出来。

MHA维护有优点和缺点:

最大的优点就是主机不down的状况下,能保持数据不丢失。

最大缺点就是主从切换了:需要配置mha.cnf文件,添加信息,并重新启动mha监控进程(自动切换进程)。