Mysql5.5部署MHA
MHA分管理节点和数据库节点,数据库节点由mysql主从或者主主从构成,当主库挂掉后,管理节点会自动将从节点提升为主节点;管理节点的角色类似于oracle数据库中的fast start failover中的observer,但mha上层可以通过keepalive部署VIP,程序连接数据库使用VIP,从而实现后台数据库的故障切换透明化
MHA节点包含三个脚本,依赖perl模块;
save_binary_logs:保存和复制当掉的主服务器二进制日志;
apply_diff_relay_logs:识别差异的relay log事件,并应用于其他salve服务器;
purge_relay_logs:清除relay log文件;
需要在所有mysql服务器上安装MHA节点,MHA管理服务器也需要安装。MHA管理节点模块内部依赖MHA节点模块;
MHA管理节点通过ssh连接管理mysql服务器和执行MHA节点脚本。MHA节点依赖perl的DBD::mysql模块;
本文环境介绍,操作系统均为rhel5.4
主库:192.168.123.13/dg53.yang.com
备库:192.168.123.14/dg54.yang.com
管理节点:192.168.123.15/dg55.yang.com
在开始之前,请先配置好服务器间的时间同步和名称解析
一:在数据库节点安装mha node
- [root@dg53 ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
- Retrieving http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
- warning: /var/tmp/rpm-xfer.yqwfYT: Header V3 DSA signature: NOKEY, key ID 217521f6
- Preparing... ########################################### [100%]
- 1:epel-release ########################################### [100%]
- [root@dg53 ~]# ls /etc/yum.repos.d/
- base.repo epel.repo epel-testing.repo rhel-debuginfo.repo
- [root@dg53 ~]# yum -y install perl-DBD-MySQL ncftp
- [root@dg53 ~]# wget http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.52.tar.gz -P /usr/local/src/tarbag/
- [root@dg53 ~]# cd /usr/local/src/tarbag/
- [root@dg53 tarbag]# tar -zxvpf mha4mysql-node-0.52.tar.gz -C ../software/
- [root@dg53 tarbag]# cd ../software/mha4mysql-node-0.52/
- [root@dg53 mha4mysql-node-0.52]# perl Makefile.PL
- [root@dg53 mha4mysql-node-0.52]# make && make install
二:管理节点
1:按照步骤一安装mha node
2:安装mha manager
- [root@dg55 ~]# yum -y install perl-Config-Tiny perl-Params-Validate perl-Log-Dispatch perl-Parallel-ForkManager
- [root@dg55 ~]# wget http://mysql-master-ha.googlecode.com/files/mha4mysql-manager-0.52.tar.gz -P /usr/local/src/tarbag/
- [root@dg55 ~]# cd /usr/local/src/tarbag/
- [root@dg55 tarbag]# tar -zxvpf mha4mysql-manager-0.52.tar.gz -C ../software/
- [root@dg55 tarbag]# cd ../software/mha4mysql-manager-0.52/
- [root@dg55 mha4mysql-manager-0.52]# perl Makefile.PL
- [root@dg55 mha4mysql-manager-0.52]# make && make install
3:编辑配置文件
- [root@dg55 mha4mysql-manager-0.52]# mkdir /etc/masterha
- [root@dg55 mha4mysql-manager-0.52]# mkdir -p /masterha/app1
- [root@dg55 mha4mysql-manager-0.52]# cp samples/conf/* /etc/masterha/
- [root@dg55 mha4mysql-manager-0.52]# cat /etc/masterha/app1.cnf
- [server default]
- manager_workdir=/masterha/app1
- manager_log=/masterha/app1/manager.log
- user=root
- password=123456
- ssh_user=root
- repl_user=r_test
- repl_password=123456
- ping_interval=1
- shutdown_script=""
- #master_ip_failover_script="/usr/local/bin/master_ip_failover"
- master_ip_online_change_script=""
- report_script=""
- [server1]
- hostname=192.168.123.13
- master_binlog_dir="/mydata"
- candidate_master=1
- [server2]
- hostname=192.168.123.14
- master_binlog_dir="/mydata"
- candidate_master=1
4:配置manager节点和node节点以及node节点间的ssh公钥信任
- [root@dg55 ~]# ssh-keygen -t rsa
- [root@dg55 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.123.13
- [root@dg55 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.123.14
- [root@dg55 ~]# ssh 192.168.123.13 "ifconfig |grep 'inet addr' |head -1"
- inet addr:192.168.123.13 Bcast:192.168.123.255 Mask:255.255.255.0
- [root@dg55 ~]# ssh 192.168.123.14 "ifconfig |grep 'inet addr' |head -1"
- inet addr:192.168.123.14 Bcast:192.168.123.255 Mask:255.255.255.0
5:测试ssh连接
- [root@dg55 ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf
- Wed Jun 6 11:11:25 2012 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
- Wed Jun 6 11:11:25 2012 - [info] Reading application default configurations from /etc/masterha/app1.cnf..
- Wed Jun 6 11:11:25 2012 - [info] Reading server configurations from /etc/masterha/app1.cnf..
- Wed Jun 6 11:11:25 2012 - [info] Starting SSH connection tests..
- Wed Jun 6 11:11:25 2012 - [debug]
- Wed Jun 6 11:11:25 2012 - [debug] Connecting via SSH from root@192.168.123.13(192.168.123.13) to root@192.168.123.14(192.168.123.14)..
- Wed Jun 6 11:11:25 2012 - [debug] ok.
- Wed Jun 6 11:11:26 2012 - [debug]
- Wed Jun 6 11:11:25 2012 - [debug] Connecting via SSH from root@192.168.123.14(192.168.123.14) to root@192.168.123.13(192.168.123.13)..
- Wed Jun 6 11:11:26 2012 - [debug] ok.
- Wed Jun 6 11:11:26 2012 - [info] All SSH connection tests passed successfully.
6:测试主从复制情况,默认使用root用户连接
- mysql> select user,host,password from mysql.user;
- +--------+----------------+-------------------------------------------+
- | user | host | password |
- +--------+----------------+-------------------------------------------+
- | root | localhost | |
- | root | dg53.yang.com | |
- | root | 127.0.0.1 | |
- | root | ::1 | |
- | | localhost | |
- | | dg53.yang.com | |
- | r_test | 192.168.123.14 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
- +--------+----------------+-------------------------------------------+
- 7 rows in set (0.08 sec)
- mysql> use mysql;
- Database changed
- mysql> update user set host='192.168.123.%' where user='r_test';
- Query OK, 1 row affected (0.05 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
- mysql> commit;
- Query OK, 0 rows affected (0.01 sec)
- mysql> update user set host='192.168.123.%' where host='localhost' and user='root' and password='';
- Query OK, 0 rows affected (0.00 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
- mysql> update user set password=PASSWORD('123456') where user='root' and host='192.168.123.%';
- Query OK, 0 rows affected (0.00 sec)
- Rows matched: 1 Changed: 0 Warnings: 0
- mysql> flush privileges;
- Query OK, 0 rows affected (0.02 sec)
- [root@dg53 ~]# whereis mysqlbinlog
- mysqlbinlog: /usr/bin/mysqlbinlog
- [root@dg53 ~]# mv /usr/bin/mysql* /tmp
- [root@dg54 ~]# mv /usr/bin/mysql* /tmp
- [root@dg53 ~]# ln -s /usr/local/mysql5.5.25/bin/* /usr/local/bin/
- [root@dg54 ~]# ln -s /usr/local/mysql5.5.25/bin/* /usr/local/bin/
- [root@dg55 ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
- Wed Jun 6 12:39:03 2012 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
- Wed Jun 6 12:39:03 2012 - [info] Reading application default configurations from /etc/masterha/app1.cnf..
- Wed Jun 6 12:39:03 2012 - [info] Reading server configurations from /etc/masterha/app1.cnf..
- Wed Jun 6 12:39:03 2012 - [info] MHA::MasterMonitor version 0.52.
- Wed Jun 6 12:39:03 2012 - [info] Dead Servers:
- Wed Jun 6 12:39:03 2012 - [info] Alive Servers:
- Wed Jun 6 12:39:03 2012 - [info] 192.168.123.13(192.168.123.13:3306)
- Wed Jun 6 12:39:03 2012 - [info] 192.168.123.14(192.168.123.14:3306)
- Wed Jun 6 12:39:03 2012 - [info] Alive Slaves:
- Wed Jun 6 12:39:03 2012 - [info] 192.168.123.14(192.168.123.14:3306) Version=5.5.25-log (oldest major version between slaves) log-bin:enabled
- Wed Jun 6 12:39:03 2012 - [info] Replicating from 192.168.123.13(192.168.123.13:3306)
- Wed Jun 6 12:39:03 2012 - [info] Primary candidate for the new Master (candidate_master is set)
- Wed Jun 6 12:39:03 2012 - [info] Current Alive Master: 192.168.123.13(192.168.123.13:3306)
- Wed Jun 6 12:39:03 2012 - [info] Checking slave configurations..
- Wed Jun 6 12:39:03 2012 - [warning] read_only=1 is not set on slave 192.168.123.14(192.168.123.14:3306).
- Wed Jun 6 12:39:03 2012 - [warning] relay_log_purge=0 is not set on slave 192.168.123.14(192.168.123.14:3306).
- Wed Jun 6 12:39:03 2012 - [info] Checking replication filtering settings..
- Wed Jun 6 12:39:03 2012 - [info] binlog_do_db= bbs,test, binlog_ignore_db= mysql
- Wed Jun 6 12:39:03 2012 - [info] Replication filtering check ok.
- Wed Jun 6 12:39:03 2012 - [info] Starting SSH connection tests..
- Wed Jun 6 12:39:05 2012 - [info] All SSH connection tests passed successfully.
- Wed Jun 6 12:39:05 2012 - [info] Checking MHA Node version..
- Wed Jun 6 12:39:05 2012 - [info] Version check ok.
- Wed Jun 6 12:39:05 2012 - [info] Checking SSH publickey authentication and checking recovery script configurations on the current master..
- Wed Jun 6 12:39:05 2012 - [info] Executing command: save_binary_logs --command=test --start_file=mysql-bin.000011 --start_pos=4 --binlog_dir=/mydata --output_file=/var/tmp/save_binary_logs_test --manager_version=0.52
- Wed Jun 6 12:39:05 2012 - [info] Connecting to root@192.168.123.13(192.168.123.13)..
- Creating /var/tmp if not exists.. ok.
- Checking output directory is accessible or not..
- ok.
- Binlog found at /mydata, up to mysql-bin.000011
- Wed Jun 6 12:39:06 2012 - [info] Master setting check done.
- Wed Jun 6 12:39:06 2012 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
- Wed Jun 6 12:39:06 2012 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user=root --slave_host=192.168.123.14 --slave_ip=192.168.123.14 --slave_port=3306 --workdir=/var/tmp --target_version=5.5.25-log --manager_version=0.52 --relay_log_info=/mydata/relay-log.info --slave_pass=xxx
- Wed Jun 6 12:39:06 2012 - [info] Connecting to root@192.168.123.14(192.168.123.14)..
- Checking slave recovery environment settings..
- Opening /mydata/relay-log.info ... ok.
- Relay log found at /mydata, up to dg54-relay-bin.000019
- Temporary relay log file is /mydata/dg54-relay-bin.000019
- Testing mysql connection and privileges.. done.
- Testing mysqlbinlog output.. done.
- Cleaning up test file(s).. done.
- Wed Jun 6 12:39:06 2012 - [info] Slaves settings check done.
- Wed Jun 6 12:39:06 2012 - [info]
- 192.168.123.13 (current master)
- +--192.168.123.14
- Wed Jun 6 12:39:06 2012 - [info] Checking replication health on 192.168.123.14..
- Wed Jun 6 12:39:06 2012 - [info] ok.
- Wed Jun 6 12:39:06 2012 - [warning] master_ip_failover_script is not defined.
- Wed Jun 6 12:39:06 2012 - [warning] shutdown_script is not defined.
- Wed Jun 6 12:39:06 2012 - [info] Got exit code 0 (Not master dead).
- MySQL Replication Health is OK.
7:启动管理节点进程
- [root@dg55 ~]# nohup masterha_manager --conf=/etc/masterha/app1.cnf > /tmp/mha_manager.log < /dev/null 2>&1 &
- [1] 25516
- [root@dg55 ~]# masterha_check_status --conf=/etc/masterha/app1.cnf
- app1 (pid:25516) is running(0:PING_OK), master:192.168.123.13
三:测试failover过程
1:当前主库为192.168.123.13,关闭主库
- mysql> show slave hosts;
- +-----------+------+------+-----------+
- | Server_id | Host | Port | Master_id |
- +-----------+------+------+-----------+
- | 2 | | 3306 | 1 |
- +-----------+------+------+-----------+
- 1 row in set (0.00 sec)
- [root@dg53 ~]# service mysqld stop
- Shutting down MySQL...[ OK ]
2:在管理节点上观察日志输出
[root@dg55 ~]# tail -f /masterha/app1/manager.log Wed Jun 6 14:50:48 2012 - [warning] master_ip_failover_script is not defined. Wed Jun 6 14:51:32 2012 - [warning] Got error on MySQL ping: 2006 (MySQL server has gone away) To: ----- Failover Report ----- app1: MySQL Master failover 192.168.123.13 to 192.168.123.14 succeeded Master 192.168.123.13 is down! Check MHA Manager logs at dg55.yang.com:/masterha/app1/manager.log for details. Started automated(non-interactive) failover. |
3:在原从库192.168.123.14上查看结果
- mysql> show master status;
- +------------------+----------+--------------+------------------+
- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
- +------------------+----------+--------------+------------------+
- | mysql-bin.000023 | 107 | bbs,test | mysql |
- +------------------+----------+--------------+------------------+
- 1 row in set (0.00 sec)
- mysql> show slave status\G;
- *************************** 1. row ***************************
- Slave_IO_State:
- Master_Host: 192.168.123.13
- Master_User: r_test
- Master_Port: 3306
- Connect_Retry: 60
- Master_Log_File:
- Read_Master_Log_Pos: 4
- Relay_Log_File: dg54-relay-bin.000001
- Relay_Log_Pos: 4
- Relay_Master_Log_File:
- Slave_IO_Running: No
- Slave_SQL_Running: No
- 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: 0
- Relay_Log_Space: 126
- 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: NULL
- 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: 1
- 1 row in set (0.00 sec)
- ERROR:
- No query specified
备注:本文只简单记录了mha的环境部署过程,更多高级的内容,例如配合keepalive使用VIP,让客户端连接数据库透明化以及手动failover和master_ip_failover_script脚本,半同步复制等功能后续将继续研究!
参考文章,感谢作者分享
http://who0168.blog.51cto.com/253401/699030
http://huoding.com/2011/12/18/139
http://www.vmcd.org/2012/04/mysql-high-availability-mha/
Mysql5.5部署MHA相关推荐
- MySQL5.6 部署MHA
趁着最近几天休息,就把之前没有补全的博客也来补补. 今天就和大家聊聊MySQL高可用方案中的MHA 在中小型架构中,针对MySQL做高可用 用的最多的可能就是keepalived/heartbeat+ ...
- MySQL 部署MHA集群部署
目录 MySQL 部署MHA集群部署 MHA集群概述 MHA介绍 MHA简介 MHA组成 MHA工作过程 MHA集群架构 MHA工作过程 拓扑结构 IP规划 拓扑图 部署MHA集群 准备集群环境 安装 ...
- 三十六.MHA集群概述 、 部署MHA集群 测试配置
1.准备MHA集群环境 准备6台虚拟机,并按照本节规划配置好IP参数 在这些虚拟机之间实现SSH免密登录 在相应节点上安装好MHA相关的软件包 使用6台RHEL 7虚拟机,如图-1所示.准备集群环境, ...
- centos 部署mysql5.7_centos7部署MySQL 5.7
一.部署安装MySQL 注:在安装MySQL前需要卸载掉当前已有的mariadb,然后需要安装gcc环境 1.安装cmake [root@mysql ~]# wget https://github.c ...
- centos 部署mysql5.7_centos7部署mysql-5.7
Mysql-5.7.21二进制部署方式可以不用编译,但要指定版本,包也比较大 一.环境声明 [mysql-Server] 主机名 = host-1 系统 = centos-7.3 地址 = 1.1.1 ...
- mysql5.7 部署文档-rpm
一.准备工作 1.1.目录规划 (1)/mysql 使用单独的逻辑卷. mkdir /mysql lvcreate -n lv_mysql -L +100g vg mkfs.ext4 /dev/map ...
- mysql HA方案: MHA
mysql-master-ha mysql 做热备和高可用的方法有很多种, 比如: mmm: http://mysql-mmm.org/ mha: https://code.google.com/p/ ...
- 业界最具影响力MySQL精品文章荟萃(300篇)
更多精彩文章可关注:51CTO技术博客微信:blog51cto 让你轻松享受更多技术文章~ MySQL是一种关联数据库管理系统,SQL语言是用于访问数据库的最常用标准化语言.本文档收集的资料有MyS ...
- MySQL之MHA高可用配置及故障切换(理论加实战详细部署步骤)
MySQL之MHA高可用配置及故障切换(理论加实战详细部署步骤) 文章目录 一.MHA介绍 (一).什么是MHA (二).MHA 的组成 (三).MHA 的特点 二.搭建 MySQL MHA (一). ...
最新文章
- OpenCV 实战:3 步实现图像降噪
- 【CIC滤波器】基于MATLAB/FPGA的数字CIC滤波器的设计
- 推荐计算机与通信领域SCI期刊,因子稳中看升,对中国作者友好,毕业优选!
- JS面向对象,创建,继承
- 云原生时代来袭 下一代云数据库技术将走向何方?
- react 怎么获取表格_react学习之js-xlsx导入和导出excel表格
- leetcode —— 19. 删除链表的倒数第N个节点
- 一分钟教你在PyTorch跑模型的时候提取中间层查看图片
- Web应用工作原理、动态网页技术
- 如何发布一个Android库
- Python 进阶——重访 list (二)
- linux下升级glibc-2.14问题
- 自动驾驶仿真:VTD的SCP命令详解
- 项目管理:如何制作项目进度表
- ucfirst() 把字符串中的首字符转换为大写
- gitlab 账号注册及修改资料
- Day12:使用正则表达式
- Openstack API 开发 快速入门
- MATLAB之微分方程求解(十一)
- python十二星座符号_12种编程语言类比12星座女