1. 程式人生 > >MYSQL MHA部署實錄

MYSQL MHA部署實錄

and option add ali more cat face -- etop

king01作為master king02與king03作為king01的slave,king04作為mha_manager


[root@king01 ~]# mkdir .ssh

[root@king01 ~]# cd .ssh

[root@king01 .ssh]# ssh-keygen -t dsa -P '' -f id_dsa

[root@king01 .ssh]# cat id_dsa.pub >> authorized_keys


[root@king02 ~]# mkdir .ssh

[root@king02 ~]# cd .ssh

[root@king02 .ssh]# ssh-keygen -t dsa -P '' -f id_dsa

[root@king02 .ssh]# cat id_dsa.pub >> authorized_keys


[root@king03 ~]# mkdir .ssh

[root@king03 ~]# cd .ssh

[root@king03 .ssh]# ssh-keygen -t dsa -P '' -f id_dsa

[root@king03 .ssh]# cat id_dsa.pub >> authorized_keys


[root@king04 ~]# mkdir .ssh

[root@king04 ~]# cd .ssh

[root@king04 .ssh]# ssh-keygen -t dsa -P '' -f id_dsa

[root@king04 .ssh]# cat id_dsa.pub >> authorized_keys


[root@king01 ~]# scp 192.168.1.202:/root/.ssh/id_dsa.pub ./id_dsa.pub.202

[root@king01 ~]# scp 192.168.1.203:/root/.ssh/id_dsa.pub ./id_dsa.pub.203

[root@king01 ~]# scp 192.168.1.204:/root/.ssh/id_dsa.pub ./id_dsa.pub.204

[root@king01 ~]# cd .ssh

[root@king01 .ssh]# cat id_dsa.pub.202 >> authorized_keys

[root@king01 .ssh]# cat id_dsa.pub.203 >> authorized_keys

[root@king01 .ssh]# cat id_dsa.pub.204 >> authorized_keys


king01-king04

yum install perl-DBD-MySQL perl-CPAN perl-Config-Tiny perl-Log-Dispatch perl-Time-HiRes perl-Parallel-ForkManager

tar zxvf mha4mysql-node-0.56.tar.gz

cd mha4mysql-node-0.56

perl Makefile.PL

make && make install


king04

tar zxvf mha4mysql-manager-0.56.tar.gz

cd mha4mysql-manager-0.56

perl Makefile.PL

make && make install


mkdir -p /etc/mha

mkdir -p /usr/local/mha


cp samples/conf/* /etc/mha

cp samples/scripts/* /usr/local/bin


cd /etc/mha/

vim /etc/mha/mha.conf

[server default]

manager_workdir=/usr/local/mha

manager_log=/usr/local/mha/manager.log

user=root

password=abcd.1234

ssh_user=root

repl_user=repl

repl_password=repl

ping_interval=1

master_ip_failover_script=/usr/local/bin/master_ip_failover

master_ip_online_change_script=/usr/local/bin/master_ip_online_change


[server1]

hostname=192.168.1.201

ssh_port=22

master_binlog_dir=/usr/local/mysql/data

candidate_master=1

port=3306

[server2]

hostname=192.168.1.302

ssh_port=22

master_binlog_dir=/usr/local/mysql/data

candidate_master=1

port=3306


[server3]

hostname=192.168.1.203

ssh_port=22

master_binlog_dir=/usr/local/mysql/data

candidate_master=1

port=3306


[root@king04 ~]# vi /usr/local/bin/master_ip_failover

#!/usr/bin/env perl


# Copyright (C) 2011 DeNA Co.,Ltd.

#

# This program is free software; you can redistribute it and/or modify

# it under the terms of the GNU General Public License as published by

# the Free Software Foundation; either version 2 of the License, or

# (at your option) any later version.

#

# This program is distributed in the hope that it will be useful,

# but WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

# GNU General Public License for more details.

#

# You should have received a copy of the GNU General Public License

# along with this program; if not, write to the Free Software

# Foundation, Inc.,

# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


## Note: This is a sample script and is not complete. Modify the script based on your environment.

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 = '192.168.1.200/24'; # Virtual IP

my $gateway = '192.168.1.1'; #Gateway IP

my $interface = 'eth0';

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;

}

# 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";

}


[root@king01 ~]# /sbin/ifconfig eth0:1 192.168.1.200/24


[root@king04 ~]# /usr/local/bin/masterha_check_ssh --conf=/etc/mha/mha.conf

[root@king04 ~]# /usr/local/bin/masterha_check_repl --conf=/etc/mha/mha.conf

[root@king04 ~]# nohup /usr/local/bin/masterha_manager --conf=/etc/mha/mha.conf > /var/log/masterhamanager.log < /dev/null 2>&1 &

[root@king04 ~]# /usr/local/bin/masterha_check_status --conf=/etc/mha/mha.conf






MYSQL MHA部署實錄