MySQL mha+keepalived solution demo (ii)

Source: Internet
Author: User
Tags failover mysql in time interval node server

First, configure the MHA working environment

192.168.2.130 Machine Operation:
1.1. Create the working directory of the MHA and create the relevant configuration file
(There is a sample configuration file in the directory after the package decompression). Refers to a sample configuration file that can be downloaded after mha4mysql-manager-0.56.tar.gz decompression

[[email protected] ~]# ifconfig eth1|awk-f ' [:]+ ' Nr==2{print $4} ' 192.168.2.130[[email protected] ~]# ll/us R/bin/masterha*-rwxr-xr-x 1 root root 1995 Apr 1 2014/usr/bin/masterha_check_repl-rwxr-xr-x 1 root root 1779 Apr 1 20 14/usr/bin/masterha_check_ssh-rwxr-xr-x 1 root root 1865 Apr 1 2014/usr/bin/masterha_check_status-rwxr-xr-x 1 root roo T 3201 Apr 1 2014/usr/bin/masterha_conf_host-rwxr-xr-x 1 root root 2517 Apr 1 2014/usr/bin/masterha_manager-rwxr-xr- X 1 root root 2165 Apr 1 2014/usr/bin/masterha_master_monitor-rwxr-xr-x 1 root root 2373 Apr 1 2014/usr/bin/masterha   _master_switch-rwxr-xr-x 1 root root 5171 Apr 1 2014/usr/bin/masterha_secondary_check-rwxr-xr-x 1 root root 1739 Apr 1 2014/usr/bin/masterha_stop[[email protected] ~]# cp-arp/usr/bin/masterha_*/usr/local/bin/[[email  Protected] bin]# cd/usr/bin/[[email protected] bin]# find./-name apply_diff_relay_logs./apply_diff_relay_logs[ [email protected] bin]# find./-Name Filter_mysqlbinlog./filter_mysqlbinlog[[email protected] bin]# find./-name Purge_relay_logs./purge_relay _logs[[email protected] bin]# find./-name save_binary_logs./save_binary_logscp/usr/bin/save_binary_logs/usr/ local/bin/cp/usr/bin/purge_relay_logs/usr/local/bin/cp/usr/bin/filter_mysqlbinlog/usr/local/bin/cp/usr/bin/ Apply_diff_relay_logs/usr/local/bin/ln-s/usr/local/mysql/bin/mysql/usr/bin/mysqlln-s/usr/local/mysql/bin/  Mysqlbinlog/usr/bin/mysqlbinlog
[[email protected] bin]# cd /usr/local/bin/You have new mail in /var/spool/mail/root[[email protected] bin]# lsapply_diff_relay_logs  filter_mysqlbinlog  masterha_check_ssh  masterha_conf_host  masterha_master_monitor  masterha_secondary_check  save_binary_logsmasterha_check_repl  masterha_check_status  masterha_manager masterha_master_switch   masterha_stop    purge_relay_logs

The MHA configuration file is as follows

[[email protected] ~]#  mkdir -p /etc/masterha[[email protected] ~]# cat  /etc/masterha/app1.cnf[server default]manager_log=/var/log/masterha/app1/manager.logmanager_workdir=/var/log/masterha/app1.logmaster_binlog_dir=/data/mysql/logs/bin-logmaster_ip_failover_script=/usr/local/bin/master_ip_failovermaster_ip_online_change_script=/usr/local/bin/master_ip_online_changepassword=123456ping_interval=1remote_workdir=/tmprepl_password=123456repl_user=repmhareport_script=/usr/local/bin/send_reportsecondary_check_script=/usr/local/bin/masterha_secondary_check -s server03 -s server02 --user=root --master_host=server02 --master_ip=192.168.2.128 --master_port=3306shutdown_script=""ssh_port=12570ssh_user=rootuser=monitor[server1]hostname=192.168.2.128port=3306[server2]candidate_master=1check_repl_delay=0hostname=192.168.2.129port=3306[server3]hostname=192.168.2.130port=3306

1.2 Configuration file Parameter description:

[[email protected] ~]# cat/etc/masterha/app1.cnf

[Server Default]manager_workdir=/var/log/masterha/app1.log//Setup Manager's working directory manager_log=/var/log/                                                   Masterha/app1/manager.log//Set manager's log Master_binlog_dir=/data/mysql Set Master to save the Binlog location so that MHA can find the master log, and here is the MySQL data directory #master_ip_failover_script=/usr/local/bin/maste R_ip_failover//Set automatic failover switch script master_ip_online_change_script=/usr/local/bin/master_ip_online_change// Set the switch script for manual switching password=123456//Set the password for the root user in MySQL, this Password is the password that was created in the previous article to monitor the user User=root//settings monitoring user R Ootping_interval=1//Set Monitoring main library, send ping packet time interval, default is 3 seconds, Try three times no response when automatic railoverremote_workdir=/tmp//set remote MySQL in the event of a cut    Save position of Binlog when changing repl_password=123456                                                        Set the password for the replication user Repl_user=repl To set the replication user name in the replication environment Report_script=/usr/local/bin/send_report// Set up scripts for alarms sent after switchover secondary_check_script=/usr/local/bin/masterha_secondary_check-s server03-s server02--user=root--                                                                                                                               Master_host=server02--master_ip=192.168.2.128--master_port=3306 MHA Manager will attempt to log in from server03 once there is a problem between MHA and Server02 monitoring To server02shutdown_script= ""//Setup failure after the shutdown of the failed host script (the primary role of the script is to shut down the host in                                                                   A brain fissure, not used here) Ssh_user=root//Set SSH login username ssh_port=12570 Set the SSH login port. Default is 22[server1]hostname=192.168.2.128port=3306[server2]hostname=192.168.2.129port=3306candidate_master=1                                                        Set to Candidate Master, if this parameter is set, this will be promoted from the library to the primary library after the master-slave switchover occurs, even if the main library is not the latest slavecheck_repl_delay=0 in the cluster By default, if a slave falls behind the master 100M relay logs, MHA will not select the slave as a new master, because the recovery for this slave takes a long time, by setting the Check_r EPL_DELAY=0,MHA trigger switch when selecting a new master, the replication delay will be ignored, which is useful for hosts with Candidate_master=1, because the candidate must be new in the process of switching master[ server3]hostname=192.168.2.130port=3306

Attention:
# #master_ip_failover_script =/usr/local/bin/master_ip_failover
MHA's failover Two ways: one is a virtual IP address, and the other is a global configuration file. MHA does not restrict which way to use, but let the user choose, the way the virtual IP address is involved in other software, such as KeepAlive software, but also to modify the script
Master_ip_failover.
So let's briefly comment master_ip_failover_script=/usr/local/bin/master_ip_failover this option. After introducing keepalived and modifying the script, turn this option on again

Second, set the relay log Purge method (on each slave node):

2.1 Three node server local hosts parsing

[[email protected] ~]# cat /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.2.128   server02192.168.2.129   server03192.168.2.130   server04

Attention:
MHA in the process of switching, from the library during the recovery process depends on the relay log information, so here to relay log automatic cleanup set to off, with manual removal relay log. By default, the relay log from the server is automatically deleted when the SQL thread finishes executing. However, in a MHA environment, these relay logs may be used when restoring other slave servers, so you need to disable the automatic deletion of the trunk log. Periodic cleanup of the relay log requires consideration of replication latency issues. In ext3 file system, deleting large files takes a certain amount of time and can cause serious replication delays. To avoid replication delays, you need to temporarily create a hard link for the trunk log because it is fast to delete large files on a Linux system with hard links. (in MySQL database, when you delete a large table, you usually use a hard-link method)

2.2 Set up regular cleanup relay scripts (two slave servers):
In slave sever03 192.168.2.129 operation:

[[email protected] ~]# cat /data/scripts/purge_relay_log.sh#!/bin/bashuser=rootpasswd=123456port=3306log_dir=‘/data/masterha/log‘work_dir=‘/data‘purge=‘/usr/local/bin/purge_relay_logs‘if [ ! -d $log_dir ]then   mkdir $log_dir -pfi$purge --user=$user --password=$passwd --disable_relay_log_purge --port=$port --workdir=$work_dir >> $log_dir/purge_relay_logs.log 2>

The slave server04 192.168.2.130 operation is the same as above, not shown here.

Description of the parameters in the script:

--user mysql                      //用户名--password mysql                  //密码--port                            //端口号--workdir                         //指定创建relay log的硬链接的位置,默认是/var/tmp,由于系统不同分区创建硬链接文件会失败,故需要执行硬链接具体位置,成功执行脚本后,硬链接的中继日志文件被删除--disable_relay_log_purge         //默认情况下,如果relay_log_purge=1,脚本会什么都不清理,自动退出,通过设定这个参数,当relay_log_purge=1的情况下会将relay_log_purge设置为0。清理relay log之后,最后将参数设置为OFF。

The purge_relay_logs script removes the trunk log without blocking the SQL thread. Let's do this manually to see what happens:

MySQL mha+keepalived solution demo (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.