1. Basic environment construction
1. Environmental requirements
hostname | System Model | IP Address |
Software to install |
Action |
the master |
CentOS 7 64-bit | 192.168.115.130 | mysql 5.7, MHA node | as host |
mha | CentOS 7 64 bit |
192.168.115.128 |
MHA node and manager components | as a management machine |
slave | CentOS 7 64 bit | 192.168.115.131 | mysql 5.7, MHA node | as slave |
slave2 | CentOS 7 64-bit | 192.168.115.132 | mysql 5.7, MHA node | as a slave |
2. Realize password-free login for each machine
[root@slave ~]# ssh-keygen generate key [root@slave ~]# ssh-copy-id 192.168.115.128 Upload the key to the other three machines
3. Realize password-free login of each domain name
Vim /etc/hosts write content, each virtual machine must write
4. Configure the configuration file of the master-slave replication environment
vim /etc/my.cnf enters the configuration file the host server-id=20 log-bin=master-bin log-slave-updates=true Slave server-id=30 log-bin=master-bin relay-log=relay-log-bin relay-log-index=relay-log-bin.index
5. Grant permissions
the host [root@master ~]# mysql -e "grant replication slave on *.* to 'myslave'@'192168.115.%' identified by '123.com';" [root@master ~]# mysql -e "grant replication slave on *.* to 'myslave'@'192.168.115.%' identified by '123.com';" [root@master ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.%' identified by '123.com';" [root@master ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.128' identified by '123.com';" [root@master ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.131' identified by '123.com';" [root@master ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.132' identified by '123.com';" Slave 1 [root@slave ~]# mysql -e "grant replication slave on *.* to 'myslave'@'192.168.115.%' identified by '123.com';" [root@slave ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.%' identified by '123.com';" [root@slave ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.130' identified by '123.com';" [root@slave ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.132' identified by '123.com';" [root@slave ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.128' identified by '123.com';" Slave 2 [root@slave2 ~]# mysql -e "grant replication slave on *.* to 'myslave'@'192.168.115.%' identified by '123.com';" [root@slave2 ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.%' identified by '123.com';" [root@slave2 ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.128' identified by '123.com';" [root@slave2 ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.130' identified by '123.com';" [root@slave2 ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.131' identified by '123.com';"
2. Installation environment
1. Install perl environment on all nodes
[root@master ~]# yum install epel-release -y [root@master ~]# yum -y install perl-DBD-MySQL perl-ExtUtils-MakeMaker perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes perl-CPAN
2. Install node on all nodes
Prepare a node compressed package, decompress and compile and install
[root@master ~]# tar xf mha4mysql-node-0.57.tar.gz [root@master ~]# cd mha4mysql-node-0.57/ [root@master mha4mysql-node-0.57]# perl Makefile.PL & amp; & amp; make & amp; & amp; make install [root@master mha4mysql-node-0.57]# cd /usr/local/bin Seeing the executable file means success
3. Decompress and install mha4mysql-manager-0.57.tar on the MHA host
[root@mha ~]# tar xf mha4mysql-manager-0.57.tar.gz [root@mha ~]# cd mha4mysql-manager-0.57/ [root@mha mha4mysql-manager-0.57]# perl Makefile.PL & amp; & amp; make & amp; & amp; make install
4. Do path optimization
[root@mha mha4mysql-manager-0.57]# cp samples/scripts/master_ip_failover /usr/local/bin/ [root@mha mha4mysql-manager-0.57]# cp samples/scripts/master_ip_online_change /usr/local/bin/
5. Modify the configuration file
(1) mha virtual machine creates a configuration file folder
mkdir /etc/masterha vim /etc/masterha/app1.cnf
(2) Write
#!/usr/bin/envperl use strict; use warnings FATAL => 'all'; use Getopt::Long; my ( $command, $ssh_user, $orig_master_host, $orig_master_ip, $orig_master_port, $new_master_host, $new_master_ip, $new_master_port ); ##############################Add content section #################### ######################### my $vip = '192.168.115.200'; #Specify the address of vip my $brdc = '192.168.115.255'; #Specify the broadcast address of vip my $ifdev = 'ens33'; #Specify the network card bound by vip my $key = '1'; #Specify the serial number of the virtual network card bound by vip my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip"; #Represents this variable value ifconfig ens33:1 192.168.184.200 1,1 top
(3) Create a masterha configuration file
[root@mha ~]# mkdir /etc/masterha [root@mha ~]# vim /etc/masterha/app1.cnf
[server default] managera_log=/var/log/masterha/app1/manager.log manager_workdir=/var/log/masterha/app1 master_binlog_dir=/var/lib/mysql master_ip_failover_script=/usr/local/bin/master_ip_failover master_ip_online_change_script=/usr/local/bin/master_ip_online_change password=manager ping_interval=1 remote_workdir=/tmp repl_password=123.com repl_user=myslave secondary_check_script=/usr/local/bin/masterha_secondary_check -s 192.168.115.131 -s 192.168.115.132 shutdown_script="" ssh_user=root user=mha [server1] hostname=192.168.115.130 port=3306 [server2] candidate_master=1 check_repl_delay=0 hostname=192.168.115.131 port=3306 [server3] hostname=192.168.115.132 port=3306
6. Check the configuration file
[root@mha bin]# masterha_check_ssh --conf=/etc/masterha/app1.cnf [root@mha bin]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Error report:
When this error occurred when I checked the second configuration file, I checked the path of this file and found that the file was correct. Later, I deleted the file and re-wrote it. The problem was solved, and it was useless to move this location. delete rebuild.
3. Verify
1. Start manager
nohup masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log 2> & amp;1 & amp;
2. Stop the master’s mariadb service
3. Query log information
[root@mha etc]# cd /var/log/masterha/app1/ [root@mha app1]# less manager.log
From the following log information, it can be seen that the master 130 has stopped, and the slave 131 has become the new master