MySQL运维实战之ProxySQL(9.5)proxysql和MySQL Group Replication配合使用

俊达2年前技术文章825

如果后端MySQL使用了Group Replication,可通过配置mysql_group_replication_hostgroups表来实现高可用

mysql_group_replication_hostgroups

字段

描述

writer_hostgroup

写hostgroup。read_only和super_read_only OFF的节点。

backup_writer_hostgroup

如果可写的节点数超过max_writers,将超出限制的节点的hostgroup设置为backup_writer_hostgroup

reader_hostgroup

读hostgroup。read_only或super_read_only ON的节点放入改hostgroup。

offline_hostgroup

如果后端mysql实例健康检查失败或group replication状态异常,则会被移入offline_hostgroup

active

是否启用。

max_writers

可写节点数上限。超过该限制数量的可写节点会放入backup_writer_hostgroup

writer_is_also_reader

如果设置为0,则只有只读节点加入reader_hostgroup。

如果设置成1,则writer_hostgroup中的节点会同时加入reader_hostgroup。

如果设置为2,则只会把backup_writer_hostgroup中的节点加入reader_hostgroup。(如果backup_writer_hostgroup中无节点,好像也会把writer_hostgroup中的节点加入到reader_hostgroup,疑似bug)。

max_transactions_behind


comment



配置集群节点

insert into mysql_servers (
  hostgroup_id, hostname, port, max_replication_lag)
values ( 200, '172.16.121.236', 3306, 3);

insert into mysql_servers (
  hostgroup_id, hostname, port, max_replication_lag)
values ( 210, '172.16.121.237', 3306, 3);


load mysql servers  to runtime; 
SAVE MYSQL servers  TO DISK;


配置集群信息

insert into mysql_group_replication_hostgroups
(writer_hostgroup, backup_writer_hostgroup, reader_hostgroup, 
offline_hostgroup, active, max_writers, writer_is_also_reader,
max_transactions_behind, comment)
values(200, 201, 210, 202, 1, 1, 0, 0, 'mysql mgr cluster 1');

load mysql servers to runtime;
save mysql servers to disk;

创建和配置用户信息

在后端创建用户

mysql> create user 'mgr'@'%' identified by 'mgr123';
Query OK, 0 rows affected (0.06 sec)

mysql> grant select,insert,update,delete,create,drop on *.* to 'mgr'@'%';
Query OK, 0 rows affected (0.02 sec)


在proxysql配置用户信息

insert into mysql_users
(username, password, transaction_persistent, backend, frontend, default_hostgroup, comment)
values ('mgr', 'mgr123', 1, 1, 1, 200, 'backend user for mgr cluster');

load mysql users  to runtime; 
save mysql users to disk;



按上面的步骤配置后,就实现了基于MySQL Group Replication和ProxySQL的高可用架构。

相关文章

MySQL运维实战之备份和恢复(8.8)恢复单表

xtrabackup支持单表恢复。如果一个表使用了独立表空间(innodb_file_per_table=1),就可以单独恢复这个表。1、Prepareprepare时带上参数--export,xtr...

MySQL运维实战(2.3)MySQL的权限体系和一个例子

mysql权限按授权范围分为3大类全局权限。全局权限是用于管理系统模块的权限。跟具体的数据库或对象无关。授权时需要指定为*.*数据库权限对象权限对于具体的数据库对象的权限,如表、字段级别的权限。MyS...

MySQL优化器特性(一)IN和Exists(semijoin)子查询优化策略

这篇文章中的SQL和执行计划在mysql 8.0.31环境下进行测试。测试的表结构和数据:表结构mysql> show create table tp\G...

MySQL运维实战(7)建立复制

建立复制的基本步骤1、主库开启binlog主库需要配置的关键参数server_id:主备库需要设置为不同。log_bin:binlog文件的前缀,可以指定绝对路径,也可以只指定文件名。若不指定路径,b...

MySQL运维实战(5.2) MySQL charset基本概念

mysql多字符集mysql支持多字符集。一个数据库中可以存储不同字符集的数据,一个表的不同字段可以使用不同的字符集。mysql> show character s...

MySQL运维实战之备份和恢复(8.9)xtrabackup备份指定表

备份部分表如果实例设置了参数innodb_file_per_table,xtrabackup可以备份部分表。通过--tables,--tables-file,--databases,--databas...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。