mysql+mha高可用搭建

主库:172.25.254.125

备库:172.25.254.225

管理节点:172.25.254.126

在开始之前,请先配置好服务器间的时间同步和名称解析

一:在数据库节点安装mha node

[[email protected] ~]# rpm -ivh epel-release-5-4.noarch.rpm

Retrieving 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%]

[[email protected] ~]# ls /etc/yum.repos.d/

base.repo  epel.repo  epel-testing.repo  rhel-debuginfo.repo

[[email protected] ~]# yum -y install perl-DBD-MySQL  ncftp

[[email protected] ~]#  wget mha4mysql-node-0.52.tar.gz -P /usr/local/src/tarbag/

[[email protected] ~]# cd /usr/local/src/tarbag/

[[email protected] tarbag]# tar -zxvpf mha4mysql-node-0.52.tar.gz -C ../software/

[[email protected] tarbag]# cd ../software/mha4mysql-node-0.52/

[[email protected] mha4mysql-node-0.52]# perl Makefile.PL

[[email protected] mha4mysql-node-0.52]# make && make install

二:管理节点

1:按照步骤一安装mha node

2:安装mha manager

[[email protected] ~]# yum -y install perl-Config-Tiny perl-Params-Validate perl-Log-Dispatch perl-Parallel-ForkManager

[[email protected] ~]# wget mha4mysql-manager-0.52.tar.gz -P /usr/local/src/tarbag/

[[email protected] ~]# cd /usr/local/src/tarbag/

[[email protected] tarbag]# tar -zxvpf mha4mysql-manager-0.52.tar.gz -C ../software/

[[email protected] tarbag]# cd ../software/mha4mysql-manager-0.52/

[[email protected] mha4mysql-manager-0.52]# perl Makefile.PL

[[email protected] mha4mysql-manager-0.52]# make && make install

3:编辑配置文件

[[email protected] mha4mysql-manager-0.52]# mkdir /etc/masterha

[[email protected] mha4mysql-manager-0.52]# mkdir -p /masterha/app1

[[email protected] mha4mysql-manager-0.52]# cp samples/conf/* /etc/masterha/

[[email protected] 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=172.25.254.225

master_binlog_dir="/mydata"

candidate_master=1

[server2]

hostname=172.25.254.126

master_binlog_dir="/mydata"

candidate_master=1

4:配置manager节点和node节点以及node节点间的ssh公钥信任

[[email protected] ~]# ssh-keygen -t rsa

[[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]

[[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]

[[email protected] ~]# ssh 172.25.254.225 "ifconfig |grep ‘inet addr‘ |head -1"

inet addr:172.25.254.225  Bcast:172.25.254.255  Mask:255.255.255.0

[[email protected] ~]# ssh 172.25.254.126 "ifconfig |grep ‘inet addr‘ |head -1"

inet addr:172.25.254.126  Bcast:172.25.254.255  Mask:255.255.255.0

5:测试ssh连接

[[email protected] ~]# 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]

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)

[[email protected] ~]# whereis mysqlbinlog

mysqlbinlog: /usr/bin/mysqlbinlog

[[email protected] ~]# mv /usr/bin/mysql* /tmp

[[email protected] ~]# mv /usr/bin/mysql* /tmp

[[email protected] ~]# ln -s /usr/local/mysql5.5.25/bin/* /usr/local/bin/

[[email protected] ~]# ln -s /usr/local/mysql5.5.25/bin/* /usr/local/bin/

[[email protected] ~]# 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 [email protected](172.25.254.125)..

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=172.25.254.225 --slave_ip=172.25.254.225 --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 [email protected](172.25.254.225)..

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] Checking replication health on 172.25.254.225

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:启动管理节点进程

[[email protected] ~]# nohup masterha_manager --conf=/etc/masterha/app1.cnf > /tmp/mha_manager.log  < /dev/null 2>&1 &

[1] 25516

[[email protected] ~]# masterha_check_status --conf=/etc/masterha/app1.cnf

app1 (pid:25516) is running(0:PING_OK), master:172.25.254.125

三:测试failover过程

1:当前主库为172.25.254.125,关闭主库

mysql> show slave hosts;

+-----------+------+------+-----------+

| Server_id | Host | Port | Master_id |

+-----------+------+------+-----------+

|         2 |      | 3306 |         1 |

+-----------+------+------+-----------+

1 row in set (0.00 sec)

[[email protected] ~]# service mysqld stop

Shutting down MySQL...[  OK  ]

2:在管理节点上观察日志输出

[[email protected] ~]# tail -f /masterha/app1/manager.log

Wed Jun  6 14:50:48 2012 - [info]

192.168.123.13 (current master)

+--192.168.123.14

Wed Jun  6 14:50:48 2012 - [warning] master_ip_failover_script is not defined.

Wed Jun  6 14:50:48 2012 - [warning] shutdown_script is not defined.

Wed Jun  6 14:50:48 2012 - [info] Set master ping interval 1 seconds.

Wed Jun  6 14:50:48 2012 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.

Wed Jun  6 14:50:48 2012 - [info] Starting ping health check on 172.25.254.125(172.25.254.125:3306)..

Wed Jun  6 14:50:48 2012 - [info] Ping succeeded, sleeping until it doesn‘t respond..

Wed Jun  6 14:51:32 2012 - [warning] Got error on MySQL ping: 2006 (MySQL server has gone away)

Wed Jun  6 14:51:32 2012 - [info] HealthCheck: SSH to 172.25.254.125 is reachable.

Wed Jun  6 14:51:33 2012 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet‘, system error: 111)

Wed Jun  6 14:51:33 2012 - [warning] Connection failed 1 time(s)..

Wed Jun  6 14:51:34 2012 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet‘, system error: 111)

Wed Jun  6 14:51:34 2012 - [warning] Connection failed 2 time(s)..

Wed Jun  6 14:51:35 2012 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet‘, system error: 111)

Wed Jun  6 14:51:35 2012 - [warning] Connection failed 3 time(s)..

Wed Jun  6 14:51:35 2012 - [warning] Master is not reachable from health checker!

Wed Jun  6 14:51:35 2012 - [warning] Master 172.25.254.125(172.25.254.125:3306) is not reachable!

Wed Jun  6 14:51:35 2012 - [warning] SSH is reachable.

Wed Jun  6 14:51:35 2012 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/masterha/app1.cnf again, and trying to connect to all servers to check server status..

Wed Jun  6 14:51:35 2012 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Wed Jun  6 14:51:35 2012 - [info] Reading application default configurations from /etc/masterha/app1.cnf..

Wed Jun  6 14:51:35 2012 - [info] Reading server configurations from /etc/masterha/app1.cnf..

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: 172.25.254.125

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

时间: 2024-12-26 01:50:18

mysql+mha高可用搭建的相关文章

搭建MySQL MHA高可用

本文内容参考:http://www.ttlsa.com/mysql/step-one-by-one-deploy-mysql-mha-cluster/ MySQL MHA 高可用集群 环境: Linux: centos 6.6 MySQL: 5.5.49 MHA: mha4mysql-manager-0.56-0.el6.noarch.rpm(管理端) 以及 mha4mysql-node-0.56-0.el6.noarch.rpm(节点) 192.168.178.128 MySQL主从环境: M

专职DBA-基于MHA高可用搭建MySQL读写分离架构-Atlas

专职DBA-基于MHA高可用搭建MySQL读写分离架构-Atlas 1.Atlas介绍 Atlas是由Qihoo360,Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目. 它是在mysql-proxy-0.8.2版本的基础上,对其进行了优化,增加了一些新的功能特性. 360内部使用Atlas运行的mysql业务,每天承载的读写请求数达几十亿条. 下载地址:https://github.com/Qihoo360/Atlas/releases 注意: 1.Atlas只能安装运

Mysql MHA高可用集群架构

记得之前发过一篇文章,名字叫<浅析MySQL高可用架构>,之后一直有很多小伙伴在公众号后台或其它渠道问我,何时有相关的深入配置管理文章出来,因此,民工哥,也将对前面的各类架构逐一进行整理,然后发布出来.那么今天将来发布的MHA的架构整体规划与配置操作. 简单介绍MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,作为MySQL高可用性环境下故障切换和主从提升的高可用软件.在MySQL故障切换过程中,MHA能做到在0~30秒之内自动完成数

MySQL MHA高可用环境搭建

一.安装MHA基本环境 1. 安装MHA node (1) 基本环境说明,本文参考互联网文章学习,搭建MHA与测试如下. 参考文档:http://www.cnblogs.com/xuanzhi201111/p/4231412.html 角色                IP地址            主机名    =============================================    Master              192.168.1.121     node

MySQL MHA高可用方案

200 ? "200px" : this.width)!important;} --> 介绍 MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件.在MySQL故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一致性,以达到真正意义上的高可用.它由两部分组成:MHA Man

mysql mha高可用架构的安装

MMM无法全然地保证数据的一致性,所以MMM适用于对数据的一致性要求不是非常高.可是又想最大程度的保证业务可用性的场景对于那些对数据一致性要求非常高的业务,非常不建议採用MMM的这样的高可用性架构.那么可以考虑使用MHA.在mysql故障切换的过程中.MHA可以在0-30s内自己主动完毕数据库的故障切换操作,而且MHA可以最大程度上保证数据的一致性,以达到真正意义上的高可用. MHA软件由两部分组成,Manager工具包和Node工具包.详细的说明例如以下. Manager工具包主要包含下面几个

MySQL MHA高可用环境部署

一,安装MHA基本环境 安装MHA节点 (1)基本环境说明 角色IP地址主机名 ========================================= 主机192.168.1.121节点1 从机192.168.1.122节点2 从机192.168.1.123节点3 监视主机192.168.1.125节点5 (2)在node1,node2,node3,node5中操作: #vi / etc / hosts 192.168.1.121 node1 192.168.1.122 node2

MySQL MHA高可用架构介绍

介绍了当前主流高可用软件MHA的工作流程和切换演示(模拟从库延迟,主库宕机后,数据自动补齐) 视频地址:http://edu.51cto.com/lesson/id-44865.html

各种报错,搭建Mysql MHA高可用集群时踩的各种坑

mha下载地址,需要翻墙 https://code.google.com/p/mysql-master-ha/ 管理软件 mha4mysql-manager-0.52-0.noarch.rpm 节点软件 mha4mysql-node-0.52-0.noarch.rpm 环境介绍 Centos6.7 X64 192.168.30.210 monitor 192.168.30.211 db1 (master) 192.168.30.212 db2  (备master) 192.168.30.213