MHA功能:
1,从故障的mysql保存二进制日志时间(binlog events);
2,识别含有最新更新的slave;
3,应用差异的中继日志(relay log)到其他的slave;
4,应用从master保存的二进制日志文事件;
5,提升一个slave为新的master;
6,是其他的slave连接新的master进行复制;

MHA环境搭建:
manager节点:192.168.125.210
node1节点:192.168.125.200
node2节点:192.168.125.201
node3节点:192.168.125.202

1,首先要配置mysql主从复制。
2,SSH免密钥互相访问配置:
[root@localhost ~]# ssh-keygen -t rsa -P ''  //生成公钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
SHA256:LzSIfKtqa4fh70k5xAreOULBySucDWzUsHf4+6PlHmQ root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| oo              |
|= o..            |
| X o .           |
|o Boo. .         |
|o= .=.oES        |
|+.oo.o+o o       |
| +.*+..o. .      |
|  *.o++...       |
| oo*=.o+.        |
+----[SHA256]-----+
[root@localhost ~]# cat .ssh/id_rsa.pub > .ssh/authorized_keys   //导入到本地认证文件
[root@localhost ~]# chmod go= .ssh/authorized_keys
[root@localhost ~]# scp .ssh/id_rsa .ssh/authorized_keys 192.168.125.200:/root/.ssh/ //SCP到各个节点就可以互相访问了。
[root@localhost ~]# scp -p .ssh/id_rsa .ssh/authorized_keys 192.168.125.201:/root/.ssh/
[root@localhost ~]# scp -p .ssh/id_rsa .ssh/authorized_keys 192.168.125.202:/root/.ssh/
3,安装MHA;
下载地址:
https://downloads.mariadb.com/MHA/mha4mysql-manager-0.55-0.el6.noarch.rpm
https://downloads.mariadb.com/MHA/mha4mysql-node-0.54-0.el6.noarch.rpm
*:需要安装epel源,通过yum安装,在manager安装(manager和node包),在其他主从复制节点安装‘node’包。
4,配置MHA:
root@manager ~]# cat /etc/masterha/app1.cnf
[server default]
manager_workdir=/etc/masterha/app1   #配置manager的工作目录
manager_log=/etc/masterha/app1/manager.log #设置manager的日志
master_binlog_dir=/var/lib/mysql/ #设置master保存binlog的位置,以便MHA可以找到master的日志
user=mhaadmin  #设置监控用的root权限账号,每个节点需要创建。
password=123123  #密码
ssh_user=root  #设置ssh的登陆用户名。
repl_user=glq  #设置复制环境中的复制用户名。
repl_password=123123 #密码
 
[server1]
hostname=192.168.125.200
port=3306
#master_binlog_dir=/var/lib64/mysql
candidate_master=1  #设置为候选master,即使这个库不是集群中最新的slave,也会选择为master。
#check_repl_delay=0  #默认情况下如果一个slave落后master 100M的relay logs的话,MHA将不会选择该slave作为一个新的master,因为对于这个slave的恢复需要花费很长时间,通过设置check_repl_delay=0,MHA触发切换在选择一个新的master的时候将会忽略复制延时,这个参数对于设置了candidate_master=1的主机非常有用,因为这个候选主在切换的过程中一定是新的master
 
[server2]
hostname=192.168.125.201
port=3306
#master_binlog_dir=/var/lib64/mysql
candidate_master=1
 
[server3]
hostname=192.168.125.202
port=3306
#master_binlog_dir=/var/lib64/mysql
#ignore_fail=1
#no_master=1
5,测试MHA;
[root@manager ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf  #测试ssh连接是否正常。
Wed Mar 14 15:44:16 2018 - [info] All SSH connection tests passed successfully. 
[root@manager ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf #测试主从配置是否正常
Wed Mar 14 15:45:09 2018 - [info]
192.168.125.200 (current master)
 +--192.168.125.201
 +--192.168.125.202
Wed Mar 14 15:45:09 2018 - [info] Checking replication health on 192.168.125.201..
Wed Mar 14 15:45:09 2018 - [info]  ok.
Wed Mar 14 15:45:09 2018 - [info] Checking replication health on 192.168.125.202..
Wed Mar 14 15:45:09 2018 - [info]  ok.
Wed Mar 14 15:45:09 2018 - [warning] master_ip_failover_script is not defined.
Wed Mar 14 15:45:09 2018 - [warning] shutdown_script is not defined.
Wed Mar 14 15:45:09 2018 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
6,启动MHA;
[root@manager ~]# masterha_manager --conf=/etc/masterha/app1.cnf
Wed Mar 14 15:46:24 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Mar 14 15:46:24 2018 - [info] Reading application default configurations from /etc/masterha/app1.cnf..
Wed Mar 14 15:46:24 2018 - [info] Reading server configurations from /etc/masterha/app1.cnf..
停止master的mysql之后的状态:
[root@manager ~]# masterha_manager --conf=/etc/masterha/app1.cnf
Wed Mar 14 15:46:24 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Mar 14 15:46:24 2018 - [info] Reading application default configurations from /etc/masterha/app1.cnf..
Wed Mar 14 15:46:24 2018 - [info] Reading server configurations from /etc/masterha/app1.cnf..
  Creating /var/tmp if not exists..    ok.   #检测到master不存在
  Checking output directory is accessible or not..
   ok.
  Binlog found at /var/lib/mysql/, up to master-bin.000003  #发现二进制日志。
Wed Mar 14 15:47:08 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Mar 14 15:47:08 2018 - [info] Reading application default configurations from /etc/masterha/app1.cnf..
Wed Mar 14 15:47:08 2018 - [info] Reading server configurations from /etc/masterha/app1.cnf..
后台运行MHA指令:
[root@manager ~]# nohup master_manager --conf=/etc/masterha/app1.cnf >/etc/masterha/app1/manager.log 2>&1 &
[1] 2832
手动切换从节点为主节点:
[root@manager ~]# masterha_master_switch --master_state=alive --conf=/etc/masterha/app1.cnf --orig_master_is_new_slave --running_updates_limit=3600 --interactive=0
Wed Mar 14 15:52:45 2018 - [info]
Wed Mar 14 15:52:45 2018 - [info] * Phase 5: New master cleanup phase..
Wed Mar 14 15:52:45 2018 - [info]
Wed Mar 14 15:52:45 2018 - [info]  192.168.125.201: Resetting slave info succeeded.
Wed Mar 14 15:52:45 2018 - [info] Switching master to 192.168.125.201(192.168.125.201:3306) completed successfully.
停止MHA manager监控:
[root@manager ~]# masterha_stop --conf=/etc/masterha/app1.cnf
参考资料:https://www.cnblogs.com/gomysql/p/3675429.html

MySQL MHA环境搭建的更多相关文章

  1. Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建教程

    这篇文章主要介绍了Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建教程,需要的朋友可以参考下 准备篇 一.环境说明: 操作系统:Windows Server 201 ...

  2. ubuntu下mysql的环境搭建及使用

    ubuntu下mysql的环境搭建及使用 环境安装 使用如下命令分别安装服务端程序,客户端程序,及客户端依赖库 sudo apt-get install mysql-server sudo apt-g ...

  3. CentOS6.8下MySQL MHA架构搭建笔记

    转载请注明出处,本文地址:http://www.cnblogs.com/ajiangg/p/6552855.html 以下是CentOS6.8下MySQL MHA架构搭建笔记 IP资源规划: 192. ...

  4. Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建)

    Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建) 具体案例:局域网内有两台主机,一台Linux.一台Windows,现在需要配置一台Cacti监控服务器对这两台 ...

  5. Lamp(linux+apache+mysql+php)环境搭建

    Lamp(linux+apache+mysql+php)环境搭建 .安装apache2:sudo apt-get installapache2 安装完毕后.执行例如以下命令重新启动apache:sud ...

  6. mysql MHA架构搭建过程

    [环境介绍] 系统环境:Red Hat Enterprise Linux 7 + 5.7.18 + MHA version 0.57 系统 IP 主机名 备注 版本 xx系统 192.168.142. ...

  7. windows下PHP+Mysql+Apache环境搭建

    Apache版本:httpd-2.2.22-win32-x86-openssl-                   下载地址:http://pan.baidu.com/s/1sjuL4RV PHP版 ...

  8. WAMP(Windows+Apache+Mysql+PHP)环境搭建

    学习PHP已经有一段时间,一直没有写过关于开发环境搭建的笔记,现在补上吧,因为安装配置的步骤记得不是很清楚,借鉴了一些别人的经验,总结如下: 首先去官方网站下载各个软件,下载需要的版本: Apache ...

  9. Apache+PHP+MySQL+phpMyAdmin环境搭建

    最近在学习web服务端开发,一开始是使用wamp的,后来决定自己完整配置一下环境,并把整个过程记录下来.其中,Apache是服务器,php是用来编写服务端的语言,MySQL作为数据库,phpMyAdm ...

随机推荐

  1. Django(一)创建和启动项目

    1,使用pycharm 2,新建工程使用django框架 location 最后一个文件夹名就是project名,我用了DjangoProject. Application 是自动加入的APP名字,我 ...

  2. Struts2工作原理及流程

    Struts2是基于MVC设计模式的JavaWeb 框架技术. 基于Struts2开发Java Web项目的主要步骤如下: (1)在web.xml中配置FilterDispatcher. (2)设计和 ...

  3. cocos2dx 不同平台上加载文件

    原文转自:http://blog.sina.com.cn/s/blog_62b2318d0101eozt.html cocos2dx在不同平台上读取资源文件时的处理方式是不同的. 在ios下,程序调用 ...

  4. nginx+uwsgi+django部署流程

    当我们在用django开发的web项目时,开发测试过程中用到的是django自带的测试服务器,由于其安全及稳定等性能方面的局限性,django官方并不建议将测试服务器用在实际生产. nginx+uws ...

  5. python3.6 ubuntu

    apt-get install python3.6-dev 安装 pip install mysqlclient 必备

  6. HAL_RTC_MspInit Msp指代什么?

    /********************************************************************************* * HAL_RTC_MspInit ...

  7. shell 脚本实战笔记(4)--linux磁盘分区重新挂载

    背景: Hadoop的HDFS文件系统的挂载, 默认指定的文件目录是/mnt/disk{N}. 当运维人员, 不小心把磁盘挂载于其他目录, 比如/mnt/data, /mnt/disk01, /mnt ...

  8. liunx的文件系统及相关的基本命令

    1.ls     当前目录列表 2.cd 切换 3.cd ..    返回上一级 4.cat 文件      显示文件内容 5.mkdir 文件夹名    创建一个新的文件夹 6.rmdir 文件夹名 ...

  9. U盘安装电脑系统教程

    [怎么使用u盘安装系统.U盘装系统.如何用U盘安装系统.U盘制作系统.U盘引导.U盘启动.U盘量产.安装系统.如何设置U盘启动] 在电脑系统的日常使用中,经常会遇到系统崩溃或重新安装系统的情况,没有光 ...

  10. ZOJ2345Gold Coins

    昨天做过一样的题: 平方和公式:n*(n+1)*(2n+1)/6 #include<cstdio> #include<cstdlib> #include<iostream ...