MHA+MySQL实现mysql高可用
发布时间:2023-02-16 13:19:04 所属栏目:MySql 来源:互联网
导读:1. MHA的简单介绍 简介 MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀的作为MysqL高可用性环境下故障切换和主从提升的高可用软件。在MysqL故障切换
7. 配置文件测试 测试ssh连通性 [root@hz-192-168-142-49 scripts]# masterha_check_ssh --conf=/data/mha/app1.cnf Fri May 25 14:24:34 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Fri May 25 14:24:34 2018 - [info] Reading application default configuration from /data/mha/app1.cnf.. Fri May 25 14:24:34 2018 - [info] Reading server configuration from /data/mha/app1.cnf.. Fri May 25 14:24:34 2018 - [info] Starting SSH connection tests.. Fri May 25 14:24:37 2018 - [debug] Fri May 25 14:24:34 2018 - [debug] Connecting via SSH from root@192.168.142.48(192.168.142.48:8822) to root@192.168.142.49(192.168.142.49:8822).. Fri May 25 14:24:35 2018 - [debug] ok. Fri May 25 14:24:35 2018 - [debug] Connecting via SSH from root@192.168.142.48(192.168.142.48:8822) to root@192.168.142.50(192.168.142.50:8822).. Fri May 25 14:24:36 2018 - [debug] ok. Fri May 25 14:24:38 2018 - [debug] Fri May 25 14:24:35 2018 - [debug] Connecting via SSH from root@192.168.142.49(192.168.142.49:8822) to root@192.168.142.48(192.168.142.48:8822).. Fri May 25 14:24:35 2018 - [debug] ok. Fri May 25 14:24:35 2018 - [debug] Connecting via SSH from root@192.168.142.49(192.168.142.49:8822) to root@192.168.142.50(192.168.142.50:8822).. Fri May 25 14:24:37 2018 - [debug] ok. Fri May 25 14:24:39 2018 - [debug] Fri May 25 14:24:35 2018 - [debug] Connecting via SSH from root@192.168.142.50(192.168.142.50:8822) to root@192.168.142.48(192.168.142.48:8822).. Fri May 25 14:24:37 2018 - [debug] ok. Fri May 25 14:24:37 2018 - [debug] Connecting via SSH from root@192.168.142.50(192.168.142.50:8822) to root@192.168.142.49(192.168.142.49:8822).. Fri May 25 14:24:39 2018 - [debug] ok. Fri May 25 14:24:39 2018 - [info] All SSH connection tests passed successfully. 测试集群中的主从复制 [root@hz-192-168-142-49 scripts]# masterha_check_repl --conf=/data/mha/app1.cnf ...... ...... 192.168.142.48(192.168.142.48:5700) (current master) +--192.168.142.49(192.168.142.49:5700) +--192.168.142.50(192.168.142.50:5700) Fri May 25 14:25:57 2018 - [info] Checking replication health on 192.168.142.49.. Fri May 25 14:25:57 2018 - [info] ok. Fri May 25 14:25:57 2018 - [info] Checking replication health on 192.168.142.50.. Fri May 25 14:25:57 2018 - [info] ok. Fri May 25 14:25:57 2018 - [info] Checking master_ip_failover_script status: Fri May 25 14:25:57 2018 - [info] /data/mha/scripts/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.142.48 --orig_master_ip=192.168.142.48 --orig_master_port=5700 --orig_master_ssh_port=8822 UnkNown option: orig_master_ssh_port IN SCRIPT TEST====systemctl stop keepalived==systemctl start keepalived=== Checking the Status of the script.. OK Fri May 25 14:25:57 2018 - [info] OK. Fri May 25 14:25:57 2018 - [warning] shutdown_script is not defined. Fri May 25 14:25:57 2018 - [info] Got exit code 0 (Not master dead). MysqL Replication Health is OK. 8. 启动MHA管理节点 启动命令 nohup masterha_manager --conf=/data/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /data/mha/mha/app1/manager.log 2>&1 & 参数含义具体可参照官网说明 https://github.com/yoshinorim/mha4MysqL-manager/wiki/masterha_manager,此处简单说明 --remove_dead_master_conf,发生failover后,MHA会自动从配置文件里移除dead master的相关信息 --ignore_last_failover,默认情况下,之前如果存在failover,那么再次启动MHA是不成功的,必须删除对应目录下的failover error文件, (manager_workdir)/(app_name).failover.error;设置此参数,就可以忽略上次是否错误而可以继续进行failover 关闭命令 masterha_stop --conf=/data/mha/app1.cnf 查看状态 masterha_check_status --conf=/data/mha/app1.cnf 9. 在线手动切换过程 1、首先需要保证mha manager处于关闭状态 masterha_stop --conf=/data/mha/app1.cnf 2、手动切换主master masterha_master_switch --conf=/data/mha/app1.cnf --master_state=alive --new_master_host=192.168.142.48 --new_master_port=5700 --orig_master_is_new_slave --running_updates_limit=10000 --interactive=0 参数解释: new_master_host:指定哪台成为新的主库 new_master_port:指定对应的数据库端口 orig_master_is_new_slave:将原来的主库变为从库 running_updates_limit:指定复制延迟在10000s内的都可切换 interactive:表示不需要人工干预,自动执行 3、切换过程 1、检查当前的配置信息及主从服务器的信息 包括读取MHA的配置文件以及检查当前slave的健康状态 2、阻止对当前master的更新 主要通过如下步骤: 1> 等待1.5s($time_until_kill_threads*100ms),等待当前连接断开 2> 执行 read_only=1,阻止新的DML操作 3> 等待0.5s,等待当前DML操作完成 4> kill掉所有连接 5> FLUSH NO_WRITE_TO_binlog TABLES 6> FLUSH TABLES WITH READ LOCK 3、等待新master执行完所有的relay log,执行完之后记录下对应的日志位点 Waiting to execute all relay logs on 192.168.142.49(192.168.142.49:5700).. Getting new master's binlog name and position.. MysqL-bin.000001:2488 4、将新master的read_only设置为off,并添加VIP 5、slave切换到新master上 1、等待slave应用完原主从复制产生的relay log,然后执行change master操作切换到新master上 Waiting to execute all relay logs on 192.168.142.50(192.168.142.50:5700).. Resetting slave 192.168.142.50(192.168.142.50:5700) and starting replication from the new master 192.168.142.49(192.168.142.49:5700).. 2、释放原master上的锁 Unlocking all tables on the orig master: Executing UNLOCK TABLES.. 3、因masterha_master_switch命令行中带有--orig_master_is_new_slave参数,故原master也切换为新master的从 Starting orig master as a new slave.. (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |