#将percona下载到两台主机上
wget https://www.percona.com/downloads/percona-toolkit/3.1.0/binary/redhat/7/x86_64/percona-toolkit-3.1.0-2.el7.x86_64.rpm
一,pt-heartbeat,监测主从延迟工具
主库创建一张heartbeat表,表中有个时间戳字段。主库上pt-heartbeat的update线程会在指定时间间隔更新时间戳。
从库上的pt-heartbeat的monitor线程会检查复制的心跳记录,这个记录就是主库修改的时间戳。然后和当前系统时间进行对比,得出时间上的差异,差异值就是延迟的时间大小。由于heartbeat表中有server_id字段,在监控某个从库的延迟时指定参考主库的server_id即可。
1,准备2台主机,配置mysql
#在主机A上配置mysql主
#关闭防火墙和selinux
[root@kafka01 ~] systemctl stop firewalld.service
[root@kafka01 ~] setenforce 0
[root@kafka01 ~] yum -y install mariadb mariadb-server
[root@kafka01 ~] vim /etc/my.cnf #开启二进制日志
[mysqld]
server-id=1
log-bin=mysql-bin
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignoreql
[root@kafka01 ~] systemctl start mariadb #启动
[root@kafka01 ~] mysql
MariaDB [(none)]> grant all on *.* to 'slave'@'192.168.59.111' identified by '123456'; #创建授权用户
MariaDB [(none)]> flush privileges; #刷新
MariaDB [(none)]> show master status; #查看二进制日志
+------------------+----------+--------------+---------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB
+------------------+----------+--------------+---------------------------------------------+
|mysql-bin.000003| 462 | | information_schema,performance_schema,mysql
+------------------+----------+--------------+---------------------------------------------+
#在主机B上配置mysql从
#关闭防火墙和selinux
[root@kafka02 ~] systemctl stop firewalld.service
[root@kafka02 ~] setenforce 0
[root@kafka02 ~] yum -y install mariadb mariadb-server
[root@kafka02 ~] vim /etc/my.cnf
[mysqld]
server-id=2
[root@kafka02 ~] systemctl start mariadb
[root@kafka02 ~] mysql
MariaDB [(none)]> change master to master_host='192.168.59.110',master_user='slave',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=462;
MariaDB [(none)]> slave start;
MariaDB [(none)]> show slave status\G
*************************** 1. row *********************