Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation and testing of MHA

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "installation and testing of MHA". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "installation and testing of MHA".

Environment:

192.168.56.221 MHA1

192.168.56.222 MHA2

192.168.56.223 MHA3

192.168.56.224 MHA4

# 221for master 222bit slave 223for slave 224as the management node

# # 1 install MHA package

Https://code.google.com/p/mysql-master-ha/

Https://downloads.mariadb.com/MHA/

Yum install-y perl-DBD-MySQL

Yum install-y perl cpan

Yum install-y perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager

Common rpm search sites:

Http://rpm.pbone.net/

Perl-Log-Dispatch

Perl-Parallel-ForkManager

[root@MHA1] # rpm-ivh perl-Mail-Sender-0.8.16-1.el6.rf.noarch.rpm

Warning: perl-Mail-Sender-0.8.16-1.el6.rf.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY

Preparing... # [100%]

1:perl-Mail-Sender # # [100%]

[root@MHA1] # rpm-ivh perl-Mail-Sendmail-0.79_16-4.2.noarch.rpm

Warning: perl-Mail-Sendmail-0.79_16-4.2.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 04b8b50a: NOKEY

Preparing... # [100%]

1:perl-Mail-Sendmail # # [100%]

[root@MHA1 ~] # yum localinstall perl-Log-Dispatch-2.27-1.el6.noarch.rpm

[root@MHA1 ~] # yum localinstall perl-Parallel-ForkManager-0.7.5-2.2.el6.rf.noarch.rpm

[root@MHA1 ~] # yum localinstall mha4mysql-node-0.54-0.el6.noarch.rpm # installation of all nodes

[root@MHA1 ~] # yum localinstall mha4mysql-manager-0.55-0.el6.noarch.rpm # Management Node installation

# # 2 Master-slave synchronization configuration:

# Master server

Mysql > show variables like 'log_bin'

+-+ +

| | Variable_name | Value |

+-+ +

| | log_bin | ON |

+-+ +

1 row in set (.53 sec)

Mysql > grant replication slave on *. * to 'rep'@'%' identified by' 123456; # configuration of all mysql servers is recommended to prevent master-slave switching

Query OK, 0 rows affected, 1 warning (0.17 sec)

Mysql > flush privileges

Query OK, 0 rows affected (0.01 sec)

# from the server

Vi my.cnf

[mysqld]

# slave

Relay_log=/usr/local/mysql/logs/relay-log.log

Master-info-repository=TABLE

Relay-log-info-repository=TABLE

Sync_master_info = 1

Sync_relay_log = 1

Sync_relay_log_info = 1

Mysql > change master to master_host='192.168.56.221', master_port=3306, master_user='rep', master_password='123456', master_log_file='ray-bin.000003', master_log_pos=740

Query OK, 0 rows affected, 2 warnings (0.05 sec)

Mysql > start slave

Query OK, 0 rows affected (0.03 sec)

Mysql > show slave status\ G

* * 1. Row *

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.56.221

Master_User: rep

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: ray-bin.000003

Read_Master_Log_Pos: 740

Relay_Log_File: relay-log.000003

Relay_Log_Pos: 318

Relay_Master_Log_File: ray-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 740

Relay_Log_Space: 519

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 21

Master_UUID: 262ff2d5-2264-11e7-a823-080027a847bd

Master_Info_File: mysql.slave_master_info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

Replicate_Rewrite_DB:

Channel_Name:

Master_TLS_Version:

1 row in set (0.00 sec)

Mysql > use mysql

Database changed

Mysql > alter table slave_master_info engine=innodb

Query OK, 0 rows affected (0.23 sec)

Records: 0 Duplicates: 0 Warnings: 0

Mysql > alter table slave_relay_log_info engine=innodb

Query OK, 0 rows affected (0.08 sec)

Records: 0 Duplicates: 0 Warnings: 0

Mysql > alter table slave_worker_info engine=innodb

Query OK, 0 rows affected (0.08 sec)

Records: 0 Duplicates: 0 Warnings: 0

# # 3 configure mutual trust

[root@MHA1 ~] # ssh-keygen-t rsa # all nodes

Generating public/private rsa key pair.

Enter file in which to save the key (/ root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in / root/.ssh/id_rsa.

Your public key has been saved in / root/.ssh/id_rsa.pub.

The key fingerprint is:

E2:1c:6a:a3:ae:e5:38:0e:e7:cd:21:50:a5:14:d2:3b root@MHA1

The key's randomart image is:

+-[RSA 2048]-+

|.. o.. | |

| | o.o |

| | o. |

| | .e |

|. . O S |

|. + o |

|. + = o |

| | o* * o |

| | + = = o |

+-+

[root@MHA1 ~] # ssh slave1 cat / root/.ssh/id_rsa.pub > > / root/.ssh/authorized_keys

[root@MHA1 ~] # ssh slave2 cat / root/.ssh/id_rsa.pub > > / root/.ssh/authorized_keys

[root@MHA1 ~] # ssh master cat / root/.ssh/id_rsa.pub > > / root/.ssh/authorized_keys

[root@MHA1 ~] # ssh MHAManager cat / root/.ssh/id_rsa.pub > > / root/.ssh/authorized_keys

[root@MHA1 ~] # scp / root/.ssh/authorized_keys slave1:/root/.ssh/authorized_keys

[root@MHA1 ~] # scp / root/.ssh/authorized_keys slave2:/root/.ssh/authorized_keys

[root@MHA1 ~] # scp / root/.ssh/authorized_keys MHAManager:/root/.ssh/authorized_keys

[root@MHA1 ~] # ssh slave1 date;ssh slave2 date;ssh master date;ssh MHAManager date

Fri Apr 28 10:46:10 CST 2017

Fri Apr 28 10:46:14 CST 2017

Fri Apr 28 10:46:12 CST 2017

Fri Apr 28 10:46:13 CST 2017

[root@MHA1 ~] #

[root@MHA4 ~] # ssh slave1 date;ssh slave2 date;ssh master date;ssh MHAManager date

Fri Apr 28 10:46:10 CST 2017

Fri Apr 28 10:46:14 CST 2017

Fri Apr 28 10:46:12 CST 2017

Fri Apr 28 10:46:13 CST 2017

[root@MHA4 ~] #

# # 4 set read-only permissions on the slave server, and turn off automatic cleanup of relay logs (relay log)

[mysqld]

Read_only = 1

Relay_log_purge = 0

Mysql-uroot-p123456-e "set global read_only=on;"

Note:

Set read-only to prevent people from mistakenly writing on the slave server, and ensure the consistency of master-slave data.

Turn off the intermediate log after automatic cleanup is completed: if a slave does not accept the binlog of the master database, then you can send the intermediate log on the latest slave to the oldest slave through MHA, identify the differential intermediate log and make up the data.

If you want the database to delete the completed log automatically, you can do so through crontab. For example, you want to delete the relay log at 5 o'clock every day.

0 5 * / usr/local/mysql/bin/mysql-uroot-p123456-e "set global relay_log_purge=1;flush logs;set global relay_log_purge=0;flush logs;"

# # 5 configure MHA monitoring and management services

# create a mha management account

Mysql > grant all privileges on *. * to 'mhaadmin'@'%' identified by' 123456'

Query OK, 0 rows affected, 1 warning (0.54 sec)

Mysql > flush privileges

Query OK, 0 rows affected (0.23 sec)

# Editing MHA configuration file

#

# manager_workdir and remote_workdir are used to define the MHA management directory for storing logs.

# user and password are the administrative account passwords of MHA

# repl_user and repl_password are copied account passwords

# if your environment is a chained replication architecture, then try multi_tier_slave=1

# ping_interval=1 detects once a second

# ping_type, master_ip_failover_script, and master_ip_online_change_script define failover and online switchover

# secondary_check_script is to prevent network jitter from switching by mistake, resulting in data inconsistency. Principle: when the monitoring node is unable to connect to the mysql master library, the view will go to ping from other slave servers and connect to the mysql master library. Only if both parties fail to connect, the mysql master library will be considered to be down. If there is a connection in case the mysql master library can be connected, no switching will occur.

# ignore_fail=0 by default, when a Slave fails (for example, cannot connect through MySQL/SSH, SQL thread stops due to error, etc.), MHA does not enable failover; if set to 1, the corresponding Slave will automatically switch when it fails.

# candidate_master is used to set whether a Slave can be preferred as a Master. If set to 1, the corresponding Slave can first become the new Master;. If multiple Slave are set to 1, the priority of becoming Master is [server_1] / [server_2] /... Sort

The full path of the binlog log file of the main master_binlog_dir= MySQL library. The default is / var/lib/mysql, which is set to the real path according to the actual situation. This parameter applies to a situation where the Master instance fails, but the OS system is running normally, and the MHA can log in through SSH, and then read and copy the necessary binary log events (that is, differential logs). # it can be seen that this parameter is necessary and useful, because after Master dies, MHA cannot automatically get the path of the binlog log file. In addition, multiple paths can be set apart by commas.

# check_repl_delay by default, if a Slave latency exceeds the relay logs,MHA of 100MB, the Slave will not be selected as the new Master because it takes too long to recover. If this parameter is set to 0 Master, replication delay will be ignored when selecting a new MHA.

#

Vi / etc/mha.cnf

[server default]

User=mhaadmin

Password=123456

Manager_workdir=/usr/local/mha

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

Remote_workdir=/usr/local/mha

Ssh_user=root

Ssh_port=22

Repl_user=rep

Repl_password=123456

Ping_interval=1

Ping_type=CONNECT

Master_ip_failover_script=/usr/local/mha/scripts/master_ip_failover

Master_ip_online_change_script=/usr/local/mha/scripts/master_ip_online_change

Secondary_check_script=/usr/bin/masterha_secondary_check-s 192.168.56.222-s 192.168.56.223-s 192.168.56.224-- user=root-- master_host=master-- master_ip=192.168.56.221-- master_port=3306

[server1]

Ignore_fail=0

Check_repl_delay=1

Hostname=MHA1

Ip=192.168.56.221

Ssh_port=22

Port=3306

Master_binlog_dir=/usr/local/mysql/logs/

Candidate_master=1

[server2]

Ignore_fail=0

Check_repl_delay=1

Hostname=MHA2

Ip=192.168.56.222

Ssh_port=22

Port=3306

Master_binlog_dir=/usr/local/mysql/logs/

Candidate_master=1

[server3]

Ignore_fail=0

Check_repl_delay=1

Hostname=MHA3

Ip=192.168.56.223

Ssh_port=22

Port=3306

Master_binlog_dir=/usr/local/mysql/logs/

Candidate_master=1

# # using tools to detect ssh

[root@MHA4 logs] # masterha_check_ssh-- conf=/etc/mha.cnf

Fri Apr 28 15:11:14 2017-[warning] Global configuration file / etc/masterha_default.cnf not found. Skipping.

Fri Apr 28 15:11:14 2017-[info] Reading application default configurations from / etc/mha.cnf..

Fri Apr 28 15:11:14 2017-[info] Reading server configurations from / etc/mha.cnf..

Fri Apr 28 15:11:14 2017-[info] Starting SSH connection tests..

Fri Apr 28 15:11:17 2017-[debug]

Fri Apr 28 15:11:15 2017-[debug] Connecting via SSH from root@master (192.168.56.221) to root@slave1 (192.168.56.222)..

Fri Apr 28 15:11:15 2017-[debug] ok.

Fri Apr 28 15:11:15 2017-[debug] Connecting via SSH from root@master (192.168.56.221) to root@slave2 (192.168.56.223)..

Fri Apr 28 15:11:17 2017-[debug] ok.

Fri Apr 28 15:11:17 2017-[debug]

Fri Apr 28 15:11:15 2017-[debug] Connecting via SSH from root@slave1 (192.168.56.222) to root@master (192.168.56.221)..

Fri Apr 28 15:11:16 2017-[debug] ok.

Fri Apr 28 15:11:16 2017-[debug] Connecting via SSH from root@slave1 (192.168.56.222) to root@slave2 (192.168.56.223)..

Fri Apr 28 15:11:17 2017-[debug] ok.

Fri Apr 28 15:11:17 2017-[debug]

Fri Apr 28 15:11:16 2017-[debug] Connecting via SSH from root@slave2 (192.168.56.223) to root@master (192.168.56.221)..

Fri Apr 28 15:11:17 2017-[debug] ok.

Fri Apr 28 15:11:17 2017-[debug] Connecting via SSH from root@slave2 (192.168.56.223) to root@slave1 (192.168.56.222)..

Fri Apr 28 15:11:17 2017-[debug] ok.

Fri Apr 28 15:11:17 2017-[info] All SSH connection tests passed successfully.

[root@MHA4] # masterha_check_repl-- conf=/etc/mha.cnf

Fri Apr 28 16:12:44 2017-[info] / usr/local/mha/scripts/master_ip_failover-command=status-ssh_user=root-orig_master_host=MHA1-orig_master_ip=192.168.56.221-orig_master_port=3306

Bareword "FIXME_xxx" not allowed while "strict subs" in use at / usr/local/mha/scripts/master_ip_failover line 93.

Execution of / usr/local/mha/scripts/master_ip_failover aborted due to compilation errors.

Fri Apr 28 16:12:44 2017-[error] [/ usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln216] Failed to get master_ip_failover_script status with return code 255 ln216 0.

Fri Apr 28 16:12:44 2017-[error] [/ usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln386] Error happend on checking configurations. At / usr/bin/masterha_check_repl line 48

Fri Apr 28 16:12:44 2017-[error] [/ usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln482] Error happened on monitoring servers.

Fri Apr 28 16:12:44 2017-[info] Got exit code 1 (Not master dead).

MySQL Replication Health is NOT OK!

Solution:

[root@MHA4 ~] # grep master_ip_failover / etc/mha.cnf

# master_ip_failover_script=/usr/local/mha/scripts/master_ip_failover

# check master-slave replication again

[root@MHA4] # masterha_check_repl-- conf=/etc/mha.cnf

Fri Apr 28 16:21:55 2017-[info] Slaves settings check done.

Fri Apr 28 16:21:55 2017-[info]

MHA1 (current master)

+-- MHA2

+-- MHA3

Fri Apr 28 16:21:55 2017-[info] Checking replication health on MHA2..

Fri Apr 28 16:21:55 2017-[info] ok.

Fri Apr 28 16:21:55 2017-[info] Checking replication health on MHA3..

Fri Apr 28 16:21:55 2017-[info] ok.

Fri Apr 28 16:21:55 2017-[warning] master_ip_failover_script is not defined.

Fri Apr 28 16:21:55 2017-[warning] shutdown_script is not defined.

Fri Apr 28 16:21:55 2017-[info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

# check mha Manager status

[root@MHA4] # masterha_check_status-- conf=/etc/mha.cnf

Mha is stopped (2:NOT_RUNNING).

Note: if normal, "PING_OK" will be displayed, otherwise "NOT_RUNNING" will be displayed, which means that MHA monitoring is not turned on.

# enable Manager service

[root@MHA4] # nohup masterha_manager-conf=/etc/mha.cnf-remove_dead_master_conf-ignore_last_failover

< /dev/null >

/ usr/local/mha/manager.log 2 > & 1 &

[1] 5073

Introduction of startup parameters:

-- remove_dead_master_conf this parameter means that when a master-slave switch occurs, the ip of the old master library will be removed from the configuration file.

-- location of manger_log logs

-- ignore_last_failover by default, if MHA detects continuous downtime and the interval between two outages is less than 8 hours, Failover will not be performed. This restriction is to avoid ping-pong effect. This parameter means that the file generated by the last MHA trigger switch is ignored. By default, after the MHA switch occurs, the app1.failover.complete file will be generated in the log directory, that is, the / data I set above. The switch will not be triggered if the file is found to exist in the directory next time, unless the file is deleted after the first switch. For convenience, it is set to-- ignore_last_failover here.

[root@MHA4] # masterha_check_status-- conf=/etc/mha.cnf

Mha (pid:5073) is running (0:PING_OK), master:MHA1

[root@MHA4] # tail-f / usr/local/mha/manager.log

# # stop MHA Manager Service

[root@MHA4] # masterha_stop-- conf=/etc/mha.cnf

Stopped mha successfully.

[1] + Exit 1 nohup masterha_manager-conf=/etc/mha.cnf-remove_dead_master_conf-ignore_last_failover

< /dev/null >

/ usr/local/mha/manager.log 2 > & 1

[root@MHA4 ~] #

# # 6. Manage and switch VIP with MHA

[root@MHA1] # / sbin/ifconfig eth2:1 192.168.56.225

[root@MHA1 ~] # ifconfig

Eth2 Link encap:Ethernet HWaddr 08:00:27:8B:0A:CE

Inet addr:192.168.56.221 Bcast:192.168.56.255 Mask:255.255.255.0

Inet6 addr: fe80::a00:27ff:fe8b:ace/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:3348 errors:0 dropped:0 overruns:0 frame:0

TX packets:2758 errors:0 dropped:0 overruns:0 carrier:0

Collisions:0 txqueuelen:1000

RX bytes:316425 (309.0 KiB) TX bytes:292848 (285.9 KiB)

Eth2:1 Link encap:Ethernet HWaddr 08:00:27:8B:0A:CE

Inet addr:192.168.56.225 Bcast:192.168.56.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

Lo Link encap:Local Loopback

Inet addr:127.0.0.1 Mask:255.0.0.0

Inet6 addr: 1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:4 errors:0 dropped:0 overruns:0 frame:0

TX packets:4 errors:0 dropped:0 overruns:0 carrier:0

Collisions:0 txqueuelen:0

RX bytes:240 (240.0 b) TX bytes:240 (240.0 b)

# Editing master_ip_failover_script script

#! / 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.56.225 Universe 24'

My $key ='1'

My $ssh_start_vip = "/ sbin/ifconfig eth2:$key $vip"

My $ssh_stop_vip = "/ sbin/ifconfig eth2:$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") {

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") {

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"

Exit 0

}

Else {

& usage ()

Exit 1

}

}

Sub start_vip () {

`ssh $ssh_user\ @ $new_master_host\ "$ssh_start_vip\" `

}

Sub stop_vip () {

Return 0 unless ($ssh_user)

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

}

# # 7 Test MHA failover and log catch-up

# Master server

[root@MHA1] # pkill-9 mysqld

[root@MHA4] # tail-f / usr/local/mha/manager.log

.

-Failover Report-

Mha: MySQL Master failover MHA1 to MHA2 succeeded

Master MHA1 is down!

Check MHA Manager logs at MHA4:/usr/local/mha/manager.log for details.

Started automated (non-interactive) failover.

Invalidated master IP address on MHA1.

The latest slave MHA2 (192.168.56.222) has all relay logs for recovery.

Selected MHA2 as a new master.

MHA2: OK: Applying all logs succeeded.

MHA2: OK: Activated master IP address.

MHA3: This host has the latest relay log events.

Generating relay diff files from the latest slave succeeded.

MHA3: OK: Applying all logs succeeded. Slave started, replicating from MHA2.

MHA2: Resetting slave info succeeded.

Master failover to MHA2 (192.168.56.222) completed successfully.

After the switch is completed, the manager service of MHA will stop. It is necessary to adjust the server option in the configuration file of MHA and put the master server under the content of server1. Modify the content of secondary_check_script.

[root@MHA4 ~] # vi / etc/mha.cnf

[server default]

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

Manager_workdir=/usr/local/mha

Master_ip_failover_script=/usr/local/mha/scripts/master_ip_failover

Master_ip_online_change_script=/usr/local/mha/scripts/master_ip_online_change

Password=123456

Ping_interval=1

Ping_type=CONNECT

Remote_workdir=/usr/local/mha

Repl_password=123456

Repl_user=rep

Secondary_check_script=/usr/bin/masterha_secondary_check-s 192.168.56.221-s 192.168.56.223-s 192.168.56.224-- user=root-- master_host=MHA2-- master_ip=192.168.56.222--master_port=3306

Ssh_port=22

Ssh_user=root

User=mhaadmin

[server1]

Candidate_master=1

Check_repl_delay=1

Hostname=MHA2

Ignore_fail=0

Ip=192.168.56.222

Master_binlog_dir=/usr/local/mysql/logs/

Port=3306

Ssh_port=22

[server2]

Candidate_master=1

Check_repl_delay=1

Hostname=MHA1

Ignore_fail=0

Ip=192.168.56.221

Master_binlog_dir=/usr/local/mysql/logs/

Port=3306

Ssh_port=22

[server3]

Candidate_master=1

Check_repl_delay=1

Hostname=MHA3

Ignore_fail=0

Ip=192.168.56.223

Master_binlog_dir=/usr/local/mysql/logs/

Port=3306

Ssh_port=22

# modify when the configuration file of the original main library opens the slave parameters, modify the current configuration file of the main library, comment out the slave parameters, and restart the mysql server

# slave

# relay_log=/usr/local/mysql/logs/relay-log.log

# master-info-repository=TABLE

# relay-log-info-repository=TABLE

# sync_master_info = 1

# sync_relay_log = 1

# sync_relay_log_info = 1

# read_only = 1

Relay_log_purge = 0

[root@MHA2 ~] # / etc/init.d/mysqld restart

Shutting down MySQL. [OK]

Starting MySQL. [OK]

# check the configuration file of MHA and start MHA service

[root@MHA4] # masterha_check_ssh-- conf=/etc/mha.cnf

Wed May 3 13:38:32 2017-[warning] Global configuration file / etc/masterha_default.cnf not found. Skipping.

Wed May 3 13:38:32 2017-[info] Reading application default configurations from / etc/mha.cnf..

Wed May 3 13:38:32 2017-[info] Reading server configurations from / etc/mha.cnf..

Wed May 3 13:38:32 2017-[info] Starting SSH connection tests..

Wed May 3 13:38:33 2017-[debug]

Wed May 3 13:38:32 2017-[debug] Connecting via SSH from root@MHA2 (192.168.56.221) to root@MHA2 (192.168.56.222)..

Wed May 3 13:38:33 2017-[debug] ok.

Wed May 3 13:38:33 2017-[debug] Connecting via SSH from root@MHA2 (192.168.56.221) to root@MHA3 (192.168.56.223)..

Wed May 3 13:38:33 2017-[debug] ok.

Wed May 3 13:38:33 2017-[debug]

Wed May 3 13:38:33 2017-[debug] Connecting via SSH from root@MHA3 (192.168.56.223) to root@MHA2 (192.168.56.222)..

Wed May 3 13:38:33 2017-[debug] ok.

Wed May 3 13:38:33 2017-[debug] Connecting via SSH from root@MHA3 (192.168.56.223) to root@MHA2 (192.168.56.221)..

Wed May 3 13:38:33 2017-[debug] ok.

Wed May 3 13:38:33 2017-[info] All SSH connection tests passed successfully.

[root@MHA4] # masterha_check_repl-- conf=/etc/mha.cnf

Wed May 3 13:38:56 2017-[warning] Global configuration file / etc/masterha_default.cnf not found. Skipping.

Wed May 3 13:38:56 2017-[info] Reading application default configurations from / etc/mha.cnf..

Wed May 3 13:38:56 2017-[info] Reading server configurations from / etc/mha.cnf..

Wed May 3 13:38:56 2017-[info] MHA::MasterMonitor version 0.55.

Wed May 3 13:38:56 2017-[error] [/ usr/share/perl5/vendor_perl/MHA/Server.pm, ln241] Getting relay log directory or current relay logfile from replication table failed on MHA2 (192.168.56.222)!

Wed May 3 13:38:56 2017-[error] [/ usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln386] Error happend on checking configurations. At / usr/share/perl5/vendor_perl/MHA/ServerManager.pm line 269

Wed May 3 13:38:56 2017-[error] [/ usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln482] Error happened on monitoring servers.

Wed May 3 13:38:56 2017-[info] Got exit code 1 (Not master dead).

MySQL Replication Health is NOT OK!

Note that the slave parameter relay-log and other parameters of the main library have been enabled, so check it, just comment out and restart it.

Thank you for reading, the above is the content of "installation and testing of MHA". After the study of this article, I believe you have a deeper understanding of the installation and testing of MHA, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report