mysql 高可用架构 proxysql 之二 架构

os:centos 7.4
mysql: 5.7
proxysql: 1.4.10

ip 规划如下:

192.168.56.101 node1 (proxysql)

192.168.56.102 node2 (mysql master)
192.168.56.103 node3 (mysql slave)
192.168.56.104 node4 (mysql slave)

连接 proxysql 6032 管理端口

# mysql -u admin -p admin -h 127.0.0.1 -P6032 --prompt='Admin> '
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.30 (ProxySQL Admin Module)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Admin> 
Admin> show databases;
+-----+---------------+-------------------------------------+
| seq | name          | file                                |
+-----+---------------+-------------------------------------+
| 0   | main          |                                     |
| 2   | disk          | /var/lib/proxysql/proxysql.db       |
| 3   | stats         |                                     |
| 4   | monitor       |                                     |
| 5   | stats_history | /var/lib/proxysql/proxysql_stats.db |
+-----+---------------+-------------------------------------+
5 rows in set (0.00 sec)

main 数据库

内存配置数据库,即MEMORY,表里存放后端db实例、用户验证、路由规则等信息。表名以runtime_开头的表示ProxySQL当前运行的配置内容,不能通过DML语句修改。只能修改对应的不以 runtime开头的表,然后“LOAD”使其生效,“SAVE”使其存到硬盘以供下次重启加载。

mysql> use main;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+--------------------------------------------+
| tables                                     |
+--------------------------------------------+
| global_variables                           |
| mysql_collations                           |
| mysql_group_replication_hostgroups         |
| mysql_query_rules                          |
| mysql_query_rules_fast_routing             |
| mysql_replication_hostgroups               |
| mysql_servers                              |
| mysql_users                                |
| proxysql_servers                           |
| runtime_checksums_values                   |
| runtime_global_variables                   |
| runtime_mysql_group_replication_hostgroups |
| runtime_mysql_query_rules                  |
| runtime_mysql_query_rules_fast_routing     |
| runtime_mysql_replication_hostgroups       |
| runtime_mysql_servers                      |
| runtime_mysql_users                        |
| runtime_proxysql_servers                   |
| runtime_scheduler                          |
| scheduler                                  |
+--------------------------------------------+
20 rows in set (0.00 sec)

global_variables
看名字就知道是参数设置,可以参考https://github.com/sysown/proxysql/wiki/Global-variables
通过set来设置,如:

mysql> set mysql-threads = 100;
Query OK, 1 row affected (0.00 sec)

mysql_query_rules
指定Query路由到后端不同服务器的规则列表。

mysql_replication_hostgroups
监视指定主机组中所有服务器的read_only值,并且根据read_only的值将服务器分配给写入器或读取器主机组

定义 hostgroup 的主从关系。ProxySQL monitor 模块会监控 HG 后端所有servers 的 read_only 变量,如果发现从库的 read_only 变为0、主库变为1,则认为角色互换了,自动改写 mysql_servers 表里面 hostgroup 关系,达到自动 Failover 效果。

mysql_servers
后端可以连接MySQL服务器的列表。

mysql_users
配置后端数据库的账号和监控的账号

scheduler
调度器是一个类似于cron的实现,集成在ProxySQL中,具有毫秒的粒度。通过脚本检测来设置ProxySQL。

disk 数据库

持久化到硬盘的配置,sqlite数据文件。

stats 数据库

proxysql运行抓取的统计信息,包括到后端各命令的执行次数、流量、processlist、查询种类汇总/执行时间等等。

monitor 数据库

存储 monitor 模块收集的信息,主要是对后端db的健康/延迟检查。

参考:
https://github.com/sysown/proxysql/wiki
https://github.com/sysown/proxysql/wiki/Global-variables

posted @ 2018-08-13 15:16  peiybpeiyb  阅读(168)  评论(0编辑  收藏  举报