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. 使用extentreports美化testng报告2,增加监听

    有兴趣研究了extentreports报告美化插件,但是因为发现插件有很多内容不能自定义,所以放弃了这个插件,我扩充了官方代码的demo,在testng中增加了监听,并打印了一些测试用例,现在我把两个 ...

  2. IIS无法识别的属性targetFramework

    出现这种错误是因为发布网站时iis的应用程序池默认使用的是.net framework v2.0.50727.4927,而开发的网站用的是.net framework 4.5,所以会出现这种错误. 我 ...

  3. js实现弹窗一个ip在24小时只弹出一次的代码

    function cookieGO(name) { var today = new Date(); var expires = new Date(); expires.setTime(today.ge ...

  4. Search in Rotated Sorted Array——LeetCode

    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...

  5. 13、SpringBoot------整合shiro

    开发工具:STS 前言: shiro,一套简单灵活的安全权限管理框架. 把所有对外暴露的服务API都看作是一种资源,那么shiro就是负责控制哪些可以获得资源,哪些不能获取. 一个比较不错的教程:ht ...

  6. PHP:(一)安装并使用PHP

    php的安装分为两个部分:环境安装配置和开发工具 一.集成环境安装配置 (一)安装 选择:wampserver或者xampp 我采用的是xampp. 在http://www.sourceforce.n ...

  7. Maven - 依赖范围<scope></scope>

    6种:

  8. rsync + git发布项目

    前言: 更新项目的时候需要将更改的文件一一上传,这样比较麻烦,用版本控制器git +rsync 搭建一个发布服务器,以后发布文件非常方便 首先说下,我这边的更新流程,本地写完之后,git push 到 ...

  9. js面向(基于)对象编程—类(原型对象)与对象

    JS分三个部分: 1. ECMAScript标准--基础语法 2. DOM  Document Object Model 文档对象模型 3. BOM  Browser Object Moldel 浏览 ...

  10. python__基础 : 类的__new__方法与实现一个单例

    __new__ : 这个方法的作用主要是创建一个实例,在创建实例时首先会调用 __new__方法 ,然后调用__init__对实例进行初始化, 如果想修改 __new__ 这个方法,那么最后要 ret ...