Get the App
SLTechnology News&Howtos  ›  Database  › 

MHA Learning (2) profile

Shulou Source: shulou.com Published: 2022-06-01 05:15:59 10月16日 Update

Configure ssh key authentication for all hosts

Ssh-keygen-t rsa

Ssh-copy-id-I / root/.ssh/id_rsa.pub root@192.168.10.103

2. Database authorization

Grant all privileges on *. * TO mha@'192.168.%' IDENTIFIED BY 'test'

Three quota documents

/ etc/masterha_default.cnf

[server default]

User=mha

Password=test

Ssh_user=root

Master_binlog_dir= / zx/mysql/data

Remote_workdir=/var/log/mha/app1

# secondary_check_script= masterha_secondary_check-s master1-s master2

Ping_interval=3

Master_ip_failover_script=/etc/mha/scripts/master_ip_failover

# shutdown_script= / etc/mha/scripts/power_manager

# report_script= / etc/mha/scripts/send_master_failover_mail

# master_ip_online_change_script=/etc/mha/scripts/master_ip_online_change

[root@manager mha] # cat / etc/mha/app1.cnf

[server default]

Manager_log=/var/log/mha/app1/manager.log

Manager_workdir=/var/log/mha/app1.log

Master_binlog_dir=/zx/mysql/data

Password=test

Ping_interval=2

Repl_password=zhangxu

Repl_user=repl_user

Ssh_user=root

User=mha

[server1]

Candidate_master=1

Check_repl_delay=0

Hostname=master2

Port=3306

[server2]

Candidate_master=1

Check_repl_delay=0

Hostname=master1

Port=3306

[root@manager mha] # cat scripts/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 = '192.168.248.100mm; # Virtual IP

My $gateway = '192.168.1.1' alternative gateway IP

My $interface = 'eth2'

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"

}

Startup script

Nohup masterha_manager-ignore_last_failover-remove_dead_master_conf-conf=/etc/mha/app1.cnf-remove_dead_master_conf

< /dev/null >

/ var/log/mha/app1/app1.log 2 > & 1 &

Check replication

Masterha_check_repl-conf=/etc/mha/app1.cnf

Check ssh

Masterha_check_ssh-conf=/etc/mha/app1.cnf

Check mha status

Masterha_check_status-conf=/etc/mha/app1.cnf

After the switch is completed

The process dies and modifies the configuration file.

Tags: Check file configuration host data database status script process quota switch authentication learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS Shulou Information MySQL Redmi