Preface
 
    MasterHA is a tool which can be used in MySQL HA architecture.I'm gonna implement it and have some tests depend on it later.
 
Framework
 
Hostname IP Port Identity OS Version MySQL Version
zlm2 192.168.1.101 3306 master CentOS 7.0 5.7.21
zlm3 192.168.1.102 3306 slave/mha-manager CentOS 7.0 5.7.21
null 192.168.1.200 null vip null null
 
Procedure
 
Downlaod the rpm package of MasterHA using below web link first:
MasterHA's wiki document.
 
Configure ssh authentication between zlm2 and zlm3 from each other.
 [root@zlm2 :: ~]
#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:
:::af:d7::3c::f3:0e:bc:ea::f1:bc: root@zlm2
The key's randomart image is:
+--[ RSA ]----+
| o. |
| . . . |
| + . + |
| o o . . + + |
| . S . o B .|
| . =E= |
| o.+ .|
| . o.. |
| .o .. |
+-----------------+ [root@zlm2 :: ~]
#cd .ssh [root@zlm2 :: ~/.ssh]
#ls -l
total
-rw------- root root Aug : id_rsa
-rw-r--r-- root root Aug : id_rsa.pub
-rw-r--r-- root root Jun : known_hosts [root@zlm2 :: ~/.ssh]
#cat id_rsa.pub >> authorized_keys [root@zlm2 :: ~/.ssh]
#scp ./* zlm3:~/.ssh/
root@zlm3's password:
authorized_keys 100% 391 0.4KB/s 00:00
id_rsa 100% 1675 1.6KB/s 00:00
id_rsa.pub 100% 391 0.4KB/s 00:00
known_hosts 100% 360 0.4KB/s 00:00 [root@zlm2 09:08:22 ~/.ssh]
#ssh zlm3
Last login: Thu Aug 2 08:47:54 2018 from 192.168.1.1
Welcome to your Vagrant-built virtual machine. [root@zlm3 09:10:39 ~]
# [root@zlm3 09:11:13 ~/.ssh]
#ssh zlm2
The authenticity of host 'zlm2 (192.168.1.101)' can't be established.
ECDSA key fingerprint is 75:06:22:b7:e2:3b:46:88:51:97:c4:4f:27:20:21:26.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'zlm2,192.168.1.101' (ECDSA) to the list of known hosts.
Last login: Thu Aug 2 03:29:04 2018 from 192.168.1.1
Welcome to your Vagrant-built virtual machine. [root@zlm2 09:11:22 ~]
#
Configure a master-slave replication.
 
 [root@zlm2 :: ~]
#scp db3306_20180802.sql zlm3:~/
db3306_20180802.sql % 8429KB .2MB/s : [root@zlm3 :: ~]
#mysql < db3306_20180802.sql
ERROR (HY000) at line : @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty. [root@zlm3 :: ~]
#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (zlm@192.168.1.102 )[(none)]>reset master;
Query OK, rows affected (0.03 sec) (zlm@192.168.1.102 )[(none)]>exit
Bye [root@zlm3 :: ~]
#mysql < db3306_20180802.sql [root@zlm3 :: ~]
#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (zlm@192.168.1.102 )[(none)]>change master to \
-> master_host='192.168.1.101',\
-> master_port=,\
-> master_user='repl',\
-> master_password='repl4slave',\
-> master_auto_position=;
Query OK, rows affected, warnings (0.02 sec) (zlm@192.168.1.102 )[(none)]>start slave;
Query OK, rows affected (0.00 sec) (zlm@192.168.1.102 )[(none)]>show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.101
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 1b7181ee-6eaf-11e8-998e-080027de0e0e
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: 1b7181ee-6eaf-11e8-998e-080027de0e0e:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec)

Install dependency packge first.

 [root@zlm2 :: ~]
#yum install -y perl-Time-HiRes perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager [root@zlm2 :: ~]
#ssh zlm3
Last login: Thu Aug :: from 192.168.1.101
Welcome to your Vagrant-built virtual machine. [root@zlm3 :: ~]
#yum install -y perl-Time-HiRes perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager
Install both manager and node rpm on master and slave.
 [root@zlm2 :: ~]
#rpm -ivh mha4mysql-manager-0.56-.el6.noarch.rpm
error: Failed dependencies:
mha4mysql-node >= 0.54 is needed by mha4mysql-manager-0.56-.el6.noarch
perl(MHA::BinlogManager) is needed by mha4mysql-manager-0.56-.el6.noarch
perl(MHA::NodeConst) is needed by mha4mysql-manager-0.56-.el6.noarch
perl(MHA::NodeUtil) is needed by mha4mysql-manager-0.56-.el6.noarch
perl(MHA::SlaveUtil) is needed by mha4mysql-manager-0.56-.el6.noarch [root@zlm2 :: ~]
#rpm -ivh mha4mysql-node-0.56-.el6.noarch.rpm
Preparing... ################################# [%]
Updating / installing...
:mha4mysql-node-0.56-.el6 ################################# [%] [root@zlm2 :: ~]
#rpm -ivh mha4mysql-manager-0.56-.el6.noarch.rpm
Preparing... ################################# [%]
Updating / installing...
:mha4mysql-manager-0.56-.el6 ################################# [%] [root@zlm2 :: ~]
#ssh zlm3
Last login: Thu Aug :: from 192.168.1.101
Welcome to your Vagrant-built virtual machine. [root@zlm3 :: ~]
#rpm -ivh mha4mysql-node-0.56-.el6.noarch.rpm
Preparing... ################################# [%]
Updating / installing...
:mha4mysql-node-0.56-.el6 ################################# [%] [root@zlm3 :: ~]
#rpm -ivh mha4mysql-manager-0.56-.el6.noarch.rpm
Preparing... ################################# [%]
Updating / installing...
:mha4mysql-manager-0.56-.el6 ################################# [%]
Configure the conf files on each manager node.
 [root@zlm2 :: ~]
#mkdir -p /var/log/masterha/app1 [root@zlm2 :: ~]
#mkdir /etc/masterha [root@zlm2 :: ~]
#cp /vagrant/masterha/* /etc/masterha/ [root@zlm2 09:50:02 ~]
#cd /etc/masterha/ [root@zlm2 09:50:09 /etc/masterha]
#ll
total 36
-rwxr-xr-x 1 root root 614 Aug 2 09:50 app1.conf
-rwxr-xr-x 1 root root 55 Aug 2 09:50 drop_vip.sh
-rwxr-xr-x 1 root root 55 Aug 2 09:50 init_vip.sh
-rwxr-xr-x 1 root root 384 Aug 2 09:50 masterha_default.conf
-rwxr-xr-x 1 root root 4438 Aug 2 09:50 master_ip_failover
-rwxr-xr-x 1 root root 10526 Aug 2 09:50 master_ip_online_change [root@zlm2 09:51:46 /etc/masterha]
#cat masterha_default.conf
[server default]
#log_level=debug
user=zlm
password=zlmzlm ssh_user=root
ssh_port=3306 repl_user=repl
repl_password=repl4slave ping_interval=1
#shutdown_script="" master_ip_failover_script= /etc/masterha/master_ip_failover
master_ip_online_change_script= /etc/masterha/master_ip_online_change [root@zlm2 09:53:56 /etc/masterha]
#cat app1.conf
[server default] manager_workdir = /var/log/masterha/app1
manager_log = /var/log/masterha/app1/app1.log
remote_workdir = /var/log/masterha/app1 [server1]
hostname=192.168.1.101
master_binlog_dir = /data/mysql/mysql3306/logs
candidate_master = 1
check_repl_delay = 0 [server2]
hostname=192.168.1.102
master_binlog_dir=/data/mysql/mysql3306/logs
candidate_master=1
check_repl_delay=0 [root@zlm2 09:56:20 /etc/masterha]
#cat init_vip.sh
vip="192.168.1.200/24"
/sbin/ip addr add $vip dev enp0s8 [root@zlm2 09:56:23 /etc/masterha]
#cat drop_vip.sh
vip="192.168.1.200/24"
/sbin/ip addr del $vip dev enp0s8 [root@zlm2 09:57:27 /etc/masterha]
#ssh zlm3
Last login: Thu Aug 2 09:40:20 2018 from 192.168.1.1
Welcome to your Vagrant-built virtual machine. [root@zlm3 09:58:04 ~]
#mkdir -p /var/log/masterha/app1 [root@zlm3 09:58:16 ~]
#mkdir /etc/masterha [root@zlm3 09:58:30 ~]
#scp zlm2:/etc/masterha/* /etc/masterha
app1.conf 100% 498 0.5KB/s 00:00
drop_vip.sh 100% 57 0.1KB/s 00:00
init_vip.sh 100% 57 0.1KB/s 00:00
masterha_default.conf 100% 387 0.4KB/s 00:00
master_ip_failover 100% 4438 4.3KB/s 00:00
master_ip_online_change 100% 10KB 10.3KB/s 00:00
Check the masterha status on both nodes..
 [root@zlm2 :: /etc/masterha]
#masterha_
masterha_check_repl masterha_check_status masterha_manager masterha_master_switch masterha_stop
masterha_check_ssh masterha_conf_host masterha_master_monitor masterha_secondary_check [root@zlm2 :: /etc/masterha]
#masterha_check_status --conf=./app1.conf
app1 is stopped(:NOT_RUNNING). [root@zlm2 :: /etc/masterha]
#masterha_check_ssh --conf=./app1.conf
Thu Aug :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Aug :: - [info] Reading application default configuration from ./app1.conf..
Thu Aug :: - [info] Reading server configuration from ./app1.conf..
Thu Aug :: - [info] Starting SSH connection tests..
Thu Aug :: - [debug]
Thu Aug :: - [debug] Connecting via SSH from root@192.168.1.101(192.168.1.101:) to root@192.168.1.102(192.168.1.102:)..
Warning: Permanently added '192.168.1.101' (ECDSA) to the list of known hosts.
Thu Aug :: - [debug] ok.
Thu Aug :: - [debug]
Thu Aug :: - [debug] Connecting via SSH from root@192.168.1.102(192.168.1.102:) to root@192.168.1.101(192.168.1.101:)..
Thu Aug :: - [debug] ok.
Thu Aug :: - [info] All SSH connection tests passed successfully. [root@zlm2 :: /etc/masterha]
#masterha_check_repl --conf=./app1.conf
Thu Aug :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Aug :: - [info] Reading application default configuration from ./app1.conf..
Thu Aug :: - [info] Reading server configuration from ./app1.conf..
Thu Aug :: - [info] MHA::MasterMonitor version 0.56.
Thu Aug :: - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm, ln301] Got MySQL error when connecting 192.168.1.101(192.168.1.101:) ::Access denied for user 'root'@'zlm2' (using password: NO), but this is not a MySQL crash. Check MySQL server settings.
at /usr/share/perl5/vendor_perl/MHA/ServerManager.pm line .
Thu Aug :: - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm, ln301] Got MySQL error when connecting 192.168.1.102(192.168.1.102:) ::Access denied for user 'root'@'zlm2' (using password: NO), but this is not a MySQL crash. Check MySQL server settings.
at /usr/share/perl5/vendor_perl/MHA/ServerManager.pm line .
Thu Aug :: - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm, ln309] Got fatal error, stopping operations
Thu Aug :: - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln424] Error happened on checking configurations. at /usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm line .
Thu Aug :: - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln523] Error happened on monitoring servers.
Thu Aug :: - [info] Got exit code (Not master dead). MySQL Replication Health is NOT OK! [root@zlm2 :: /etc/masterha]
#masterha_check_repl --conf=./app1.conf --global_conf=./masterha_default.conf //The "--global_conf" option is indispensable.
Thu Aug :: - [info] Reading default configuration from /etc/masterha/masterha_default.conf..
Thu Aug :: - [info] Reading application default configuration from ./app1.conf..
Thu Aug :: - [info] Reading server configuration from ./app1.conf..
Thu Aug :: - [info] MHA::MasterMonitor version 0.56.
Thu Aug :: - [info] GTID failover mode =
Thu Aug :: - [info] Dead Servers:
Thu Aug :: - [info] Alive Servers:
Thu Aug :: - [info] 192.168.1.101(192.168.1.101:)
Thu Aug :: - [info] 192.168.1.102(192.168.1.102:)
Thu Aug :: - [info] Alive Slaves:
Thu Aug :: - [info] 192.168.1.102(192.168.1.102:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Thu Aug :: - [info] GTID ON
Thu Aug :: - [info] Replicating from 192.168.1.101(192.168.1.101:)
Thu Aug :: - [info] Primary candidate for the new Master (candidate_master is set)
Thu Aug :: - [info] Current Alive Master: 192.168.1.101(192.168.1.101:)
Thu Aug :: - [info] Checking slave configurations..
Thu Aug :: - [info] read_only= is not set on slave 192.168.1.102(192.168.1.102:).
Thu Aug :: - [info] Checking replication filtering settings..
Thu Aug :: - [info] binlog_do_db= , binlog_ignore_db=
Thu Aug :: - [info] Replication filtering check ok.
Thu Aug :: - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Thu Aug :: - [info] Checking SSH publickey authentication settings on the current master..
ssh_exchange_identification: Connection closed by remote host
Thu Aug :: - [warning] HealthCheck: SSH to 192.168.1.101 is NOT reachable.
Thu Aug :: - [info]
192.168.1.101(192.168.1.101:) (current master)
+--192.168.1.102(192.168.1.102:) Thu Aug :: - [info] Checking replication health on 192.168.1.102..
Thu Aug :: - [info] ok.
Thu Aug :: - [info] Checking master_ip_failover_script status:
Thu Aug :: - [info] /etc/masterha/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.1.101 --orig_master_ip=192.168.1.101 --orig_master_port= --orig_master_ssh_port=
Thu Aug :: - [info] OK.
Thu Aug :: - [warning] shutdown_script is not defined.
Thu Aug :: - [info] Got exit code (Not master dead). MySQL Replication Health is OK. //Do these above checking operations on zlm3,too.
Start MasterHA-manager and check the status.
 [root@zlm2 :: /etc/masterha]
#masterha_manager --conf=./app1.conf --global_conf=./masterha_default.conf &
[] [root@zlm2 :: /etc/masterha]
#Thu Aug :: - [info] Reading default configuration from ./masterha_default.conf..
Thu Aug :: - [info] Reading application default configuration from ./app1.conf..
Thu Aug :: - [info] Reading server configuration from ./app1.conf..
ssh_exchange_identification: Connection closed by remote host
^C [root@zlm2 :: /etc/masterha]
#masterha_check_status --conf=./app1.conf
app1 (pid:) is running(:PING_OK), master:192.168.1.101 [root@zlm2 :: /etc/masterha]
#cd /var/log/masterha/app1 [root@zlm2 :: /var/log/masterha/app1]
#ls -l
total
-rw-r--r-- root root Aug : app1.log
-rw-r--r-- root root Aug : app1.master_status.health [root@zlm2 :: /var/log/masterha/app1]
#tail app1.log
+--192.168.1.102(192.168.1.102:) Thu Aug :: - [info] Checking master_ip_failover_script status:
Thu Aug :: - [info] /etc/masterha/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.1.101 --orig_master_ip=192.168.1.101 --orig_master_port= --orig_master_ssh_port=
Thu Aug :: - [info] OK.
Thu Aug :: - [warning] shutdown_script is not defined.
Thu Aug :: - [info] Set master ping interval seconds.
Thu Aug :: - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.
Thu Aug :: - [info] Starting ping health check on 192.168.1.101(192.168.1.101:)..
Thu Aug :: - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond.. [root@zlm2 :: /var/log/masterha/app1]
#tail app1.master_status.health
:PING_OK master:192.168.1.101

MySQL高可用之MHA安装的更多相关文章

  1. MySQL高可用之MHA (转)

    MySQL高可用之MHA MHA简介 MHA是由日本人yoshinorim(原就职于DeNA现就职于FaceBook)开发的比较成熟的MySQL高可用方案.MHA能够在30秒内实现故障切换,并能在故障 ...

  2. mysql高可用方案MHA介绍

    mysql高可用方案MHA介绍 概述 MHA是一位日本MySQL大牛用Perl写的一套MySQL故障切换方案,来保证数据库系统的高可用.在宕机的时间内(通常10-30秒内),完成故障切换,部署MHA, ...

  3. MySQL高可用方案--MHA部署及故障转移

    架构设计及必要配置 主机环境 IP                 主机名             担任角色 192.168.192.128  node_master    MySQL-Master| ...

  4. 【DB宝42】MySQL高可用架构MHA+ProxySQL实现读写分离和负载均衡

    目录 一.MHA+ProxySQL架构 二.快速搭建MHA环境 2.1 下载MHA镜像 2.2 编辑yml文件,创建MHA相关容器 2.3 安装docker-compose软件(若已安装,可忽略) 2 ...

  5. MySQL高可用方案MHA自动Failover与手动Failover的实践及原理

    集群信息 角色                             IP地址                 ServerID      类型 Master                     ...

  6. MySQL高可用方案MHA在线切换的步骤及原理

    在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小. MHA就提 ...

  7. MySQL高可用之MHA的搭建 转

     http://www.cnblogs.com/muhu/p/4045780.html http://www.cnblogs.com/gomysql/p/3675429.html http://www ...

  8. MySQL高可用方案MHA的部署和原理

    MHA(Master High Availability)是一套相对成熟的MySQL高可用方案,能做到在0~30s内自动完成数据库的故障切换操作,在master服务器不宕机的情况下,基本能保证数据的一 ...

  9. MySQL高可用之MHA的搭建

    MySQL MHA架构介绍: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Face ...

随机推荐

  1. *1 Two Sum two pointers(hashmap one scan)

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  2. python 网址

    https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431752945034e ...

  3. 装箱问题,贪心(POJ1017)

    题目链接:http://poj.org/problem?id=1017 解题报告: #include<stdio.h> int main() { int n,a,b,c,d,e,f,x,y ...

  4. 【转载】刘昕明:送给和我一样曾经浮躁过的PHP程序员

    刘昕明:送给和我一样曾经浮躁过的PHP程序员 来源:刘昕明博客 作者:刘昕明         2012年偶决定开始写博客了,不为别的,就希望可以通过博客记录我的成长历程同时也希望可以帮助一些刚毕业,刚 ...

  5. Hive 常用命令和语句

    示例数据库为 db_hive 1. 创建表 create-table.sql create table if not exists db_hive.tb_user ( id int, username ...

  6. MAC卸载/删除 Parallels Desktop虚拟机的方法

    一些MAC用户在自己的电脑上安装了虚拟机之后,想要将它卸载,但是不知道该怎么做.今天小编就为大家带来了这个问题的解决方法. 解决方案(删除/卸载虚拟机 (VM): 1.启动Parallels Desk ...

  7. python-类对象以列表切片模式操作

    #类对象以列表切片模式操作 class Person: def __init__(self): self.cache=[] def __setitem__(self, key, value): #修改 ...

  8. html和node.js实现websocket

    websocket websocket是HTML5开始提供的一种单个TCP连接上进行全双工通讯的协议.它让客户端和服务端之间的数据交换变得更加简单,允许服务端主动向客户端推送数据.浏览器和服务器只需要 ...

  9. CBCGPImage的GetSize的问题及解决方法

    BCGControlBar Pro for MFC 25.10是目前(2018-07-16)网上能够找到的最新能够使用的版本,我配合Visual Studio 2010使用.在单文档MFC程序的视图中 ...

  10. JSP页面字符集设置

    错误提示: HTTP Status 500 - /test1.jsp (line: 2, column: 1) Page directive must not have multiple occurr ...