文档章节

mysql mha

o
 osc_y8yehimr
发布于 2019/03/20 17:27
字数 617
阅读 11
收藏 0

1.rpm安装mysql5.7

yum remove mariadb* -y
rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm

2.启动mysql,更改root密码

systemctl start mysqld
grep "temporary password" /var/log/mysqld.log
mysqladmin -uroot -p password

3.主从配置

修改mysql配置文件/etc/my.cnf,添加以下内容
[client]
user=root
password=JPcms123!
[mysqld]
server-id=1
read-only=1
log-bin=mysql-bin
relay-log=mysql-relay-bin
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%
创建同步账户
mysql>grant replication slave on *.* to 'repl_user'@'192.168.1.%' identified by 'REPL_passwd123!';
mysql>grant all on *.* to 'root'@'192.168.1.%' identified by 'JPcms123456!';    #很重要

查看master状态

在slave上设置master

change master to master_host='192.168.1.111',master_user='repl_user',master_password='REPL_passwd123!',master_log_file='mysql-bin.000001',master_log_pos=742;

查看slave状态

start slave;
show slave status\G;

4.配置3个节点ssh互信

ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.111
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.112
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.113

最后测试三个节点之间可以无密码登录

ssh 192.168.1.111 date
ssh 192.168.1.112 date
ssh 192.168.1.113 date

5.安装MHA

 安装依赖包

rpm -ivh mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
yum install epel-release -y
yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Config-IniFiles perl-Time-HiRes

在3个节点安装MHA的node

rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm

在slave/MHA manager节点上安装mha4mysql-manage

rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

6.配置MHA

mkdir -p /etc/mha/scripts
vim /etc/masterha_default.cnf
[server default]
user=root
password=JPcms123456!
ssh_user=root
repl_user=repl_user
repl_password=REPL_passwd123!
ping_interval=1
secondary_check_script=masterha_secondary_check -s 192.168.1.111 -s 192.168.1.112 -s 192.168.1.113 --user=repl_user --master_host=localhost.localdomain --master_ip=192.168.1.111 --master_port=3306
master_ip_failover_script="/etc/mha/scripts/master_ip_failover"
# master_ip_online_change_script="/etc/mha/scripts/master_ip_online_change"
# shutdown_script= /script/masterha/power_manager
report_script="/etc/mha/scripts/send_report"
vim /etc/mha/app1.cnf
脚本
#!/usr/bin/env perl
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.1.115/24';
my $key = '1';
my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down";
GetOptions(
 'command=s' => \$command,
 'ssh_user=s' => \$ssh_user,
 'orig_master_host=s' => \$orig_master_host,
 'orig_master_ip=s' => \$orig_master_ip,
 'orig_master_port=i' => \$orig_master_port,
 'new_master_host=s' => \$new_master_host,
 'new_master_ip=s' => \$new_master_ip,
 'new_master_port=i' => \$new_master_port,
);
exit &main();
sub main {
 print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";
 if ( $command eq "stop" || $command eq "stopssh" ) {
 my $exit_code = 1;
 eval {
 print "Disabling the VIP on old master: $orig_master_host \n";
 &stop_vip();
 $exit_code = 0;
 };
 if ($@) {
 warn "Got Error: $@\n";
 exit $exit_code;
 }
 exit $exit_code;
 }
 elsif ( $command eq "start" ) {
 my $exit_code = 10;
 eval {
 print "Enabling the VIP - $vip on the new master - $new_master_host \n";
 &start_vip();
 $exit_code = 0;
 };
 if ($@) {
 warn $@;
 exit $exit_code;
 }
 exit $exit_code;
 }
 elsif ( $command eq "status" ) {
 print "Checking the Status of the script.. OK \n";
 exit 0;
 }
 else {
 &usage();
 exit 1;
 }
}
sub start_vip() {
 `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}
sub stop_vip() {
 return 0 unless ($ssh_user);
 `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
}
sub usage {
 print
 "Usage: master_ip_failover --command=start|stop|stopssh|status --orig_master_host=host
--orig_master_ip=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip
--new_master_port=port\n";
}

在master上添加VIP

ifconfig eth0:1 192.168.1.115/24

 

测试MHA

a.通过 masterha_check_ssh 验证 ssh 信任登录是否成功

masterha_check_ssh --conf=/etc/mha/app1.cnf

b.masterha_check_repl 验证 mysql 复制是否成功

masterha_check_repl --conf=/etc/mha/app1.cnf

 

o
粉丝 0
博文 500
码字总数 0
作品 0
私信 提问
加载中
请先登录后再评论。

暂无文章

如何在Ruby中生成随机字符串 - How to generate a random string in Ruby

问题: I'm currently generating an 8-character pseudo-random uppercase string for "A" .. "Z": 我目前正在为“ A” ..“ Z”生成一个8个字符的伪随机大写字符串: value = ""; 8.times{......

法国红酒甜
37分钟前
12
0
Python中的mkdir -p功能[重复] - mkdir -p functionality in Python [duplicate]

问题: This question already has an answer here: 这个问题在这里已有答案: How can I safely create a nested directory? 如何安全地创建嵌套目录? 25 answers 25个答案 Is there a way...

技术盛宴
今天
15
0
原价500元的认证证书,限时免费考取!

本文作者:y****n 百度云智学院致力于为百度ABC战略(人工智能、大数据、云计算)提供人才生态体系建设,包括基于百度ABC、IoT的课程体系,整合百度优势技术能力的深度学习技术、Apollo无人车...

百度开发者中心
昨天
17
0
在virtualenv中使用Python 3 - Using Python 3 in virtualenv

问题: Using virtualenv , I run my projects with the default version of Python (2.7). 使用virtualenv ,我使用默认版本的Python(2.7)运行项目。 On one project, I need to use Pyth......

富含淀粉
今天
16
0
Python的__init__和self是做什么的? - What __init__ and self do on Python?

问题: I'm learning the Python programming language and I've came across something I don't fully understand. 我正在学习Python编程语言,遇到了一些我不太了解的东西。 In a method ......

javail
今天
15
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部