MySQL高可用之MHA安装
| 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 |
[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 ~]
#
[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
[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 ################################# [%]
[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
[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.
[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安装的更多相关文章
- MySQL高可用之MHA (转)
MySQL高可用之MHA MHA简介 MHA是由日本人yoshinorim(原就职于DeNA现就职于FaceBook)开发的比较成熟的MySQL高可用方案.MHA能够在30秒内实现故障切换,并能在故障 ...
- mysql高可用方案MHA介绍
mysql高可用方案MHA介绍 概述 MHA是一位日本MySQL大牛用Perl写的一套MySQL故障切换方案,来保证数据库系统的高可用.在宕机的时间内(通常10-30秒内),完成故障切换,部署MHA, ...
- MySQL高可用方案--MHA部署及故障转移
架构设计及必要配置 主机环境 IP 主机名 担任角色 192.168.192.128 node_master MySQL-Master| ...
- 【DB宝42】MySQL高可用架构MHA+ProxySQL实现读写分离和负载均衡
目录 一.MHA+ProxySQL架构 二.快速搭建MHA环境 2.1 下载MHA镜像 2.2 编辑yml文件,创建MHA相关容器 2.3 安装docker-compose软件(若已安装,可忽略) 2 ...
- MySQL高可用方案MHA自动Failover与手动Failover的实践及原理
集群信息 角色 IP地址 ServerID 类型 Master ...
- MySQL高可用方案MHA在线切换的步骤及原理
在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小. MHA就提 ...
- MySQL高可用之MHA的搭建 转
http://www.cnblogs.com/muhu/p/4045780.html http://www.cnblogs.com/gomysql/p/3675429.html http://www ...
- MySQL高可用方案MHA的部署和原理
MHA(Master High Availability)是一套相对成熟的MySQL高可用方案,能做到在0~30s内自动完成数据库的故障切换操作,在master服务器不宕机的情况下,基本能保证数据的一 ...
- MySQL高可用之MHA的搭建
MySQL MHA架构介绍: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Face ...
随机推荐
- 创建React工程:React工程模板
这是本人初学React做的学习笔记;讲的不是很深,只算是简单的进行介绍. 这是一个小系列.都是在同一个模板中搭建的,但是代码是不能正常执行的. >>index.js <!DOCTYP ...
- 使用ABAP代码创建S/4HANA里的Sales Order
下图是使用ABAP代码创建的S/4HANA的Sales Order的截图: 其中红色区域的值是我代码里硬编码的,而蓝色是函数SD_SALESDOCUMENT_CREATE自己创建的. 来看下代码: D ...
- 小程序wx.request的POST方法的参数传输服务器接收不到
这是API里面的例子: 而实际这样,服务端拿到的是空值. 将header更改一下,application/x-www-form-urlencoded,则可以让服务器收到数据
- Poj(2225),三维BFS
题目链接:http://poj.org/problem?id=2225 这里要注意的是,输入的是坐标x,y,z,那么这个点就是在y行,x列,z层上. 我竟然WA在了结束搜索上了,写成了输出s.step ...
- 2017.10.13 Java中引用类型变量的创建及使用&循环高级写法
今日内容介绍 1.引用类型变量的创建及使用 2.流程控制语句之选择语句 3.流程控制语句之循环语句 4.循环高级 ###01创建引用类型变量公式 * A: 创建引用类型变量公式 ...
- 原生Servlet 上传文件
依赖jar <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons ...
- 利用python中的PIL进行矩阵与图像之间的转换
1.图像转换为矩阵 matrix = numpy.asarray(image) 2.矩阵转换为图像 image = Image.fromarray(matrix)
- Qlikview 数据加载方法罗列
以下是通常会用到的数据加载的方法,供大家参考: 1. 从文件加载: Data: Load *,RowNo() as InputKey; SQL SELECT ID,TEST,DATECREATED F ...
- [USACO07FEB]银牛派对Silver Cow Party---最短路模板题
银牛排队 对于我这种蒟蒻来说,还是不要跑一次单元最短路.跑两次好写呀(- ̄▽ ̄)- 而题目中是有向图.如果如果按照题意进行最短路的话.就会出现一个单终点最短路和一个单起点最短路 对于单起点自然就是套模 ...
- 流形(Manifold)初步
原文链接 欧几里得几何学(Euclidean Geometry) 两千三百年前,古希腊数学家欧几里得著成了<几何原本>,构建了被后世称为“欧几里得几何学”的研究图形的方法.欧几里得创立了当 ...