MySQL高可用架构之MHA

1、关于MHA

MHA(Master HA)是一款开源的MySQL的高可用程序,它为MySQL主从复制架构提供了automating master failover功能。MHA在监控到master节点故障时,会提升其中拥有的最新数据的slave节点成为新的master节点,在此期间,MHA会通过其它从节点获取额外信息来避免一致性方面的问题。MHA还提供了master节点的在线切换功能,即按需切换master/slave节点。

MHA服务有两种角色,MHA Manager(管理节点)和MHA Node(数据节点):

MHA Manager:通常单独部署在一台独立机器上管理多个master/slave集群,每个master/slave集群称为一个application;

MHA node:运行在每台MySQL服务器上,它通过监控具备解析和清理log功能的脚本来加快故障转移

2、MHA组件说明

Manager节点:

-masterha_check_ssh:MHA依赖的SSH环境检测工具;
-masterha_check_repl:MySQL复制环境检测工具;
-masterha_manager:MHA服务主程序;
-masterha_check_status:MHA运行状态探测工具;
-masterha_master_monitor:MySQL master节点可用性检测工具;
-masterha_master_switch:master节点切换工具;
-masterha_conf_host:添加或删除配置的节点;
-masterha_stop:关闭MHA服务的工具;

Node节点:

-save_binary_logs:保存和复制master的二进制日志;
-apply_diff_relay_logs:识别差异的中继日志事件并用于其他slave;
-fiter_mysqlbinlog:去除不必要的ROLLBACK事件(MHA已不再使用这个工具);
-purge_relay_logs:清除中继日志(不会阻塞SQL线程);

自定义扩展:

-secondary_check_script:通过多条网络路由检测master的可用性;
-master_ip_failover_script:更新appliction使用的masterip;
-shutdown_script:强制关闭master节点;
-report_script:发送报告;
-init_conf_load_script:加载初始配置参数;
-master_ip_online_change_script:更新master节点ip地址

3、部署及测试

实验拓扑:

node1:192.168.150.137   MHA manager
node2:192.168.150.138   MHA node    mariadb master
node3:192.168.150.139   MHA node    mariadb slave candidate
node4:192.168.150.140   MHA node    mariadb slave

配置过程:

1、修改每台服务器的hosts文件
/etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.150.137 node1.com node1
192.168.150.138 node2.com node2
192.168.150.139 node3.com node3
192.168.150.140 node4.com node4

2、node2-node4进行mariadb的yum安装
yum -y install mariadb-server

3、配置ssh互信通信环境
[[email protected] ~]# 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:
a2:f2:10:28:cd:ea:7b:d8:f4:95:15:6e:73:a6:9d:4e [email protected]
The key‘s randomart image is:
+--[ RSA 2048]----+
|                 |
|         .       |
|        . .      |
| +       = o     |
|o +   . S * .    |
|.. o . + . E     |
|. * o .   o      |
|.. * .     .     |
| oo .            |
+-----------------+
[[email protected] ~]# ls .ssh/id_rsa
id_rsa      id_rsa.pub  
[[email protected] ~]# cat .ssh/id_rsa.pub > .ssh/authorized_keys
[[email protected] ~]# ssh node1
The authenticity of host ‘node1 (192.168.150.137)‘ can‘t be established.
ECDSA key fingerprint is 2a:e3:03:52:8c:84:02:59:a2:26:a3:b2:f6:74:6c:3c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘node1,192.168.150.137‘ (ECDSA) to the list of known hosts.
Last login: Wed Mar 29 15:06:52 2017 from 192.168.150.1
[[email protected] ~]# ll .ssh/authorized_keys 
-rw-r--r-- 1 root root 396 3月  29 15:35 .ssh/authorized_keys
[[email protected] ~]# chmod go= .ssh/authorized_keys 
[[email protected] ~]# scp -p .ssh/id_rsa .ssh/authorized_keys node2:/root/.ssh
[email protected]‘s password: 
id_rsa                                                  100% 1675     1.6KB/s   00:00    
authorized_keys                                         100%  396     0.4KB/s   00:00    
[[email protected] ~]# scp -p .ssh/id_rsa .ssh/authorized_keys node3:/root/.ssh
The authenticity of host ‘node3 (192.168.150.139)‘ can‘t be established.
ECDSA key fingerprint is 2a:e3:03:52:8c:84:02:59:a2:26:a3:b2:f6:74:6c:3c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘node3,192.168.150.139‘ (ECDSA) to the list of known hosts.
[email protected]‘s password: 
id_rsa                                                  100% 1675     1.6KB/s   00:00    
authorized_keys                                         100%  396     0.4KB/s   00:00    
[[email protected] ~]# scp -p .ssh/id_rsa .ssh/authorized_keys node4:/root/.ssh
[email protected]‘s password: 
Permission denied, please try again.
[email protected]‘s password: 
id_rsa                                                  100% 1675     1.6KB/s   00:00    
authorized_keys                                         100%  396     0.4KB/s   00:00    
[[email protected] ~]# ssh node2
Last login: Wed Mar 29 15:07:05 2017 from 192.168.150.1
[[email protected] ~]# exit
登出
Connection to node2 closed.
[[email protected] ~]# ssh node3
Last login: Wed Mar 29 15:07:18 2017 from 192.168.150.1
[[email protected] ~]# exit
登出
Connection to node3 closed.
[[email protected] ~]# ssh node3
Last login: Wed Mar 29 15:40:05 2017 from node1.com
[[email protected] ~]# exit
登出
Connection to node3 closed.
[[email protected] ~]# ssh node4
Last failed login: Wed Mar 29 15:39:53 CST 2017 from node1.com on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Wed Mar 29 15:39:30 2017 from node1.com
[[email protected] ~]# exit
登出
Connection to node4 closed.
[[email protected] ~]# ssh node4
Last login: Wed Mar 29 15:40:13 2017 from node1.com
[[email protected] ~]# exit
登出
Connection to node4 closed.

4、修改mysql参数
master:
[mysqld]
innodb_file_per_table = 1
skip_name_resolve = 1
log-bin = master-bin
relay-log = relay-bin
server_id = 1

slave:
[mysqld]
innode_file_per_table = 1
skip_name_resolve = 1
log-bin = master-bin
relay-log = relay-bin
server_id = 2
read_only = 1
relay_log_purge = 0

5、主库开启并创建授权账号
master:
MariaDB [(none)]> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000003 |      245 |              |                  |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO ‘repluser‘@‘192.168.%.%‘ IDENTIFIED BY ‘replpass‘;

MariaDB [(none)]> GRANT ALL ON *.* TO ‘mhauser‘@‘192.168.%.%‘ IDENTIFIED BY ‘mhapass‘;  #此为mha的管理账号

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘read_only‘;   #此时主库是可写可读
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only     | OFF   |
+---------------+-------+
1 row in set (0.00 sec)

6、从库进行主从功能开启 node3、node4操作相同
[[email protected] ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=‘192.168.150.138‘,MASTER_USER=‘repluser‘,MSTER_PASSWORD=‘replpass‘,MASTER_LOG_FILE=‘master-bin.000003‘,MASTER_LOG_POS=245;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 192.168.150.138
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000003
          Read_Master_Log_Pos: 245
               Relay_Log_File: relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: master-bin.000003
             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: 245
              Relay_Log_Space: 245
              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: 0
1 row in set (0.00 sec)

MariaDB [(none)]> START SLAVE;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.150.138
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000003
          Read_Master_Log_Pos: 497
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 782
        Relay_Master_Log_File: master-bin.000003
             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: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 497
              Relay_Log_Space: 1070
              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: 0
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)

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘read_only‘;   #此时从库是只读模式
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only     | ON    |
+---------------+-------+
1 row in set (0.00 sec)

7、此时一主两从架构已经配置完成,安装MHA包
manager节点(node1):
安装mha4mysql-manager-0.56-0.el6.noarch.rpm和mha4mysql-node-0.56-0.el6.noarch.rpm
yum install mha4mysql* -y

node节点(node2-node4):
安装mha4mysql-node-0.56-0.el6.noarch.rpm
yum -y iinstall mha4mysql-node-0.56-0.el6.noarch.rpm

8、初始化MHA
创建配置目录及配置文件(在node1上执行)
[[email protected] ~]# mkdir /etc/masterha
[[email protected] ~]# vim /etc/masterha/app1.cnf 
[server default]
user=mhauser
password=mhapass
manager_workdir=/data/masterha/app1
master_log=/data/masterha/app1/manager.log
remote_workdir=/data/masterha/app1
ssh_user=root
repl_user=repluser
repl_password=replpass
ping_interval=1

[server1]
hostname=192.168.150.138
candidate_master=1

[server2]
hostname=192.168.150.139
candidate_master=1

[server3]
hostname=192.168.150.140

9、启动前检测
ssh互信配置是否OK
[[email protected] ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf
......
Warning: Permanently added ‘192.168.150.139‘ (ECDSA) to the list of known hosts.
Wed Mar 29 17:03:03 2017 - [debug]   ok.
Wed Mar 29 17:03:03 2017 - [info] All SSH connection tests passed successfully.

mysql复制集群的连接配置是否OK
[[email protected] ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
......
Wed Mar 29 17:04:40 2017 - [info] 
192.168.150.138(192.168.150.138:3306) (current master)
 +--192.168.150.139(192.168.150.139:3306)
 +--192.168.150.140(192.168.150.140:3306)

Wed Mar 29 17:04:40 2017 - [info] Checking replication health on 192.168.150.139..
Wed Mar 29 17:04:40 2017 - [info]  ok.
Wed Mar 29 17:04:40 2017 - [info] Checking replication health on 192.168.150.140..
Wed Mar 29 17:04:40 2017 - [info]  ok.
Wed Mar 29 17:04:40 2017 - [warning] master_ip_failover_script is not defined.
Wed Mar 29 17:04:40 2017 - [warning] shutdown_script is not defined.
Wed Mar 29 17:04:40 2017 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

10、启动MHA
[[email protected] ~]# nohup masterha_manager --conf=/etc/masterha/app1.cnf > /data/masterha/app1/manager.log 2>&
1 &[1] 16989

[[email protected] ~]# tail -f /data/masterha/app1/manager.log 
192.168.150.138(192.168.150.138:3306) (current master)
 +--192.168.150.139(192.168.150.139:3306)
 +--192.168.150.140(192.168.150.140:3306)

Wed Mar 29 21:51:58 2017 - [warning] master_ip_failover_script is not defined.
Wed Mar 29 21:51:58 2017 - [warning] shutdown_script is not defined.
Wed Mar 29 21:51:58 2017 - [info] Set master ping interval 1 seconds.
Wed Mar 29 21:51:58 2017 - [warning] secondary_check_script is not defined. It is highly recommended setti
ng it to check master reachability from two or more routes.Wed Mar 29 21:51:58 2017 - [info] Starting ping health check on 192.168.150.138(192.168.150.138:3306)..
Wed Mar 29 21:51:58 2017 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn‘t respond..

11、启动后查看master节点状态
[[email protected] ~]# masterha_check_status --conf=/etc/masterha/app1.cnf
app1 (pid:16623) is running(0:PING_OK), master:192.168.150.138

12、进行故障转移测试
(1)maser节点关闭mariadb
[[email protected] ~]# killall mysqld mysqld_safe

(2)此时在manager上可以看到转移的日志
----- Failover Report -----

app1: MySQL Master failover 192.168.150.138(192.168.150.138:3306) to 192.168.150.139(192.168.150.139:3306)
 succeeded
Master 192.168.150.138(192.168.150.138:3306) is down!

Check MHA Manager logs at node1.com:/data/masterha/app1/manager.log for details.

Started automated(non-interactive) failover.
The latest slave 192.168.150.139(192.168.150.139:3306) has all relay logs for recovery.
Selected 192.168.150.139(192.168.150.139:3306) as a new master.
192.168.150.139(192.168.150.139:3306): OK: Applying all logs succeeded.
192.168.150.140(192.168.150.140:3306): This host has the latest relay log events.
Generating relay diff files from the latest slave succeeded.
192.168.150.140(192.168.150.140:3306): OK: Applying all logs succeeded. Slave started, replicating from 19
2.168.150.139(192.168.150.139:3306)192.168.150.139(192.168.150.139:3306): Resetting slave info succeeded.
Master failover to 192.168.150.139(192.168.150.139:3306) completed successfully.

故障转移后,manager会自动停止,此时查看master状态
[[email protected] ~]# masterha_check_status --conf=/etc/masterha/app1.cnf
app1 is stopped(2:NOT_RUNNING).

(3)查看其它两个库状态
node3   已成功接管master,并可读写
MariaDB [(none)]> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000003 |      245 |              |                  |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘read_only‘;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only     | OFF   |
+---------------+-------+
1 row in set (0.00 sec)

node4
MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.150.139
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000003
          Read_Master_Log_Pos: 245
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 530
        Relay_Master_Log_File: master-bin.000003
             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: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 245
              Relay_Log_Space: 818
              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: 0
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: 2
1 row in set (0.00 sec)

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘read_only‘;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only     | ON    |
+---------------+-------+
1 row in set (0.00 sec)

(4)提供新的从节点已修复复制集群
master界定啊故障后,需要重新准备好一个新的MySQL节点。基于来自于master节点的备份恢复后,将其重新配置为mster的从节点即可。新加入节点IP为原master节点IP,否则还得修改appl.cnf中相应的设置,最后再次启动manager,并再次检查状态。

[[email protected] ~]# rm -rf /var/lib/mysql/*
[[email protected] ~]# vim /etc/my.cnf
添加从库两选项
read_only = 1
relay_log_purge = 0
[[email protected] ~]# systemctl start mariadb.service
[[email protected] ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO ‘repluser‘@‘192.168.%.%‘ IDENTIFIED
 BY ‘replpass‘;Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON *.* TO ‘mhauser‘@‘192.168.%.%‘ IDENTIFIED BY ‘mhapass‘;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=‘192.168.150.139‘,MASTER_USER=‘repluser‘,MASTER_PASSWORD=‘r
eplpass‘,MASTER_LOG_FILE=‘master-bin.000003‘,MASTER_LOG_POS=245;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> SHOW SLAVE\G
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaD
B server version for the right syntax to use near ‘‘ at line 1MariaDB [(none)]> START SLAVE;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.150.139
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000003
          Read_Master_Log_Pos: 245
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 530
        Relay_Master_Log_File: master-bin.000003
             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: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 245
              Relay_Log_Space: 818
              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: 0
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: 2
1 row in set (0.00 sec)

再次开启manager查看状态,状态全部OK,主库变更为node3
[[email protected] ~]# nohup masterha_manager --conf=/etc/masterha/app1.cnf > /data/masterha/app1/manager.log 2>&1 &

[[email protected] ~]# masterha_check_status --conf=/etc/masterha/app1.cnf
app1 (pid:17229) is running(0:PING_OK), master:192.168.150.139
时间: 2024-08-08 01:25:03

MySQL高可用架构之MHA的相关文章

MySQL高可用架构之MHA (未完,待续)

MySQL高可用架构之MHA 简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件.在MySQL故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一致性,以达到真正意义上的高可用. 该软件由两部分组成:

探索MySQL高可用架构之MHA(7)

-----构建mysql高可用系列(共9篇) 上一篇文章介绍了本次架构的keepalive读写分离! 本篇文章主要介绍本次架构中的mha安装部分! 关于MHA MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于 Facebook公司)开发,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件.在MySQL故障切换过程中,MHA能做到在 0~30秒之内自动完成数据库的故

探索MySQL高可用架构之MHA(4)

-----构建mysql高可用系列(共9篇) 上一篇文章介绍了本次架构中的Mysql源码安装.本篇文章主要介绍本次架构中的ABBB复制. 首先我们先介绍什么是MySql AB复制???? AB复制又称主从复制,实现的是数据同步.如果要做MySQL AB复制,数据库版本尽量保持一致.如果版本不一致,从服务器版本高于主服务器,但是版本不一致不能做双向复制. MySQL AB复制有什么好处呢? a.解决宕机带来的数据不一致,因为MySQL AB复制可以实时备份数据. b.减轻数据库服务器压力,这点很容

探索MySQL高可用架构之MHA(6)

-----构建mysql高可用系列(共9篇) 上一篇文章介绍了本次架构的Atlas读写分离! 本篇文章主要介绍本次架构中的keepalive部分! 什么是Keepalived呢???? keepalived是一款c语言写的实现在linux系统上实现负载均衡和高可用的软件.它遵从于GNU是一款优秀的开源软件.keepalived观其名可知,保持存活,在网络里面就是保持在线了,也就是所谓的高可用或热备,用来防止单点故障的发生. 两个关键词的解释 负载均衡 keepalived内置了对ipvs函数的调

探索MySQL高可用架构之MHA(5)

-----构建mysql高可用系列(共9篇) 上一篇文章介绍了本次架构的AB复制操作! 本篇文章主要介绍本次架构中的Atlas读写分离! 为什么要分库.分表.读写分离? 现在大型的电子商务系统,在数据库层面大都采用读写分离技术,就是一个Master数据库,多个Slave数据库. Master库负责数据更新,Slave库当然负责非实时数据查询. 因为在实际的应用中,数据库都是读多写少(读取数据的频率高,更新数据的频率相对较少),而读取数据通常耗时比较长,占用数据库服务器的CPU较多,从而影响用户体

MySQL高可用系列之MHA(二)

一.参数说明 MHA提供了一系列配置参数,深入理解每个参数的具体含义,对优化配置.合理使用MHA非常重要,很多高可用性也都是通过合理配置一些参数而实现的. MHA包括如下配置参数,分别说明如下: hostname/ip/port (Local Only) hostname为MySQL Server的IP地址或主机名: ip为MySQL Server的IP地址,缺省从$hostname中获取:port为MySQL Server的端口号,缺省为3306 ssh_host/ssh_ip/ssh_por

mysql高可用集群——MHA架构

目录 1.下载 2.搭建mha 2.1 系统配置 2.2 架构 2.3 添加ssh公钥信任 2.4 安装mha节点 2.5 manager配置文件 2.6 检查 2.7 启动manager进程 2.8 碰到的问题 3.测试切换 3.1 正常切换测试 3.2 回切测试 3.3 雪崩测试 3.4 主从不一致切换测试 下载 mha链接地址:http://pan.baidu.com/s/1pJkDGX9#dir/path=%2Fmysql%2FHA%2Fmha 或者:https://code.googl

mysql实现高可用架构之MHA

一.简介 MHA(Master HA)是一款开源的 MySQL 的高可用程序,它为 MySQL 主从复制架构提供了 automating master failover 功能.MHA 在监控到 master 节点故障时,会提升其中拥有最新数据的 slave 节点成为新的master 节点,在此期间,MHA 会通过于其它从节点获取额外信息来避免一致性方面的问题.MHA 还提供了 master 节点的在线切换功能,即按需切换 master/slave 节点. MHA 是由日本人 yoshinorim

整个MHA+keepalived+lvs+mysql高可用架构配置说明

整个MHA+keepalived+lvs+mysql高可用架构配置说明1.1. 环境简介1.1.1.vmvare虚拟机,系统版本CentOS7.5 x86_64位最小化安装,mysql的版本5.7.21,1.1.2.虚拟机器的ssh端口均为默认22,1.1.3.虚拟机的iptables全部关闭,1.1.4.虚拟机的selinux全部关闭,1.1.5.虚拟机服务器时间全部一致 ntpdate 0.asia.pool.ntp.org1.1.6.3台机器的ssh端口为22**1.2.此次试验采用的是3