管理vip的方式:keepalived
-
1.如何保证,一定从51切到53
- 在MHA的配置文件中,加入候选主库的参数
candidate_master=1 check_repl_delay=0
-
2.如何保证53一定是数据最新的从库
- 半同步
-
3.影响主库性能,超时就恢复成异步复制
- 买配置高的机器(磁盘性能高,内存/cpu:1核2G、2核4G、4核8G)
- 半同步复制的从库,不提供服务
- 费用高,花钱多
管理vip的方式:MHA自带脚本
master_ip_failover_script is not set. Skipping invalidating dead master IP address.
[root@db01 scripts]# ll
total 32
-rwxr-xr-x 1 4984 users 3648 Apr 1 2014 master_ip_failover
[root@db01 scripts]# pwd
/root/mha4mysql-manager-0.56/samples/scripts
my $vip = '10.0.0.55/24';
my $key = '0';
my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down";
#修改配置文件
[root@db02 mha]# vim app1.cnf
master_ip_failover_script=/etc/mha/app1/master_ip_failover
#停止MHA
master_ip_failover_script=/etc/mha/app1/master_ip_failover
#启动MHA
[root@db02 app1]# nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /etc/mha/app1/manager.log 2>&1 &
#1.语法问题
#2.权限问题
[root@db02 app1]# chmod +x /etc/mha/app1/master_ip_failover
#3.格式问题
[root@db02 app1]# yum install -y dos2unix
[root@db02 app1]# dos2unix /etc/mha/app1/master_ip_failover
dos2unix: converting file /etc/mha/app1/master_ip_failover to Unix format ...
#手动添加vip在主库上
[root@db01 scripts]# ifconfig eth0:0 10.0.0.55/24
[root@db01 scripts]# ifconfig eth0:0
eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.55 netmask 255.255.255.0 broadcast 10.0.0.255
ether 00:0c:29:e9:87:43 txqueuelen 1000 (Ethernet)
MHA VIP管理切换测试
#修改程序连接数据库的IP
[root@db02 ~]# vim a.sh
#!/bin/bash
num=1
while true;do
mysql -uroot -p123 -h10.0.0.55 -e 'insert into rep.rep values('"$num"');commit;'
let num++
sleep 1
done
#启动程序
[root@db02 ~]# sh a.sh
#关闭db02,多db03的IO线程
mysql> stop slave io_thread;
MHA VIP管理实现自动化恢复集群
#每台机器上放recover
#!/bin/bash
#old_master=`ssh 10.0.0.52 "sed -nr 's#^Master (.*)\(.*!$#\2#gp' /etc/mha/app1/manager.log"`
change=`ssh 10.0.0.52 "grep -i 'change master to' /etc/mha/app1/manager.log"|awk -F: '{print $NF}'|sed 's#xxx#123#g'`
/etc/init.d/mysqld start
mysql -uroot -p123 -e "$change start slave;"
ssh 10.0.0.52 '\cp /etc/mha/app1.cnf.ori /etc/mha/app1.cnf'
[root@db02 ~]# vim /etc/mha/app1/master_ip_failover
sub start_vip() {
`ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
`ssh $ssh_user\@$orig_master_host \" /bin/sh /root/recovery_mha.sh \"`;
}
MHA binlog server
如果断电,断网,怎么办?
#添加一个binlog server
[root@db02 ~]# vim /etc/mha/app1.cnf
[binlog1]
no_master=1
hostname=10.0.0.53
master_binlog_dir=/data/mysql/binlog/
#创建实时备份binlog的目录
[root@db03 ~]# mkdir /data/mysql/binlog/ -p
#逻辑备份工具
1.mysqldump
2.into out file
3.binlog
4.replication
---------------
5.mysqlbinlog
#实时拉取binlog
[root@db03 ~]# cd /data/mysql/binlog/
[root@db03 binlog]# mysqlbinlog -R --host=10.0.0.52 --user=mha --password=mha --raw --stop-never mysql-bin.000001 &