MHA的VIP
# MHA + keepalived
1.keepalived如何找数据最新的从库
2.需要等待MHA切换完成再漂移VIP
3.多个脚本同时执行
4.两台之间互相切换
5.如何保证另外一台一定最新
6.半同步阻塞主库数据写入,影响性能
7.半同步从库不提供服务
8.互相切换的两台数据库升配,配置要高于另外两台数据库
### 1.修改MHA 配置文件
[root@mha-manager ~]# vim /etc/mha/app1.cnf
[server default]
master_ip_failover_script=/etc/mha/app1/master_ip_failover
### 2.修改MHA脚本
[root@mha-manager ~]# mv master_ip_failover /etc/mha/app1
my $vip = '172.16.1.55/24';
my $key = '1';
my $ssh_start_vip = "/sbin/ifconfig eth1:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig eth1:$key down";
### 3.查看当前MHA集群状态,找到主库
[root@mha-manager ~]# masterha_check_status --conf=/etc/mha/app1.cnf
app1 (pid:26500) is running(0:PING_OK), master:172.16.1.51
### 4.给脚本执行权限
[root@mha-manager ~]# chmod +x /etc/mha/app1/master_ip_failover
### 5.手动在主库上绑定VIP
[root@db01 ~]# ifconfig eth1:1 172.16.1.55/24
### 6.重启MHA
[root@mha-manager ~]# systemctl stop mha
[root@mha-manager ~]# systemctl start mha
## 添加脚本后,启动不起来的原因:
1.脚本权限问题
[root@mha-manager ~]# chmod +x /etc/mha/app1/master_ip_failover
2.脚本语法问题
3.脚本格式问题
[root@mha-manager ~]# dos2unix /etc/mha/app1/master_ip_failover
dos2unix: converting file /etc/mha/app1/master_ip_failover to Unix format ...
使用mysqlbinlog同步binlog
## MHA 配置 binlog server
# 1.修改MHA配置文件
[root@mha-manager ~]# vim /etc/mha/app1.cnf
[binlog1]
no_master=1
hostname=172.16.1.50
master_binlog_dir=/data/mysql/binlog/
# 2.创建binlog目录
[root@mha-manager ~]# mkdir -p /data/mysql/binlog/
# 3.manager服务器安装mysql5.7客户端
[root@mha-manager ~]# cat /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch
enabled=1
gpgcheck=0
[root@mha-manager binlog]# yum install -y mysql
# 4.实时同步binlog
[root@mha-manager binlog]# mysqlbinlog -R --host=172.16.1.55 --user=mha --password=mha --raw --stop-never mysql-bin.000001 &