2019-11-18
直接上我在生产环境的配置过程:
登录到proxysql集群的任意节点的管理控制台,执行下面的操作:
Admin> SELECT DISTINCT digest, digest_text FROM stats_mysql_query_digest WHERE digest_text LIKE '%@%'; -- 查看当前sql明细和摘要情况
Admin> SELECT DISTINCT 1,digest,2,0 FROM stats_mysql_query_digest WHERE digest_text LIKE '%@%'; -- 查看sql指纹
+---+--------------------+---+---+
| 1 | digest | 2 | 0 |
+---+--------------------+---+---+
| 1 | 0x928841C8AEDD64F9 | 2 | 0 |
| 1 | 0x9771AB06EF4857A5 | 2 | 0 |
| 1 | 0xA9919C0B1C3491E6 | 2 | 0 |
| 1 | 0xEDF9C60BDFD2F5B0 | 2 | 0 |
| 1 | 0x226CD90D52A2BA0B | 2 | 0 |
| 1 | 0x82A12D4C4E7B0A28 | 2 | 0 |
| 1 | 0xA072D1AB0FD3C016 | 2 | 0 |
| 1 | 0x7CDEEF2FF695B7F8 | 2 | 0 |
+---+--------------------+---+---+
8 rows in set (0.01 sec)
-- 在proxysql中插入sql改写规则
Admin> INSERT INTO
mysql_query_rules(active,digest,multiplex,apply)
SELECT DISTINCT 1,digest,2,0 FROM stats_mysql_query_digest WHERE digest_text LIKE '%@%';
select * from mysql_query_rules ;
Admin> select rule_id,digest,multiplex,apply,comment from mysql_query_rules ;
+---------+--------------------+-----------+-------+---------+
| rule_id | digest | multiplex | apply | comment |
+---------+--------------------+-----------+-------+---------+
| 1 | 0x928841C8AEDD64F9 | 2 | 0 | NULL |
| 2 | 0x9771AB06EF4857A5 | 2 | 0 | NULL |
| 3 | 0xA9919C0B1C3491E6 | 2 | 0 | NULL |
| 4 | 0xEDF9C60BDFD2F5B0 | 2 | 0 | NULL |
| 5 | 0x226CD90D52A2BA0B | 2 | 0 | NULL |
| 6 | 0x82A12D4C4E7B0A28 | 2 | 0 | NULL |
| 7 | 0xA072D1AB0FD3C016 | 2 | 0 | NULL |
| 8 | 0x7CDEEF2FF695B7F8 | 2 | 0 | NULL |
+---------+--------------------+-----------+-------+---------+
8 rows in set (0.00 sec)
-- 将配置load到内存生效,并持久化到文件
Admin> LOAD MYSQL QUERY RULES TO RUNTIME;
Admin> SAVE MYSQL QUERY RULES TO DISK;
Admin> select * from runtime_mysql_query_rules ; -- 确认是否生效
执行完上述操作后,我们稍等片刻看下grafana监控,如下:
我这里降低不明显的原因是: 我pxc上的业务请求比较少,都是些内部服务,因此产生的sql指纹也比较少,如果对于一个非常繁忙的pxc集群而言,我们在前面的proxysql做了上述的多路复用配置后,可以大幅度降低后端pxc节点的连接数。