MYSQL MHA部署實錄

來源:互聯網
上載者:User

標籤:and   start   1.2   abc   mkdir   main   slave   binlog   lis   

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


[[email protected] ~]# mkdir .ssh

[[email protected] ~]# cd .ssh

[[email protected] .ssh]# ssh-keygen -t dsa -P '' -f id_dsa

[[email protected] .ssh]# cat id_dsa.pub >> authorized_keys


[[email protected] ~]# mkdir .ssh

[[email protected] ~]# cd .ssh

[[email protected] .ssh]# ssh-keygen -t dsa -P '' -f id_dsa

[[email protected] .ssh]# cat id_dsa.pub >> authorized_keys


[[email protected] ~]# mkdir .ssh

[[email protected] ~]# cd .ssh

[[email protected] .ssh]# ssh-keygen -t dsa -P '' -f id_dsa

[[email protected] .ssh]# cat id_dsa.pub >> authorized_keys


[[email protected] ~]# mkdir .ssh

[[email protected] ~]# cd .ssh

[[email protected] .ssh]# ssh-keygen -t dsa -P '' -f id_dsa

[[email protected] .ssh]# cat id_dsa.pub >> authorized_keys


[[email protected] ~]# scp 192.168.1.202:/root/.ssh/id_dsa.pub ./id_dsa.pub.202

[[email protected] ~]# scp 192.168.1.203:/root/.ssh/id_dsa.pub ./id_dsa.pub.203

[[email protected] ~]# scp 192.168.1.204:/root/.ssh/id_dsa.pub ./id_dsa.pub.204

[[email protected] ~]# cd .ssh

[[email protected] .ssh]# cat id_dsa.pub.202 >> authorized_keys

[[email protected] .ssh]# cat id_dsa.pub.203 >> authorized_keys

[[email protected] .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


[[email protected] ~]# 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 ([email protected]) {

warn "Got Error: [email protected]\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 ([email protected]) {

warn [email protected];

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

}


[[email protected] ~]# /sbin/ifconfig eth0:1 192.168.1.200/24


[[email protected] ~]# /usr/local/bin/masterha_check_ssh --conf=/etc/mha/mha.conf

[[email protected] ~]# /usr/local/bin/masterha_check_repl --conf=/etc/mha/mha.conf

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

[[email protected] ~]# /usr/local/bin/masterha_check_status --conf=/etc/mha/mha.conf






MYSQL MHA部署實錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.