In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. MHA deployment environment:
MHA_Manager: 192.168.1.100
Mysql_Master:10.20.20.12
Mysql_Slave-1:10.20.20.13
Mysql_Slave-2:10.20.20.14
Download address of the software package:
Http://yunpan.cn/c3S5IAKdhqXJe access password 5ea4
Note: turn off the firewall, selinux
Second, the preparatory stage:
Step1: build a trust relationship:
On Node:10.20.20.12:
[root@mysqlmaster /] # ssh-keygen-t rsa
[root@mysqlmaster /] # ssh-copy-id-I / root/.ssh/id_rsa.pub root@10.20.20.12
[root@mysqlmaster /] # ssh-copy-id-I / root/.ssh/id_rsa.pub root@10.20.20.13
[root@mysqlmaster /] # ssh-copy-id-I / root/.ssh/id_rsa.pub root@10.20.20.14
On Node:10.20.20.13:
[root@mysqlslave1 /] # ssh-keygen-t rsa
[root@mysqlslave1 /] # ssh-copy-id-I / root/.ssh/id_rsa.pub root@10.20.20.12
[root@mysqlslave1 /] # ssh-copy-id-I / root/.ssh/id_rsa.pub root@10.20.20.13
[root@mysqlslave1 /] # ssh-copy-id-I / root/.ssh/id_rsa.pub root@10.20.20.14
On Node:10.20.20.14:
[root@mysqlslave2 /] # ssh-keygen-t rsa
[root@mysqlslave2 /] # ssh-copy-id-I / root/.ssh/id_rsa.pub root@10.20.20.12
[root@mysqlslave2 /] # ssh-copy-id-I / root/.ssh/id_rsa.pub root@10.20.20.13
[root@mysqlslave2 /] # ssh-copy-id-I / root/.ssh/id_rsa.pub root@10.20.20.14
Step2: deploy mysql services (source code build)
1. Install the packages needed to compile the code
Yum-y install make gcc-c++ cmake bison-devel ncurses-devel
2. Download MySQL 5.6.14
Wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27.tar.gz
Tar xvf mysql-5.6.17.tar.gz
Cd mysql-5.6.27
3. Compile and install
Cmake\
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DMYSQL_DATADIR=/data/mysql\
-DSYSCONFDIR=/etc\
-DWITH_MYISAM_STORAGE_ENGINE=1\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_MEMORY_STORAGE_ENGINE=1\
-DWITH_READLINE=1\
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock\
-DMYSQL_TCP_PORT=3306\
-DENABLED_LOCAL_INFILE=1\
-DWITH_PARTITION_STORAGE_ENGINE=1\
-DEXTRA_CHARSETS=all\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci
Make & & make install
Configure MySQL
Create a user group
Groupadd mysql
Useradd-g mysql mysql
Modify / usr/local/mysql permissions
Chown-R mysql:mysql / usr/local/mysql
Chown-R mysql:mysql / data
Configure my.cnf (see conf file for details)
Here is a simple my.cnf configuration
[root@mysqlmaster /] # cat / etc/my.cnf
[mysqld]
Log-bin=mysql-bin
Server-id=12
Skip-name-resolve
[root@mysqlslave1 ~] # cat / etc/my.cnf
[mysqld]
Log-bin=mysql-bin
Server-id=13
Read-only=1
Relay_log_purge=0
Skip-name-resolve
[root@mysqlslave2 .ssh] # cat / etc/my.cnf
[mysqld]
Log-bin=mysql-bin
Server-id=14
Read-only=1
Relay_log_purge=0
Skip-name-resolve
Initialize configuration
Cd / usr/local/mysql
Enter the installation path, execute the initialization configuration script, and create the database and table that comes with the system.
Scripts/mysql_install_db-basedir=/usr/local/mysql-datadir=/data/mysql-user=mysql
Start MySQL
Cp support-files/mysql.server / etc/init.d/mysql
Chkconfig mysql on
Service mysql start
Configure environment variables
Vi / etc/profile
Export PATH=/usr/local/mysql/bin:$PATH
Effective environment variable
Source / etc/profile
Execute the following command to change the root password
Mysql-uroot
Mysql > SET PASSWORD = PASSWORD ('123456')
To set that root users can access remotely, execute
Mysql > GRANT ALL PRIVILEGES ON *. * TO 'root'@'172.16.%' IDENTIFIED BY' password' WITH GRANT OPTION
3. Create MySQL master-slave replication
Step1: create database management account and copy account (both main database and standby database are executed)
Grant all privileges on *. * to 'root'@'10.20.20.%' identified by' 123456'
Grant Replication slave,super on *. * to 'repler'@'10.20.20.%' identified by' 123.com'
Grant all privileges on *. * to 'root'@'192.168.1.%' identified by' 123456'
Flush privileges
Step2: establish master-slave replication between mysql
Log in to the mysql of the master server and query the status of master
Mysql > show master status
+-+
| | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | |
+-+
| | mysql-bin.000001 | 308 |
+-+
Configure slave server Slave
Mysql > change master to master_host='10.20.20.12',master_user='repler',master_password='123.com',master_log_file='mysql-bin.000001',master_log_pos=308
Create a soft link and set it from library to read only
Step1:ln-s / usr/local/mysql/bin/* / usr/local/bin/
Note: you need to make this soft connection, otherwise when you perform masterha_check_repl verification, you will report Can't exec "mysqlbinlog": there is no error in that file or directory.
Step2: all my.cnf from the server to add: read-only=1 and relay_log_purge=0
5. Install MHA_Manager
1. Install the epel source
Rpm-Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
Yum-- disablerepo=epel-y update ca-certificates
two。 Install dependency packages
Yum-y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Params-Validate perl-TimeDate perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN perl-Parallel-ForkManager perl-Log-Message
Yum-y install perl-NTLM.noarch-if you want to send email send_report, you need to install this package, otherwise you will not send email
3. Install MHA_Node (required for MHA_Manager)
Tar-zxvf mha4mysql-manager-0.57.tar.gz
Cd mha4mysql-manager-0.57
Perl Makefile.PL
Make
Make install
Tar-zxf Test-Simple-1.001014.tar.gz
Cd Test-Simple-1.001014
Perl Makefile.PL
Make
Make install
Tar-zxf CPAN-Perl-Releases-2.48.tar.gz
Cd CPAN-Perl-Releases-2.48
Perl Makefile.PL
Make
Make install
Tar-zxf Log-Dispatch-Perl-0.04.tar.gz
Cd Log-Dispatch-Perl-0.04
Perl Makefile.PL
Make
Make install
Mkdir / etc/masterha/
Mkdir / etc/masterha/scripts
Mkdir / masterha/app1-p
Install MHA_Node (on all Mysql servers)
1. Install the epel source
Rpm-Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
Yum-- disablerepo=epel-y update ca-certificates
two。 Install dependency packages
Yum-y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Params-Validate perl-TimeDate perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN perl-Parallel-ForkManager
3. Install MHA_Node
Tar-zxf mha4mysql-node-0.57.tar.gz
Cd mha4mysql-node-0.57
Perl Makefile.PL
Make
Make install
Mkdir / masterha/app1-p
7. Configure MHA_Manager (192.168.1.100):
Vim / etc/masterha/app1.cnf
[server default]
# workdir on the management server
Manager_workdir=/masterha/app1/
Manager_log=/masterha/app1/manager.log
# workdir on the node for mysql server
Remote_workdir=/masterha/app1
Master_binlog_dir=/data/mysql
Check_repl_delay=0
# mysql user and password
User=root
Password=123456
# replication_user
Repl_user=repler
Repl_password=123.com
# checking master every second
Ping_interval=1
# ssh user
Ssh_user=root
# check the availability of master
Secondary_check_script=masterha_secondary_check-s 10.20.20.13-s 10.20.20.14
# automatic failure VIP switchover call script
Master_ip_failover_script=/etc/masterha/scripts/master_ip_failover
# Manual failover call script
Master_ip_online_change_script=/etc/masterha/scripts/master_ip_online_change
# send email script
Report_script=/mha/scripts/send_report
[server1]
Hostname=10.20.20.12
Candidate_master=1
[server2]
Hostname=10.20.20.13
Candidate_master=1
[server3]
Hostname=10.20.20.14
No_master=1
2. Automatic failure VIP switchover call script
Vi / etc/masterha/scripts/master_ip_failover (on MHA_manager node)
#! / 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 = '192.168.1.100mm; # Virtual IP
My $gateway = '192.168.1.1; # Gateway IP
My $interface = 'eth0'; # bind to interface
My $key = "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
}
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 {
"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"
}
3. Manual failover call script (in MHA_manager)
Vi / etc/masterha/scripts/master_ip_online_change
#! / 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
Use MHA::DBHelper
Use MHA::NodeUtil
Use Time::HiRes qw (sleep gettimeofday tv_interval)
Use Data::Dumper
My $_ tstart
My $_ running_interval = 0.1
My (
$command, $orig_master_host, $orig_master_ip
$orig_master_port, $orig_master_user, $orig_master_ssh_user
$new_master_host, $new_master_ip, $new_master_port
$new_master_user, $new_master_ssh_user, $orig_master_is_new_slave
$orig_master_password, $new_master_password
);
My $vip = '192.168.1.100mm; # Virtual IP
My $gateway = '192.168.1.1; # Gateway IP
My $interface = 'eth0'; # interface
My $key = "1"
My $ssh_start_vip = "/ sbin/ifconfig $interface:$key $vip/24"
My $flush_arp = "/ sbin/arping-I $interface-c 2-s $vip $gateway"
My $ssh_stop_vip = "/ sbin/ifconfig $interface:$key down"
My $ssh_user = "root"
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
'orig_master_user=s' = >\ $orig_master_user
'orig_master_password=s' = >\ $orig_master_password
'new_master_host=s' = >\ $new_master_host
'new_master_ip=s' = >\ $new_master_ip
'new_master_port=i' = >\ $new_master_port
'new_master_user=s' = >\ $new_master_user
'new_master_password=s' = >\ $new_master_password
'orig_master_ssh_user=s' = >\ $orig_master_ssh_user
'new_master_ssh_user=s' = >\ $new_master_ssh_user
'orig_master_is_new_slave' = >\ $orig_master_is_new_slave
);
Exit & main ()
Sub current_time_us {
My ($sec, $microsec) = gettimeofday ()
My $curdate = localtime ($sec)
Return $curdate. "". Sprintf ("d", $microsec)
}
Sub sleep_until {
My $elapsed = tv_interval ($_ tstart)
If ($_ running_interval > $elapsed) {
Sleep ($_ running_interval-$elapsed)
}
}
Sub get_threads_util {
My $dbh = shift
My $my_connection_id = shift
My $running_time_threshold = shift
My $type = shift
$running_time_threshold = 0 unless ($running_time_threshold)
$type = 0 unless ($type)
My @ threads
My $sth = $dbh- > prepare ("SHOW PROCESSLIST")
$sth- > execute ()
While (my $ref = $sth- > fetchrow_hashref ()) {
My $id = $ref- > {Id}
My $user = $ref- > {User}
My $host = $ref- > {Host}
My $command = $ref- > {Command}
My $state = $ref- > {State}
My $query_time = $ref- > {Time}
My $info = $ref- > {Info}
$info = ~ s / ^\ s * (. *?)\ if defined ($info)
Next if ($my_connection_id = = $id)
Next if (defined ($query_time) & & $query_time
< $running_time_threshold ); next if ( defined($command) && $command eq "Binlog Dump" ); next if ( defined($user) && $user eq "system user" ); next if ( defined($command) && $command eq "Sleep" && defined($query_time) && $query_time >= 1)
If ($type > = 1) {
Next if (defined ($command) & & $command eq "Sleep")
Next if (defined ($command) & & $command eq "Connect")
}
If ($type > = 2) {
Next if (defined ($info) & & $info = ~ m / ^ select / I)
Next if (defined ($info) & & $info = ~ m / ^ show / I)
}
Push @ threads, $ref
}
Return @ threads
}
Sub main {
If ($command eq "stop") {
# # Gracefully killing connections on the current master
# 1. Set read_only= 1 on the new master
# 2. DROP USER so that no app user can establish new connections
# 3. Set read_only= 1 on the current master
# 4. Kill current queries
# * Any database access failure will result in script die.
My $exit_code = 1
Eval {
# # Setting read_only=1 on the new master (to avoid accident)
My $new_master_handler = new MHA::DBHelper ()
# args: hostname, port, user, password, raise_error (die_on_error) _ or_not
$new_master_handler- > connect ($new_master_ip, $new_master_port
$new_master_user, $new_master_password, 1)
Print current_time_us (). "Set read_only on the new master.."
$new_master_handler- > enable_read_only ()
If ($new_master_handler- > is_read_only ()) {
Print "ok.\ n"
}
Else {
Die "Failed!\ n"
}
$new_master_handler- > disconnect ()
# Connecting to the orig master, die if any database error happens
My $orig_master_handler = new MHA::DBHelper ()
$orig_master_handler- > connect ($orig_master_ip, $orig_master_port
$orig_master_user, $orig_master_password, 1)
# # Drop application user so that nobody can connect. Disabling per-session binlog beforehand
# $orig_master_handler- > disable_log_bin_local ()
# print current_time_us (). "Drpping app user on the orig master..\ n"
# FIXME_xxx_drop_app_user ($orig_master_handler)
# # Waiting for N * 100milliseconds so that current connections can exit
My $time_until_read_only = 15
$_ tstart = [gettimeofday]
My @ threads = get_threads_util ($orig_master_handler- > {dbh})
$orig_master_handler- > {connection_id})
While ($time_until_read_only > 0 & & $# threads > = 0) {
If ($time_until_read_only% 5 = = 0) {
Printf
"% s Waiting all running d threads are disconnected.. (max% d milliseconds)\ n"
Current_time_us (), $# threads + 1, $time_until_read_only * 100
If ($# threads
< 5 ) { print Data::Dumper->New ([$_])-> Indent (0)-> Terse (1)-> Dump. "\ n"
Foreach (@ threads)
}
}
Sleep_until ()
$_ tstart = [gettimeofday]
$time_until_read_only--
@ threads = get_threads_util ($orig_master_handler- > {dbh})
$orig_master_handler- > {connection_id})
}
# # Setting read_only=1 on the current master so that nobody (except SUPER) can write
Print current_time_us (). "Set read_only=1 on the orig master.."
$orig_master_handler- > enable_read_only ()
If ($orig_master_handler- > is_read_only ()) {
Print "ok.\ n"
}
Else {
Die "Failed!\ n"
}
# # Waiting for M * 100milliseconds so that current update queries can complete
My $time_until_kill_threads = 5
@ threads = get_threads_util ($orig_master_handler- > {dbh})
$orig_master_handler- > {connection_id})
While ($time_until_kill_threads > 0 & & $# threads > = 0) {
If ($time_until_kill_threads% 5 = = 0) {
Printf
"% s Waiting all running d queries are disconnected.. (max% d milliseconds)\ n"
Current_time_us (), $# threads + 1, $time_until_kill_threads * 100
If ($# threads
< 5 ) { print Data::Dumper->New ([$_])-> Indent (0)-> Terse (1)-> Dump. "\ n"
Foreach (@ threads)
}
}
Sleep_until ()
$_ tstart = [gettimeofday]
$time_until_kill_threads--
@ threads = get_threads_util ($orig_master_handler- > {dbh})
$orig_master_handler- > {connection_id})
& stop_vip ()
# # Terminating all threads
Print current_time_us (). "Killing all application threads..\ n"
$orig_master_handler- > kill_threads (@ threads) if ($# threads > = 0)
Print current_time_us (). "done."
# $orig_master_handler- > enable_log_bin_local ()
$orig_master_handler- > disconnect ()
# # After finishing the script, MHA executes FLUSH TABLES WITH READ LOCK
$exit_code = 0
}
If ($@) {
Warn "Got Error: $@\ n"
Exit $exit_code
}
Exit $exit_code
}
Elsif ($command eq "start") {
# # Activating master ip on the new master
# 1. Create app user with write privileges
# 2. Moving backup script if needed
# 3. Register new master's ip to the catalog database
# If exit code is 0 or 10, MHA does not abort
My $exit_code = 10
Eval {
My $new_master_handler = new MHA::DBHelper ()
# args: hostname, port, user, password, raise_error_or_not
$new_master_handler- > connect ($new_master_ip, $new_master_port
$new_master_user, $new_master_password, 1)
# # Set read_only=0 on the new master
# $new_master_handler- > disable_log_bin_local ()
Print current_time_us (). "Set read_only=0 on the new master."
$new_master_handler- > disable_read_only ()
# # Creating an app user on the new master
# print current_time_us (). "Creating app user on the new master..\ n"
# FIXME_xxx_create_app_user ($new_master_handler)
# $new_master_handler- > enable_log_bin_local ()
$new_master_handler- > disconnect ()
# # Update master ip on the catalog database, etc
Print "Enabling the VIP-$vip on the new master-$new_master_host\ n"
& start_vip ()
& flush_arp ()
$exit_code = 0
}
If ($@) {
Warn "Got Error: $@\ n"
Exit $exit_code
}
Exit $exit_code
}
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\" `
}
# flush arp
Sub flush_arp () {
`ssh $ssh_user\ @ $new_master_host\ "$flush_arp\" `
}
Sub usage {
"Usage: master_ip_online_change-- command=start | stop | 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"
Die
}
4. Automatic email script (email will be triggered after automatic switching, in MHA_manager)
Vi / etc/masterha/scripts/send_report
#! / usr/bin/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 Mail::Sender
Use Getopt::Long
# new_master_host and new_slave_hosts are set only when recovering master succeeded
My ($dead_master_host, $new_master_host, $new_slave_hosts, $subject, $body)
My $smtp='smtp.chinadaas.com'
My $mail_from='support@chinadaas.com'
My $mail_user='support@chinadaas.com'
My $mail_pass='ZS_123456'
# my $mail_to= ['chenzhibin@chinadaas.com']
My $mail_to='chenzhibin@chinadaas.com'
GetOptions (
'orig_master_host=s' = >\ $dead_master_host
'new_master_host=s' = >\ $new_master_host
'new_slave_hosts=s' = >\ $new_slave_hosts
'subject=s' = >\ $subject
'body=s' = >\ $body
);
# Do whatever you want here
MailToContacts ($smtp,$mail_from,$mail_user,$mail_pass,$mail_to,$subject,$body)
Sub mailToContacts {
My ($smtp, $mail_from, $mail_user, $mail_pass, $mail_to, $subject, $msg) = @ _
Open my $DEBUG, "> / var/log/masterha/app1/mail.log"
Or die "Can't open the debug fileParticipation!\ n"
My $sender = new Mail::Sender {
Ctype = > 'text/plain;charset=utf-8'
Encoding = > 'utf-8'
Smtp = > $smtp
From = > $mail_from
Auth = > 'LOGIN'
TLS_allowed = >'0'
Authid = > $mail_user
Authpwd = > $mail_pass
To = > $mail_to
Subject = > $subject
Debug = > $DEBUG
}
$sender- > MailMsg (
{
Msg = > $msg
Debug = > $DEBUG
}
) or print $Mail::Sender::Error
Return 1
}
Exit 0
5. Grant executive authority
Chmod + x / etc/masterha/scripts/master_ip_failover
Chmod + x / etc/masterha/scripts/master_ip_online_change
Chmod + x / etc/masterha/scripts/send_report
8. Check the status
Check ssh authentication status (on mha_manager)
Masterha_check_ssh-conf=/etc/masterha/app1.cnf
Check replication status (on mha_manager)
Masterha_check_repl-conf=/etc/masterha/app1.cnf
IX. Start and shut down the management node
You can start mha with the following command:
Nohup masterha_manager-- conf=/etc/masterha/app1.cnf > > / dev/null 2 > & 1 &
You can stop mha with the following command
Masterha_stop-conf=/etc/app1.cnf
10. View the services started by the management node:
Ps-ef | grep master_ip_
Ps-ef | grep masterha
Or
Masterha_check_status-conf=/etc/masterha/app1.cnf
Or
View management node log information
Tail-f / masterha/app1/manager.log
Automatic switching test
Establish a VIP on the master (the script will only be triggered and the VIP will be generated only if there is a failure):
For the first time, you need to bind vip manually on the main library Mysql_Master:10.101.110.90
Ifconfig eth0:1 10.101.110.10/24
If the master library (service mysql stop) is disabled, you can observe the automatic promotion of 10.20.20.13 master through the log (tail-f / masterha/app1/manager.log), and cut the rest of the slave master to 10.20.20.13.
At the same time, VIP is automatically created on the new master 10.20.20.13
Pay attention to the following:
After the master / slave switch occurs, the manager service is automatically stopped and generated under / masterha/app1
App1.failover.complete. Delete the app1.failover.complete file if the switch occurs again.
Rm-fr / masterha/app1/app1.failover.complete
* if you switch automatically, you need to manually execute the mha manager startup script, monitor the master node, and delete rm-fr / masterha/app1/app1.failover.complete
Normally, after automatic switching, the original master may have been discarded. After the original master host is repaired, if the data is complete,
If we want to re-use the original master as the slave of the new main library, we can repair the original master by automatically switching the MHA log at that time.
The following is the command to extract the related logs: (on mha_manager)
The original main library has been repaired and the following steps are required to become a standby library.
Mha manager node
[root@mha manager] # grep-I "All other slaves should start" / masterha/app1/manager.log
Mon Apr 21 22:28:33 2014-[info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='10.20.20.13', (ip of the new main library) MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000022', MASTER_LOG_POS=506716, MASTER_USER='repl', MASTER_PASSWORD='xxx'
After obtaining the above information, you can directly perform change master to-related operations on the repaired original master and re-use it as a slave library.
12. Manual switching
Sometimes you need to switch the MySQL master server manually, you can use the masterha_master_switch command, but it calls not a master_ip_failover_script script, but a master_ip_online_change_script script, but the call parameters are similar, and the scripts can be used interchangeably.
On the mha_manager machine:
Masterha_master_switch-master_state=alive-conf=/etc/masterha/app1.cnf-new_master_host=10.20.20.12-new_master_port=3306-orig_master_is_new_slave-running_updates_limit=10000-interactive=0
Thirteen clear relay log (binlog log for database recovery)
For MHA scenarios, the recovery of some lagging slave libraries depends on the relay log of other slave libraries, so the automatic deletion feature is disabled and cleaned regularly. For cleaning up too much relay log, you need to pay attention to the replication delay resource overhead and so on. MHA can accomplish this task through purge_relay_logs script and with cronjob.
On several MHA node nodes (not required for MHA manager):
Add the following script and task execution plan:
[root@JBWDB03 shell] # cat / usr/local/shell/purge_relay_logs.sh
#! / bin/bash
User=root
Passwd='-s4) SVqJ'
Port=3306
Log_dir='/etc/masterha/log'
Work_dir='/etc/masterha/data'
Purge='/usr/local/bin/purge_relay_logs'
If [!-d $log_dir]
Then
Mkdir $log_dir-p
Fi
If [!-d $work_dir]
Then
Mkdir $work_dir-p
Fi
$purge-user=$user-- password=$passwd-- disable_relay_log_purge-- port=$port-- workdir=$work_dir > > $log_dir/purge_relay_logs.log 2 > & 1
[root@JBWDB03 shell] # crontab-l
# # emptying relay log at 1 am every day
00 01 * / 1 * * / bin/bash / usr/local/shell/purge_relay_logs.sh
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.