https://dzone.com/articles/consul-proxysql-and-mysql-ha?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed:%20dzone

https://boke.wsfnk.com/archives/537.html

https://www.aliyun.com/jiaocheng/132307.html?spm=5176.100033.2.6.51e94d54AD4NcE

https://qiniu.wsfnk.com/%E7%AC%AC12%E8%AF%BE-4%E4%BC%81%E4%B8%9A%E5%B8%B8%E8%A7%81MySQL%E6%9E%B6%E6%9E%84%E5%BA%94%E7%94%A8%E5%AE%9E%E6%88%98%E4%B9%8BMHA%E6%9E%B6%E6%9E%84.pdf

一、配置主从同步

 

1.1 本例中主从ip及端口

Master:192.168.20.50:3306

Slave1:192.168.31.3:3306 (候选master)

Slave2:192.168.31.2:3306

1.2、安装mysql

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
systemctl start mysqld.service
grep "password" /var/log/mysqld.log
mysql -uroot -p  #登录
ALTER USER 'root'@'localhost' IDENTIFIED BY 'My2019..';
#因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉
yum -y remove mysql57-community-release-el7-10.noarch

1.3.Master配置参数

[mysqld]

user=mysql
pid_file               = /var/lib/mysql/mysqld.pid
socket                 = /var/lib/mysql/mysql.sock
port                    =
basedir                 = /usr
datadir                 = /var/lib/mysql
tmpdir                 = /tmp
log-bin                 = master-bin
log-bin-index           = master-bin.index
server_id               =
innodb_log_file_size         = 256M
expire-logs-days = 1
validate_password=off #取消密码验证

#mysql5.6已上的特性,开启gtid,必须主从全开
 gtid_mode = on
 enforce_gtid_consistency = 1
 log_slave_updates = 1


#开启半同步复制 否则自动切换主从的时候会报主键错误
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000

1.4.在master创建一个复制用户

主节点:
mysql> create user repl_user;
所有主机上授权:
mysql> grant replication slave on *.* to repl_user identified by 'tt123456';
mysql> flush privileges;
mysql>grant all on *.* to root identified by 'my'; #很重要

1.5. Slave1 配置参数

[mysqld]

pid_file = /var/lib/mysql/mysqld.pid
socket = /var/lib/mysql/mysql.sock

basedir=/usr
port=3306
user=mysql
tmpdir= /tmp
server_id= 2
relay_log_index = slave_relay_bin.index
relay_log= slave_relay_bin
innodb_log_file_size= 256M
expire-logs-days = 1

log-bin = mysql-bin (候选需要配)
log-bin-index = mysql-bin.index (候选需要配)
read_only=1
relay_log_purge=0   #(一主一丛不需要此项,两从及以上建议开次参数,防止切换为成主库的从库自动删除中继日志后,无法给其他从库应用这部分日志)

validate_password=off #取消密码验证

gtid_mode = on
 enforce_gtid_consistency = 1
 log_slave_updates = 1

#开启半同步复制 否则自动切换主从的时候会报主键错误
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"(候选需要配)
loose_rpl_semi_sync_master_enabled = 1(候选需要配)
loose_rpl_semi_sync_slave_enabled = 1(候选需要配)
loose_rpl_semi_sync_master_timeout = 5000(候选需要配)

1.6.连接Master和Slave

参考:https://blog.csdn.net/lichangzai/article/details/50423906

mysql> CHANGE MASTER TO

MASTER_HOST='192.168.31.3',
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1,
MASTER_USER='repl_user',
MASTER_PASSWORD='tt123456';

#master_log_file='master-bin.000007',#5.6后不需要指定
#master_log_pos=194;

mysql> start slave;
mysql> show slave status\G;

 1.7查看半同步是否开启

master:
mysql> show status like 'Rpl_semi_sync_master_status';
+-----------------------------+-------+
| Variable_name | Value |
+-----------------------------+-------+
| Rpl_semi_sync_master_status | ON |
+-----------------------------+-------+ slave:
mysql> show status like 'Rpl_semi_sync_slave_status';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| Rpl_semi_sync_slave_status | ON |
+----------------------------+-------+

二、配置ssh公钥互信

2.1. 本例中manager节点和node节点ip

manager:192.168.20.50

node1:192.168.20.50

node2:192.168.31.3

node3:192.168.31.2

注:manager节点可以安装独立的服务器上,本例为了节省机器,manager安装在了主库(192.168.20.50)上.

2.2. 配置manager和node各节点间的root用户的ssh公钥互信

在三个 mysql 节点分别执行如下操作:(三个都有,包括自己ssh自己)
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.20.50
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.31.2
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.31.3

三、安装 MHA 包

3.1. MHA安装

 manager和node节点安装:

   #先安装依赖  

      wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
      rpm -ivh epel-release-latest-7.noarch.rpm 
   yum install -y perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager
   wget https://qiniu.wsfnk.com/mha4mysql-node-0.58-0.el7.centos.noarch.rpm
   rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm

manager上安装:

wget https://qiniu.wsfnk.com/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

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

3.2、MHA Manager 端配置

   配置主配置文件

 vi /etc/mha/app1.cnf
[server default]
manager_workdir=/var/log/mha/app1
manager_log=/var/log/mha/app1/manager.log

user=root #mysql用户
password=my123456 #mysql密码
ssh_user=root
repl_user=repl_user
repl_password=tt123456
ping_interval=1
#master_binlog_dir= /var/lib/mysql,/var/log/mysql
#secondary_check_script=masterha_secondary_check -s 192.168.20.50 -s 192.168.31.3 -s 192.168.31.2
#master_ip_failover_script="/etc/mha/scripts/master_ip_failover"
#master_ip_online_change_script="/etc/mha/scripts/master_ip_online_change"
#report_script="/etc/mha/scripts/send_report"

[server1]#这里模块不注释,ssh测试会报错,不过没影响
hostname=192.168.20.50
port=
master_binlog_dir=/var/lib/mysql
candidate_master=
check_repl_delay= [server2]
hostname=192.168.31.3
port=
master_binlog_dir=/var/lib/mysql
candidate_master=  #如果候选master有延迟的话,relay日志超过100m,failover切换不能成功,加上此参数后会忽略延迟日志大小。
check_repl_delay= [server3]
hostname=192.168.31.2
port=
master_binlog_dir=/var/lib/mysql
ignore_fail=  #如果这个节点挂了,mha将不可用,加上这个参数,slave挂了一样可以用
no_master=  #从不将这台主机转换为master
PS:以上注释不能写在配置文件里,不然会报错

四、运行

4.1. 检查SSH配置

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

4.2检查MHA当前配置

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

 4.3启动mha

nohup masterha_manager --conf=/etc/masterha/app1/app1.cnf   --remove_dead_master_conf --ignore_last_failover < /dev/null >  /var/log/mha/app1/manager.log  2>&1 &

4.4查看状态

masterha_check_status --conf=/etc/masterha/app1/app1.cnf

4.5关闭mha

masterha_stop  --conf=/etc/masterha/app1/app1.cnf

4.6查看日志

tail -f  /etc/masterha/app1/mha_manager.log

 4.7从库从新加入新主

grep "CHANGE MASTER TO MASTER"  /var/log/mha/app1/manager.log | tail -1

五、Failover应用场景测试

自动failover测试

应用场景1:master dead后,MHA当时已经开启,候选Master库(Slave)会自动failover为Master.

后面我的主库改为192.168.31.3,在这机器执行:systemctl stop mysqld.service

然后192.168.20.50执行:mysql> show master status\G;

    

从库机器192.168.31.2执行:mysql> show slave status\G;

最后把原主库192.168.31.3修复成一个新的slave:

#查看具体修复语句
# grep "CHANGE MASTER TO MASTER"  /etc/masterha/app1/manager.log | tail -
   CHANGE MASTER TO MASTER_HOST='192.168.20.50',MASTER_PORT=, MASTER_LOG_FILE='master-bin.000009', MASTER_AUTO_POSITION=,MASTER_USER='repl_user', MASTER_PASSWORD='xxx';

mysql> CHANGE MASTER TO MASTER_HOST='192.168.20.50',MASTER_PORT=3306, MASTER_LOG_FILE='master-bin.000009', MASTER_AUTO_POSITION=1,MASTER_USER='repl_user', MASTER_PASSWORD='tt123456';

mysql>start slave;

mysql>show slave status\G;

验证。

报错

1.replicates is not defined in the configuration file!

masterha_check_repl --conf=/etc/masterha/app1/app1.cnf
Thu Jan :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Jan :: - [info] Reading application default configuration from /etc/masterha/app1/app1.cnf..
Thu Jan :: - [info] Reading server configuration from /etc/masterha/app1/app1.cnf..
Thu Jan :: - [info] MHA::MasterMonitor version 0.58.
Thu Jan :: - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm, ln671] Master 192.168.20.50: from w
hich slave 192.168.31.2(192.168.31.2:) replicates is not defined in the configuration file!
Thu Jan :: - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln427] Error happened on checking confi
gurations. at /usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm line .
Thu Jan :: - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln525] Error happened on monitoring ser
vers.
Thu Jan :: - [info] Got exit code (Not master dead). 解决:配置文件里面没有manager的主机信息,添加上去。
[server1]
hostname=192.168.20.50
port=3306
master_binlog_dir=/var/lib/mysql
candidate_master=1
check_repl_delay=0

2、[error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm

[error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln427] Error happened on checking confi
gurations. Argument "1 #M-dM-;M-^NM-dM-8M-\rM-eM-0M-^FM-hM-?M-^YM-eM-^OM-0M-d..." isn't numeric in numeric ge (>=) at /usr/s
hare/perl5/vendor_perl/MHA/ServerManager.pm line .
Thu Jan :: - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln525] Error happened on monitoring ser
vers.
解决:
配置文件不能有中文注释。。

centos7 mysql+MHA高可用安装的更多相关文章

  1. MySQL MHA 高可用集群部署及故障切换

    MySQL MHA 高可用集群部署及故障切换 1.概念 2.搭建MySQL + MHA 1.概念: a)MHA概念 : MHA(MasterHigh Availability)是一套优秀的MySQL高 ...

  2. 搭建MySQL MHA高可用

    本文内容参考:http://www.ttlsa.com/mysql/step-one-by-one-deploy-mysql-mha-cluster/ MySQL MHA 高可用集群 环境: Linu ...

  3. Mysql MHA高可用集群架构

    ** 记得之前发过一篇文章,名字叫<浅析MySQL高可用架构>,之后一直有很多小伙伴在公众号后台或其它渠道问我,何时有相关的深入配置管理文章出来,因此,民工哥,也将对前面的各类架构逐一进行 ...

  4. mysql mha高可用架构的安装

    MMM无法全然地保证数据的一致性,所以MMM适用于对数据的一致性要求不是非常高.可是又想最大程度的保证业务可用性的场景对于那些对数据一致性要求非常高的业务,非常不建议採用MMM的这样的高可用性架构.那 ...

  5. mysql+MHA高可用

    MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀 ...

  6. MySQL MHA高可用集群部署及故障切换

    一.MHA概念MHA(MasterHigh Availability)是一套优秀的MySQL高可用环境下故障切换和主从复制的软件.MHA 的出现就是解决MySQL 单点的问题.MySQL故障切换过程中 ...

  7. MySQL mha 高可用集群搭建

    [mha] MHA作为MySQL故障切换和主从提升的高可用软件,在故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一 ...

  8. Centos7之pacemaker高可用安装配置详解

    申明: centos7的pacemaker与6使用的方法不一致,即使用centos6.x的方法在centos7.x上面配置pacemaker不能成功. 因此openstack 上面的centos7.1 ...

  9. mysql+MHA高可用 (一主双从)

    1.准备三台服务器 10.0.0.12 10.0.0.13 10.0.0.14 2.在三台服务器上执行操作 时间同步 [root@ c7m01 ~]# echo "*/5* * * * /u ...

随机推荐

  1. 未能加载文件或程序集“System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKe

    https://bbs.csdn.net/topics/392046946 电脑没安装mvc4,应该是,解决这个问题一上午了今天,然后装完了后就好了! https://www.microsoft.co ...

  2. P2257 YY的GCD(莫比乌斯反演)

    第一次做莫比乌斯反演,推式子真是快乐的很啊(棒读) 前置 若函数\(F(n)\)和\(f(d)\)存在以下关系 \[ F(n)=\sum_{n|d}f(d) \] 则可以推出 \[ f(n)=\sum ...

  3. 到底什么是 ROI Pooling Layer ???

    到底什么是 ROI Pooling Layer ??? 只知道 faster rcnn 中有 ROI pooling, 而且其他很多算法也都有用这个layer 来做一些事情,如:SINT,检测的文章等 ...

  4. 常用的 Linux 命令

    列出文件列表:ls [参数 -a -l]创建目录和移除目录:mkdir rmdir用于显示文件后几行内容:tail打包:tar -xvf打包并压缩:tar -zcvf查找字符串:grep显示当前所在目 ...

  5. Paper Reviews and Presentations

    Copied from Advanced Computer Networks, Johns Hopkins University. Paper Reviews and Presentations Ea ...

  6. Excel 导出通用类

    public class ExportToExcelHelper { public static void ExportExcel(DataTable dt) { try { //创建一个工作簿 IW ...

  7. hdu 6070 Dirt Ratio 线段树+二分

    Dirt Ratio Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Spe ...

  8. MySQL中字符串和数字拼接

    select * from qa_employ where EMPLOY_GROUP =2 原先雇佣表中所有雇佣姓名全部是"张三", 希望将雇用姓名变得不一样,比如张三+id SQ ...

  9. vue模板编译

    Vue 的模板编译是在 $mount 的过程中进行的,在 $mount 的时候执行了 compile 方法来将 template 里的内容转换成真正的 HTML 代码. complie 最终生成 re ...

  10. Codeforces 1076 E - Vasya and a Tree

    E - Vasya and a Tree 思路: dfs动态维护关于深度树状数组 返回时将当前节点的所有操作删除就能保证每次访问这个节点时只进行过根节点到当前节点这条路径上的操作 代码: #pragm ...