笔者做游戏运维开发,最近新项目有调研构建全球发行平台(登录支付等游戏共通业务平台)。
于是进行构建,然后测试Mysql压力测试下的主从延时。
以下是梳理的安装、测试步骤,以及遇到问题的解决方案。
笔者环境:
AWS
ec2:ubuntu18.04
mysql:Aurora 2.04.1,mysql5.7
sudo apt install wget
wget https://repo.percona.com/apt/percona-release_0.1-6.$(lsb_release -sc)_all.deb
wget https://www.percona.com/downloads/percona-toolkit/3.0.12/binary/debian/bionic/x86_64/percona-toolkit_3.0.12-1.bionic_amd64.deb
sudo dpkg -i percona-release_0.1-6.$(lsb_release -sc)_all.deb
sudo dpkg -i percona-toolkit_3.0.12-1.bionic_amd64.deb
顺利的话,可以看到如下内容
Selecting previously unselected package percona-release.
(Reading database ... 105206 files and directories currently installed.)
Preparing to unpack percona-release_0.1-6.bionic_all.deb ...
Unpacking percona-release (0.1-6.bionic) ...
Setting up percona-release (0.1-6.bionic) ...
Percona Toolkit
sudo apt update
sudo apt-get install percona-toolkit
一般报错是说组件找不到,按照提示安装组件即可
apt-get install libdbi-perl libdbd-mysql-perl libterm-readkey-perl libio-socket-ssl-perl
apt --fix-broken install
CREATE USER 'te'@'test' IDENTIFIED BY 'te密码'; #主从同步用户
GRANT SELECT, PROCESS, REPLICATION CLIENT ON *.* TO 'te'@'%' IDENTIFIED BY 'te密码';
GRANT REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'te'@'test';
grant all privileges on test.* to '%'@'%';
GRANT SELECT, PROCESS, REPLICATION CLIENT ON *.* TO 'pt_checksum'@'%' IDENTIFIED BY 'pt_checksum'; #pt-heartbeat主从延时用户,也可以只用一个
然后我们给予这个用户访问test数据库的权限。
grant all privileges on test.* topt_checksum@'%';
show grants for pt_checksum;
FLUSH PRIVILEGES;
call mysql.rds_stop_replication;
CALL mysql.rds_set_external_master ('主库ip', 3306,
'te', 'te密码', 'mysql-bin-changelog.000006',1759, 0);
CALL mysql.rds_start_replication;
show slave status;
从库不报错,正常启动即可
可以在主库写数据,测试是否同步成功
ec2实例上启动后台
pt-heartbeat h='主库ip',u='pt_checksum',p='pt_checksum',P=3306 -D test --create-table --interval=1 --update --replace --daemonize
从库上访问延迟
pt-heartbeat h='从库ip',u='pt_checksum', p='pt_checksum', P=3306 -D test --table=heartbeat --monitor --master-server-id=510609414 --frames=1m,2m,3m,4m,5m,10m
参考资料:
在Ubuntu 18.04系统上安装和使用Percona Toolkit