环境: 三台机器
主服务器: 192.168.1.130
主备机器: 192.168.1.131
监控机器: 192.168.1.132
130和131, 是mysql双主架构
1.在三台机器上安装mha4mysql-node
yum -y install perl-DBD-MySQL
tar -zxvpf mha4mysql-node-0.56.tar.gz
mha4mysql-node-0.56.tar.gz
cd mha4mysql-node-0.56
perl Makefile.PL
----------------
可能报错:
Can‘t locate ExtUtils/MakeMaker.pm
Can‘t locate CPAN.pm
解决办法:
yum install perl perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN
----------------
make && make install
2.在主服务器和主备机器上:
授权账户
mysql> grant all on *.* to "mha"@"192.168.32.%" identified by ‘123456‘;
主备修改my.cnf: 增加两个参数
[mysqld] read-only relay_log_purge=0
3.在监控机器上安装mha4mysql-manager
yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Config-IniFiles perl-Time-HiRes
tar -zxvpf mha4mysql-manager-0.56.tar.gz
mha4mysql-manager-0.56.tar.gz
cd mha4mysql-manager-0.56
perl Makefile.PL
------------------
可能报错:
Can‘t locate Log/Dispatch.pm
解决办法:
perl -MCPAN -e "install Log::Dispatch"
------------------
make && make install
4.修改manager的配置文件: 详见...
mkdir /etc/masterha
mkdir -p /masterha/app1
cd mha4mysql-manager-0.56
cp samples/conf/* /etc/masterha/
cp samples/scripts/* /usr/local/bin/
5.在三台机器上都执行: 建立ssh无密码登录环境
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
//132机器: 执行后两句
//131机器: 执行第二句
//130机器: 执行第三句
6.回到监控机器, 检查: ssh登录 和 repl复制
masterha_check_ssh --conf=/etc/masterha/app1.cnf
------------------
可能报错:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)
解决办法: ???
chmod 700 /root/
chmod 700 /root/.ssh/
chmod 644 /root/.ssh/authorized_keys
chmod 600 /root/.ssh/id_rsa
------------------
masterha_check_repl --conf=/etc/masterha/app1.cnf
都无误后可以启动manager
nohup masterha_manager --conf=/etc/masterha/app1.cnf < /dev/null > /masterha/app1/manager.log 2>&1 &
7.在主备机器或从服务器上, 加入计划任务
00 00 * * * /usr/local/bin/purge_relay_logs –user=mha –password=123456 –disable_relay_log_purge >> /masterha/purge_relay_logs.log 2>&1
正常情况下,master主机用虚拟IP对外提供写服务。master宕掉后, master将转移到主备
配置文件: /etc/masterha/app1.cnf
[server default] user=mha password=123456 manager_workdir=/masterha/app1 manager_log=/masterha/app1/manager.log remote_workdir=/masterha/app1 ssh_user=root repl_user=rep repl_password=123456 ping_interval=1 secondary_check_script= masterha_secondary_check -s 192.168.1.130 -s 192.168.1.131 master_ip_failover_script=/usr/local/bin/master_ip_failover [server1] hostname=192.168.32.130 ssh_port=22 master_binlog_dir=/usr/local/mysql/data candidate_master=1 [server2] hostname=192.168.32.131 ssh_port=22 master_binlog_dir=/usr/local/mysql/data candidate_master=1
;