MHA的安装搭建和测试
这篇文章主要讲解了“MHA的安装搭建和测试”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“MHA的安装搭建和测试”吧!
专业成都网站建设公司,做排名好的好网站,排在同行前面,为您带来客户和效益!创新互联公司为您提供成都网站建设,五站合一网站设计制作,服务好的网站设计公司,成都做网站、成都网站制作负责任的成都网站制作公司!
环境:
192.168.56.221 MHA1
192.168.56.222 MHA2
192.168.56.223 MHA3
192.168.56.224 MHA4
#221为master 222位slave 223为slave 224为管理节点
##1 安装MHA软件包
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
常用rpm搜索网站:
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 #所有节点安装
[root@MHA1 ~]# yum localinstall mha4mysql-manager-0.55-0.el6.noarch.rpm #管理节点安装
##2 主从同步配置:
#主服务器
mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.53 sec)
mysql> grant replication slave on *.* to 'rep'@'%' identified by '123456'; #建议所有mysql服务器配置,以防主从切换
Query OK, 0 rows affected, 1 warning (0.17 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
#从服务器
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 配置互信
[root@MHA1 ~]# ssh-keygen -t rsa #所有节点
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 slave服务器上设置只读权限,并关闭自动清除执行完毕的中继日志(relay log)
[mysqld]
read_only = 1
relay_log_purge = 0
mysql -uroot -p123456 -e "set global read_only=on;"
注意:
设置只读是防止人在slave服务器上误写入,保证主从数据一致
关闭自动清除执行完毕的中级日志是:假如一台从库没有接受完主库的binlog,那么可以通过MHA把最新的slave上的中级日志发送到最老的slave上,识别差异中级日志并补齐数据
如果想数据库自动删除执行完毕的日志,可以通过crontab实现,例如想要每天5点删除中继日志
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 配置MHA监控、管理服务
#创建mha管理账号
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)
#编辑MHA配置文件
############
#manager_workdir和remote_workdir用来定义MHA管理目录,以便存放日志。
#user和password为MHA的管理账号密码
#repl_user和repl_password为复制的账号密码
#如果你的环境是链式复制架构,那么试着multi_tier_slave=1
#ping_interval=1每个一秒检测一次
#ping_type、master_ip_failover_script和master_ip_online_change_script定义故障切换和在线切换
#secondary_check_script是为了防止网络抖动误切换,造成数据不一致。原理:当监控节点无法连接mysql主库是,会视图从其他从服务器去ping和连接mysql主库,只有双方都连接失败,才认定mysql主库宕机,如果有以防可以连接mysql主库,则不发生切换
#ignore_fail=0缺省情况下,当某个Slave故障时(比如:不能通过MySQL/SSH连接,SQL线程因错误停止等),MHA不开启故障切换;若设置为1,则对应的那个Slave出现故障时自动切换。
#candidate_master用于设置某个Slave是否可以优先成为Master。若设置为1,则对应的那个Slave可优先成为新的Master;若多个Slave均设置该参数为1,则成为Master的优先级按照[server_1]/[server_2]/…排序;
#master_binlog_dir= MySQL主库的binlog日志文件的全路径,缺省为/var/lib/mysql,根据实际情况设置为真实的路径。该参数适用于这么一种情况:Master实例故障,但OS系统运行正常,此时MHA可通过SSH登录,然后读取并拷贝必须的二进制日志事件(即差异的日志)。#可见该参数是必要而有用的,因为Master死掉后,MHA无法自动获取binlog日志文件的路径。另外,可用逗号隔开设置多个路径。
#check_repl_delay 缺省情况下,如果某个Slave延迟超过100MB的relay logs,MHA则不会选择该Slave成为新的Master,因为这需要太长的时间来恢复。若设置该参数为0,MHA在选择新的Master时,会忽略复制延迟。
############
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
##使用工具检测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:22) to root@slave1(192.168.56.222:22)..
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:22) to root@slave2(192.168.56.223:22)..
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:22) to root@master(192.168.56.221:22)..
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:22) to root@slave2(192.168.56.223:22)..
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:22) to root@master(192.168.56.221:22)..
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:22) to root@slave1(192.168.56.222:22)..
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: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!
解决方案:
[root@MHA4 ~]# grep master_ip_failover /etc/mha.cnf
#master_ip_failover_script=/usr/local/mha/scripts/master_ip_failover
#再次检查主从复制
[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.
#检查mha Manager状态
[root@MHA4 ~]# masterha_check_status --conf=/etc/mha.cnf
mha is stopped(2:NOT_RUNNING).
注意:如果正常,会显示"PING_OK",否则会显示"NOT_RUNNING",这代表MHA监控没有开启。
#开启Manager服务
[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
启动参数介绍:
--remove_dead_master_conf 该参数代表当发生主从切换后,老的主库的ip将会从配置文件中移除。
--manger_log 日志存放位置
--ignore_last_failover 在缺省情况下,如果MHA检测到连续发生宕机,且两次宕机间隔不足8小时的话,则不会进行Failover,之所以这样限制是为了避免ping-pong效应。该参数代表忽略上次MHA触发切换产生的文件,默认情况下,MHA发生切换后会在日志目录,也就是上面我设置的/data产生app1.failover.complete文件,下次再次切换的时候如果发现该目录下存在该文件将不允许触发切换,除非在第一次切换后收到删除该文件,为了方便,这里设置为--ignore_last_failover。
[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
##停止MHA Manager服务
[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 MHA 管理和切换VIP
[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)
#编辑master_ip_failover_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/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 { "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 测试MHA 故障切换和日志追赶
#主服务器
[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:3306) 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:3306) completed successfully.
切换完成后,MHA的manager服务就会停止,这是需要把MHA的配置文件中的server选项调整,把主服务器放在server1的内容下。把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
#修改当原主库的配置文件把slave参数开放,修改当前主库配置文件把slave参数注释掉,重启mysql服务器
#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 ]
#检查MHA的配置文件和启动MHA服务
[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:22) to root@MHA2(192.168.56.222:22)..
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:22) to root@MHA3(192.168.56.223:22)..
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:22) to root@MHA2(192.168.56.222:22)..
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:22) to root@MHA2(192.168.56.221:22)..
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:3306)!
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!
注意主库的slave参数relay-log等参数已经开启,所以检查不过,注释掉重启就可以了
感谢各位的阅读,以上就是“MHA的安装搭建和测试”的内容了,经过本文的学习后,相信大家对MHA的安装搭建和测试这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
网页标题:MHA的安装搭建和测试
文章地址:http://scjbc.cn/article/gjhjoi.html