七:linux之mysl57高可用mha4mysql

linux之mysl57高可用mha4mysql

1 环境准备 master (主机) salve1(从机) slave2(从机) mha(mha管理) 都安装了mysql 正常


2 ssh免密登录 master (主机) salve1(从机) slave2(从机) mha(mha管理)分别安装

ssh-keygen -t rsa 三回车

ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.106.128

ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.106.129

ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.106.130

ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.106.131

添加完 用 ping 都测试下


3 master (主机) salve1(从机) slave2(从机) mha(mha管理)分别安装

1)添加依赖

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum install perl-DBD-MySQL -y  

yum install perl-Config-Tiny -y

yum install epel-release -y

yum install perl-Log-Dispatch -y

yum install perl-Parallel-ForkManager -y

yum install perl-Time-HiRes -y

yum install perl-CPAN -y

2)安装节点

wget https://github.com/yoshinorim/mha4mysql-node/releases/download/v0.58/mha4mysql-node-0.58-0.el7.centos.noarch.rpm

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


4  mha(mha管理)安装  注意:centos8 不支持 mha4mysql-manager

wget https://github.com/yoshinorim/mha4mysql-manager/releases/download/v0.58/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

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

以上 4不都正常安装 接下来就开始分别配置 测试


5 关闭所有库的防火墙

systemctl stop firewalld 


6 配置  master (主机)

#bin_log配置

log_bin=mysql-bin

server-id=1

sync-binlog=1

binlog-ignore-db=information_schema

binlog-ignore-db=mysql

binlog-ignore-db=performation_schema

binlog-ignore-db=sys

#relay_log配置

relay_log=mysql-relay-bin

log_slave_updates=1

relay_log_purge=0

#gtid配置

#开启gtid

gtid_mode=on

enforce_gtid_consistency=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=1000


7 重启mysql

systemctl restart mysqld

mysql -uroot -p


8 进行授权

grant replication slave on *.* to 'root'@'%' identified by 'Yumeko213@';

flush privileges;

grant all privileges on *.* to 'root'@'%' identified by 'Yumeko213@';

flush privileges;


9 配置  salve1(从机) slave2(从机)

#bin_log配置

log_bin=mysql-bin

#服务器ID,从库1是2,从库2是3

server-id=2

sync-binlog=1

binlog-ignore-db=information_schema

binlog-ignore-db=mysql

binlog-ignore-db=performation_schema

binlog-ignore-db=sys

#relay_log配置

relay_log=mysql-relay-bin

log_slave_updates=1

relay_log_purge=0

read_only=1

#gtid配置

#开启gtid

gtid_mode=on

enforce_gtid_consistency=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=1000


10 重启mysql

systemctl restart mysqld

mysql -uroot -p


11进行授权

grant replication slave on *.* to 'root'@'%' identified by 'Yumeko213@';

flush privileges;

grant all privileges on *.* to 'root'@'%' identified by 'Yumeko213@';

flush privileges;


12 设置从库复制的主库地址

change master to master_host='192.168.106.128',master_port=3306,master_user='root',master_password='Yumeko213@',master_auto_position=1;


13 测试以上无问题

主库 show master status;

从库 start slave;    show slave status \G;


14 mha配置

1)创建目录 和 文件

mkdir -p /etc/mha/

touch /var/log/mha/manager.log

mkdir -p /data/log/mha

2)公共配置vim /etc/masterha_default.cnf

[server default]

user=root

password=Yumeko213@

repl_user=root

repl_password=Yumeko213@

ssh_user=root

master_binlog_dir=/var/lib/mysql

remote_workdir=/data/log/mha

ping_interval=1

secondary_check_script=masterha_secondary_check -s 192.168.106.128 -s 192.168.106.129 -s 192.168.106.130

3)主配置vim /etc/mha/app1.cnf

[server default]

manager_workdir=/var/log/mha/manager

manager_log=/var/log/mha/manager.log

[server1]

hostname=192.168.106.128

port=3306

candidate_master=1

[server2]

hostname=192.168.106.129

port=3306

candidate_master=1

[server3]

hostname=192.168.106.130

port=3306


15 测试管理 

1)检查SSH连接

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

出现All SSH connection tests passed successfully.

2)检查复制配置

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

出现MySQL Replication Health is OK!

3)后台启动

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

出现app1 (pid:5057) is running(0:PING_OK), master:192.168.106.128

4)检查启动状态

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

出现app1 (pid:6312) is running(0:PING_OK), master:192.168.106.128

5)停止

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

出现 Stopped app1 successfully.


16 测试主故障转移

killall -9 mysqld

cat /var/log/mha/manager.log

17撤销主从关系

stop slave;

reset slave all;

show slave status;  就为空了,并且删除了本地内存重点 

删除master.info和relay-log.info文件;

删除所有的relay log(包括还没有应用完的日志),创建一个新的relay log文件

你可能感兴趣的:(七:linux之mysl57高可用mha4mysql)