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 ...
随机推荐
- web的攻击技术
简单的http协议本身并不存在安全性问题,因此技术本身几乎不会成为攻击的对象,应用http协议的服务器和客户端,以及运行在服务器端web应用等资源才是攻击目标,那么怎么攻击,来源于哪里呢 web应用攻 ...
- Java 截屏工具类
PrintScreenUtils.java package javax.utils; import java.awt.AWTException; import java.awt.Dimension; ...
- p2597 灾难
我的思路 代码: #include<cstdio> #include<iostream> #include<algorithm> #include<vecto ...
- mayan 游戏真是毒瘤
如题 真坑呀!!! 可算过了 我率先达到了氧气富有化 先是改变时没有fall.40分 然后是fall函数写慢了 tle 50分 . 上代码 #include<cstdio> #includ ...
- phpmyadmin高级功能尚未完全设置部分功能未激活
1.登录phpmyadmin,点击导入,选择/var/ww/html/phpmyadmin/examples/create_tables.sql并执行 完成后可以看到多出了一个库phpmyadmin. ...
- gulp详细教程——前端自动化构建工具
项目构建 一个项目是由多个开发者共同开发一个项目,各负责不同的模块,这就会造成一个完整的项目许多‘代码片段’组成,合并css.javascript,压缩html.css.javascript.imag ...
- angular学习之angular-phonecat项目的实现
---恢复内容开始--- AngularJS官方网站提供了一个用于学习的示例项目:PhoneCat.这是一个Web应用,用户可以浏览一些Android手机,了解它们的详细信息,并进行搜索和排序操作. ...
- Java对象容器总结
泛型容器类 容器类型: ArrayList 元素类型: 有排序 String:里面存放的是对象的管理者,而不是具体的对象,所以string类型有null值 集合容器 容器类型 Set 元素类型 唯一性 ...
- LeetCode977. 有序数组的平方
问题:977. 有序数组的平方 给定一个按非递减顺序排序的整数数组 A,返回每个数字的平方组成的新数组,要求也按非递减顺序排序. 示例 1: 输入:[-4,-1,0,3,10] 输出:[0,1,9,1 ...
- ajax状态值和状态码
AJAX状态值是指,运行AJAX所经历过的几种状态,无论访问是否成功都将响应的步骤,可以理解成为AJAX运行步骤.如:正在发送,正在响应等,由AJAX对象与服务器交互时所得:使用“ajax.ready ...