Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Modify MySQL high availability module to receive custom VIP parameters

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

All MySQL DBA must have heard of MHA high availability solutions, and many companies achieve MySQL high availability through secondary development of MHA. If MHA is not combined with VIP, each switching of the main library requires the program to modify the configuration of the database, which is more troublesome. When using MHA+VIP, you can let VIP drift to the new main database in the process of switching the main database, eliminating the process of changing the database configuration.

The company used to configure a manager node for each group of master-slave replication clusters, and then write information such as vip and network interface in master_ip_failover and master_ip_online_change scripts. When there are too many master-slave clusters, there are many manager nodes to be maintained, which is very troublesome to manage.

How to manage multiple VIP-supporting mysql master-slave clusters with one Manager node? There are two ways to do this:

1. Each group of master-slave replication cluster maintains two switching scripts to write VIP and network interface information in the script.

2. Modify the relevant modules of MHA so that they can identify our custom parameters. We only need to pass values to the parameters in the configuration file of each master-slave replication cluster.

Obviously, the first approach is too low and requires a large number of switching scripts to be maintained. Which modules do we need to modify?

If you take a look at the masterha_check_repl script, you can see that the MasterMonitor module is called when the master-slave replication status is detected.

Exit_code = MHA::MasterMonitor::main ("--interactive=0", "--check_only", "--check_repl_health", @ ARGV); if ($exit_code = = 0) {print "\ nMySQL Replication Health is OK.\ n";} else {print "\ nMySQL Replication Health is NOT OK!\ n";}

Through the masterha_master_switch script, you can see that the online switchover is the invoked MasterRotate module, and the failover is the invoked MasterFailover module.

If ($master_state eq "dead") {$exit_code = MHA::MasterFailover::main (@ ARGV);} elsif ($master_state eq "alive") {$exit_code = MHA::MasterRotate::main (@ ARGV);} else {pod2usage (1);}

All three modules of MasterMonitor.pm,MasterRotate.pm,MasterFailover.pm call the Config.pm module to read the parameter configuration, so we only need to modify these modules.

For the sake of the uneven network environment, I have added these three configuration items to the configuration file:

App_vip: VIP of the main library

Netmask: the network bit of VIP

Interface: the Internet to which VIP is bound

The code for the corresponding adjustment is as follows:

Config.pm:

Declare variables:

My @ PARAM_ARRAY = qw/ hostname ip port ssh_host ssh_ip ssh_port ssh_connection_timeout ssh_options node_label candidate_master no_master ignore_fail skip_init_ssh_check skip_reset_slave user password repl_user repl_password disable_log_bin master_pid_file handle_raw_binlog ssh_user remote_workdir master_binlog_dir log_level manager_workdir manager_log check_repl_delay check_repl_filter latest_priority multi_tier_slave ping_interval ping_type secondary _ check_script master_ip_failover_script master_ip_online_change_script shutdown_script report_script init_conf_load_script client_bindir client_libdir use_gtid_auto_pos app_vip netmask interface/

Assign a value to a variable:

$value {app_vip} = $param_arg- > {app_vip}; if (! defined ($value {app_vip})) {$value {app_vip} = $default- > {app_vip};} $value {netmask} = $param_arg- > {netmask}; if (! defined ($value {netmask})) {$value {netmask} = $default- > {netmask};} $value {interface} = $param_arg- > {interface} If (! defined ($value {interface})) {$value {interface} = $default- > {interface};}

MasterMonitor.pm:

Modify the command for replication detection:

"$current_master- > {master_ip_failover_script}-- command=status-- ssh_user=$current_master- > {ssh_user}-- orig_master_host=$current_master- > {hostname}-- orig_master_ip=$current_master- > {ip}-- orig_master_port=$current_master- > {port}-- app_vip=$current_master- > {app_vip}-- netmask=$current_master- > {netmask}-- interface=$current_master- > {interface}"

MasterMonitor.pm:

Modify the command written by the original master library:

"$orig_master- > {master_ip_online_change_script}-- command=stop-- orig_master_host=$orig_master- > {hostname}-- orig_master_ip=$orig_master- > {ip}-- orig_master_port=$orig_master- > {port}-- orig_master_user=$orig_master- > {escaped_user}-- orig_master_password=$orig_master- > {escaped_password}-- new_master_host=$new_master- > {hostname}-- new_master _ ip=$new_master- > {ip}-- new_master_port=$new_master- > {port}-- new_master_user=$new_master- > {escaped_user}-- new_master_password=$new_master- > {escaped_password}-- app_vip=$orig_master- > {app_vip}-- netmask=$orig_master- > {netmask}-- interface=$orig_master- > {interface} "

Modify the commands that are allowed to be written to the new main library:

"$new_master- > {master_ip_online_change_script}-- command=start-- orig_master_host=$orig_master- > {hostname}-- orig_master_ip=$orig_master- > {ip}-- orig_master_port=$orig_master- > {port}-- orig_master_user=$orig_master- > {escaped_user}-- orig_master_password=$orig_master- > {escaped_password}-- new_master_host=$new_master- > {hostname}-- new_master _ ip=$new_master- > {ip}-- new_master_port=$new_master- > {port}-- new_master_user=$new_master- > {escaped_user}-- new_master_password=$new_master- > {escaped_password}-- app_vip=$orig_master- > {app_vip}-- netmask=$orig_master- > {netmask}-- interface=$orig_master- > {interface} "

MasterFailover.pm:

Modify the vip command that disables the original slave library:

"$dead_master- > {master_ip_failover_script}-- orig_master_host=$dead_master- > {hostname}-- orig_master_ip=$dead_master- > {ip}-- orig_master_port=$dead_master- > {port}-- app_vip=$dead_master- > {app_vip}-- netmask=$dead_master-> {netmask}-- interface=$dead_master- > {interface}"

Modify the command that enables the original slave library vip:

"$new_master- > {master_ip_failover_script}-- command=start-- ssh_user=$new_master- > {ssh_user}-- orig_master_host=$dead_master- > {hostname}-- orig_master_ip=$dead_master- > {ip}-- orig_master_port=$dead_master- > {port}-- new_master_ host=$new_master- > {hostname}-- new_master_ip=$new_master- > {ip}-- new_master_port=$new_ Master- > {port}-- new_master_user=$new_master- > {escaped_user}-- new_master_password=$new_master- > {escaped_password}-app_vip=$de ad_master- > {app_vip}-- netmask=$dead_master- > {netmask}-- interface=$dead_master- > {interface} "

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report