如何实行sandbox和MHA的测试
发布时间:2021-12-20 10:54:01 所属栏目:通讯 来源:互联网
导读:本篇文章为大家展示了如何进行sandbox和MHA的测试,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。 昨天写了一篇使用脚本搭建一主多从的脚本之后,奇龙兄建议我看看sandbox的功能,可以秒级搭建主从环境,简单试
本篇文章为大家展示了如何进行sandbox和MHA的测试,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。 昨天写了一篇使用脚本搭建一主多从的脚本之后,奇龙兄建议我看看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' ;然后指定一个配置文件,内容如下: [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个阶段来做。 上述内容就是如何进行sandbox和MHA的测试,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。 (编辑:南京站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐
热点阅读