简述Mariadb MHA高可用搭建步骤

一、基础环境搭建

1.环境需求

主机名       系统型号 IP地址

需要安装的软件

作用

master       

CentOS 7 64 位 192.168.115.130 mysql 5.7、MHA node 作为主机
mha CentOS 7 64 位

192.168.115.128

MHA node 和 manager 组件 作为管理机
slave CentOS 7 64 位 192.168.115.131 mysql 5.7、MHA node 作为从机
slave2 CentOS 7 64 位 192.168.115.132 mysql 5.7、MHA node 作为从机

2.实现各机免密登录

[root@slave ~]# ssh-keygen   生成密钥

[root@slave ~]# ssh-copy-id 192.168.115.128  将密钥上传给其他三台机器

3.实现各机域名免密登录

vim /etc/hosts 写入内容,每个虚拟机都要写入

简述Mariadb MHA高可用搭建步骤_第1张图片

4.配置主从复制环境的配置文件


vim /etc/my.cnf  进入配置文件

主机

server-id=20
log-bin=master-bin
log-slave-updates=true


从机

server-id=30
log-bin=master-bin
relay-log=relay-log-bin
relay-log-index=relay-log-bin.index

简述Mariadb MHA高可用搭建步骤_第2张图片

5.赋予权限


主机

[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';"

从机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';"
从机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';"

 二、安装环境

1.所有节点安装perl环境

[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.所有节点安装node

准备一个node压缩包,解压并编译安装

[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 && make && make install

[root@master mha4mysql-node-0.57]# cd /usr/local/bin

看到可执行文件 即为成功

3.MHA主机解压安装mha4mysql-manager-0.57.tar 

[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 && make && make install

4.做路径优化

[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.修改配置文件

(1)mha虚拟机创建配置文件文件夹

mkdir /etc/masterha

vim /etc/masterha/app1.cnf

(2)写入

#!/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
);
#############################添加内容部分#########################################
my $vip = '192.168.115.200';                                                            #指定vip的地址
my $brdc = '192.168.115.255';                                                           #指定vip的广播地址
my $ifdev = 'ens33';                                                                            #指定vip绑定的网卡
my $key = '1';                                                                                          #指定vip绑定的虚拟网卡序列号
my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip";           #代表此变量值为ifconfig ens33:1 192.168.184.200
                                                                1,1          顶端

(3)建立masterha配置文件

[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.检查配置文件

[root@mha bin]# masterha_check_ssh --conf=/etc/masterha/app1.cnf


[root@mha bin]# masterha_check_repl --conf=/etc/masterha/app1.cnf

简述Mariadb MHA高可用搭建步骤_第3张图片

报错: 

我在检查第二个配置文件时出现此报错时,我去检查此文件的路径,发现文件没错,后来我把该文件删除重新写了一份,问题解决,移动此位置也没用,必须删除重建。

三、验证

1.启动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>&1 &

2.停止master的mariadb服务

3.查询日志信息

[root@mha etc]# cd /var/log/masterha/app1/



[root@mha app1]# less manager.log 

 从下面的日志信息中可用看出,主机130已经停止,从机131成为新的主机

简述Mariadb MHA高可用搭建步骤_第4张图片

 

你可能感兴趣的:(mariadb,数据库)