MYSQL MHA Deployment Transcript

Source: Internet
Author: User
Tags mkdir install perl

King01 as Master king02 with king03 as King01 slave,king04 as 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) DeNA Co.,ltd.

#

# is the 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.

#

# distributed in the hope that it'll 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 has received a copy of the GNU general public License

# along with the program; If not, write to the free software

# Foundation, Inc.,

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


# # Note:this is a sample script and are 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& Gt;&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 is passed.

# If you manage the 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 the master IP address at global Catalog database,

# Activate NEW_MASTER_IP here.

# 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 to enable the VIP on the new master

Sub Start_vip () {

' SSH $ssh _user\@ $new _master_host \ "$ssh _start_vip \";

}

# A Simple system Call this 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 Deployment Transcript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.