sandbox和MHA快速测试(r12笔记第32天)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 昨天写了一篇使用脚本搭建一主多从的脚本之后,奇龙兄建议我看看sandbox的功能,可以秒级搭建主从环境,简单试了下,确实很好很强大。    环境部署其实很简单,如果有网络环境,直接cpan一个命令即可。

昨天写了一篇使用脚本搭建一主多从的脚本之后,奇龙兄建议我看看sandbox的功能,可以秒级搭建主从环境,简单试了下,确实很好很强大。

   环境部署其实很简单,如果有网络环境,直接cpan一个命令即可。或者使用wget的方式来安装也可以。

安装sandbox

使用cpan来安装,非常简单,就是下面的命令:

cpan MySQL::Sandbox

一些日志的输出之后就提示你安装成功,在/usr/local/bin下面就会多几个make_sandbox相关的命令。

[root@grtest bin]# ll make*
-r-xr-xr-x 1 root root  8681 Apr 12 16:16 make_multiple_custom_sandbox
-r-xr-xr-x 1 root root 13862 Apr 12 16:16 make_multiple_sandbox
-r-xr-xr-x 1 root root 22260 Apr 12 16:16 make_replication_sandbox
-r-xr-xr-x 1 root root 11454 Apr 12 16:16 make_sandbox
-r-xr-xr-x 1 root root  4970 Apr 12 16:16 make_sandbox_from_installed
-r-xr-xr-x 1 root root  7643 Apr 12 16:16 make_sandbox_from_source
-r-xr-xr-x 1 root root  5772 Apr 12 16:16 make_sandbox_from_url

另外一种方式是通过安装包的方式,可以通过编译安装完成。

可以使用wget下载安装包:

# wget https://launchpad.net/mysql-sandbox/mysql-sandbox-3/mysql-sandbox-3/+download/MySQL-Sandbox-3.0.25.tar.gz然后使用make,make install的方式即可安装。


比如我要部署一个MySQL数据库环境,我们给定一个二进制安装包,直接make_sandbox即可。

# make_sandbox mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz这个命令有一点需要说明,就是考虑到安全,默认使用root是敏感的,会抛出下面的警告。主要就是向你确认是否确实要这儿做,如果是一个线上环境,操作的风险很高,所以就特别提示,需要你设定一个变量值,确认之后才可以。

# make_sandbox percona-server-5.6.25-73.1.tar.gz
MySQL Sandbox should not run as root

If you know what you are doing and want to
 run as root nonetheless, please set the environment
variable 'SANDBOX_AS_ROOT' to a nonzero value
我们就给这个变量给一个值,比如go

export SANDBOX_AS_ROOT=go一套数据库环境就自动部署出来了,难得的是会自动生成对应的快捷脚本,如果下个做一些批量管理类的任务,就非常快捷方便,这里的数据库安装目录是msb_5_7_17,数据文件都在这个目录下面。

[root@grtest sandboxes]# ll
total 48
-rwxr-xr-x 1 root root   54 Apr 12 16:35 clear_all
drwxr-xr-x 4 root root 4096 Apr 12 16:35 msb_5_7_17
-rw-r--r-- 1 root root 3621 Apr 12 16:35 plugin.conf
-rwxr-xr-x 1 root root   56 Apr 12 16:35 restart_all
-rwxr-xr-x 1 root root 2145 Apr 12 16:35 sandbox_action
-rwxr-xr-x 1 root root   58 Apr 12 16:35 send_kill_all
-rwxr-xr-x 1 root root   54 Apr 12 16:35 start_all
-rwxr-xr-x 1 root root   55 Apr 12 16:35 status_all
-rwxr-xr-x 1 root root   53 Apr 12 16:35 stop_all
-rwxr-xr-x 1 root root 4514 Apr 12 16:35 test_replication
-rwxr-xr-x 1 root root   52 Apr 12 16:35 use_all连接数据库,只需要一个use命令即可。

 ./use
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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.
mysql [localhost] {msandbox} ((none)) >其它的启停命令也是如此,非常快捷方便。

而要搭建主从环境,操作步骤简单,输出日志也很简单,比如我指定一个已经解压的二进制目录5.7.17,就会默认创建一主两从的环境。

# export SANDBOX_AS_ROOT=go
# make_replication_sandbox 5.7.17
installing and starting master
installing slave 1
installing slave 2
starting slave 1
.. sandbox server started
starting slave 2
. sandbox server started
initializing slave 1
initializing slave 2
replication directory installed in $HOME/sandboxes/rsandbox_5_7_17查看主从的状态,使用status_all即可。

# ./status_all
REPLICATION rsandbox_5_7_17
master on
port: 20192
node1 on
port: 20193
node2 on
port: 20194

MHA快速测试


   当然上面的工作可以使用sandbox来做,也可以使用自定义脚本来做,各有好处,相对来说,手工脚本的方式最起码自己更清楚一些。

   动态搭建一主多从,我的一个设想就是快速模拟MHA的环境。

我们先创建一个数据库用户mha_test,作为配置中的连接用户

GRANT ALL PRIVILEGES ON *.* TO 'mha_test'@'%' identified by 'mha_test' ;然后指定一个配置文件,内容如下:

# cat /home/mha/conf/app1.cnf
[server default]
manager_workdir=/home/mha/manager
manager_log=/home/mha/manager/app1/manager.log
port=24801
user=mha_test
password=mha_test
repl_user=rpl_user
repl_password=rpl_pass

[server1]
hostname=127.0.0.1
port=24801
candidate_master=1

[server2]
hostname=127.0.0.1
candidate_master=1
port=24802

[server3]
hostname=127.0.0.1
candidate_master=1
port=24803因为是同一台服务器,所以能够快速模拟MHA的容灾切换和快速恢复。

使用如下的脚本来检测SSH的情况。

#  masterha_check_ssh --conf=/home/mha/conf/app1.cnf基本就是如下的ssh连接请检查。

Wed Apr 12 18:35:52 2017 - [debug]  Connecting via SSH from root@127.0.0.1(127.0.0.1:22) to root@127.0.0.1(127.0.0.1:22)..
Wed Apr 12 18:35:52 2017 - [debug]   ok.
Wed Apr 12 18:35:52 2017 - [debug]  Connecting via SSH from root@127.0.0.1(127.0.0.1:22) to root@127.0.0.1(127.0.0.1:22)..
Wed Apr 12 18:35:52 2017 - [debug]   ok.
Wed Apr 12 18:35:52 2017 - [info] All SSH connection tests passed successfully.检查主从的复制情况,可以使用如下的命令

masterha_check_repl --conf=/home/mha/conf/app1.cnf

输出日志部分如下,可以看到主从关系和复制检测都可以清晰看到。

Wed Apr 12 18:35:29 2017 - [info]
127.0.0.1(127.0.0.1:24801) (current master)
 +--127.0.0.1(127.0.0.1:24802)
 +--127.0.0.1(127.0.0.1:24803)

Wed Apr 12 18:35:29 2017 - [info] Checking replication health on 127.0.0.1..
Wed Apr 12 18:35:29 2017 - [info]  ok.
Wed Apr 12 18:35:29 2017 - [info] Checking replication health on 127.0.0.1..
Wed Apr 12 18:35:29 2017 - [info]  ok.
Wed Apr 12 18:35:29 2017 - [warning] master_ip_failover_script is not defined.
Wed Apr 12 18:35:29 2017 - [warning] shutdown_script is not defined.
Wed Apr 12 18:35:29 2017 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.接着我们启动MHA-manager

 nohup masterha_manager --conf=/home/mha/conf/app1.cnf  > /tmp/mha_manager.log 2>&1 &如果检查目前 MHA的状态,可以使用如下的命令:

# masterha_check_status --conf=/home/mha/conf/app1.cnf
app1 (pid:11701) is running(0:PING_OK), master:127.0.0.1这个时候我们来破坏一下,可以手工Kill掉24081端口的mysqld_safe和mysqld服务。

这个就会从日志中发现MHA开始工作了。

tail -f /home/mha/manager/app1/manager.log
Wed Apr 12 22:54:53 2017 - [info] Resetting slave info on the new master..
Wed Apr 12 22:54:53 2017 - [info]  127.0.0.1: Resetting slave info succeeded.
Wed Apr 12 22:54:53 2017 - [info] Master failover to 127.0.0.1(127.0.0.1:24802) completed successfully.
Wed Apr 12 22:54:53 2017 - [info]
----- Failover Report -----
app1: MySQL Master failover 127.0.0.1(127.0.0.1:24801) to 127.0.0.1(127.0.0.1:24802) succeeded
Master 127.0.0.1(127.0.0.1:24801) is down!
Check MHA Manager logs at grtest:/home/mha/manager/app1/manager.log for details.
Started automated(non-interactive) failover.
Selected 127.0.0.1(127.0.0.1:24802) as a new master.
127.0.0.1(127.0.0.1:24802): OK: Applying all logs succeeded
127.0.0.1(127.0.0.1:24803): OK: Slave started, replicating from 127.0.0.1(127.0.0.1:24802)
127.0.0.1(127.0.0.1:24802): Resetting slave info succeeded.
Master failover to 127.0.0.1(127.0.0.1:24802) completed successfully.这样一来24802端口的mysql服务会自动接管,由从库变为主库。而24803端口的从库会自动从24802端口的服务接受数据变更。

整个过程有条不紊,会分为5个阶段来做。


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
4月前
|
架构师 测试技术 网络性能优化
dpdk课程学习之练习笔记七(vpp环境搭建及plugin demo测试)
dpdk课程学习之练习笔记七(vpp环境搭建及plugin demo测试)
168 0
|
4月前
|
存储 缓存 网络协议
dpdk课程学习之练习笔记二(arp, udp协议api测试)
dpdk课程学习之练习笔记二(arp, udp协议api测试)
67 0
|
1月前
|
iOS开发
iOS自动混淆测试处理笔记
iOS自动混淆测试处理笔记
12 0
|
4月前
|
测试技术 API Python
小红书API接口测试 | 小红书笔记详情 API 接口测试指南
随着互联网的发展,越来越多的应用开始使用API接口来提供服务。而API接口的测试也变得越来越重要。本文将介绍如何使用Python语言进行小红书笔记详情API接口的测试。
|
1月前
|
算法 测试技术 开发者
软件质量测试笔记-合工大
软件质量测试笔记-合工大
102 1
|
2月前
|
iOS开发
  iOS 自动混淆测试处理笔记
  iOS 自动混淆测试处理笔记
|
4月前
|
缓存 监控 网络协议
dpdk课程学习之练习笔记五(kni理解及测试)
dpdk课程学习之练习笔记五(kni理解及测试)
77 0
|
4月前
|
前端开发 测试技术 UED
前端知识笔记(三十三)———浅谈用户体验测试的主要功能
前端知识笔记(三十三)———浅谈用户体验测试的主要功能
39 0
|
5月前
|
消息中间件 Kafka Apache
kafka2.x常用命令笔记(一)创建topic,查看topic列表、分区、副本详情,删除topic,测试topic发送与消费
kafka2.x常用命令笔记(一)创建topic,查看topic列表、分区、副本详情,删除topic,测试topic发送与消费
210 0
|
6月前
|
iOS开发
iOS自动混淆测试处理笔记
自动混淆测试是针对 oc 类和oc方法这两个模块进行自动混淆ipa,并ipa安装到设备中运行,通过检测运行ipa包是否崩溃,来对oc类和oc方法进行筛选。如果崩溃,则该类名或方法名不可混淆。 当没有勾选oc类和oc方法,会自动测试所有的可执行文件中的oc类和oc方法名。如果有选中数据,则只会测试选中的数据集合。除了 oc 类和oc方法这两个模块会自动筛选测,其他的模块需要手动配置

热门文章

最新文章