ProxySQL设置主机组问题

时间:2019-08-09 01:52:28

标签: proxysql

关于AWS的此指令。

https://aws.amazon.com/blogs/database/how-to-use-proxysql-with-open-source-platforms-to-split-sql-reads-and-writes-on-amazon-aurora-clusters/

我不确定hostgroup_id是否存在问题。当我运行“ SELECT hostgroup_id,hostname,status from mysql_servers;”时,它对主数据库显示10,对只读副本显示20,但是,当我运行“ LOAD MYSQL SERVERS TO RUNTIME; “将MYSQL服务器保存到磁盘;”,两个主机的hostgroup_id都更改为20。这正常吗?请指教。谢谢

ProxySQLAdmin> INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES ('uatrds1.ap-southeast-2.rds.amazonaws.com 



',10,3306,1000,10000);
Query OK, 1 row affected (0.00 sec)

ProxySQLAdmin> INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES ('uatreadreplica.ap-southeast-2.rds.amazonaws.com 



',20,3306,1000,10000);
Query OK, 1 row affected (0.00 sec)

ProxySQLAdmin> SELECT hostgroup_id, hostname, status FROM mysql_servers;
+--------------+--------------------------------------------------------------+--------+
| hostgroup_id | hostname                                                     | status |
+--------------+--------------------------------------------------------------+--------+
| 10           | uatrds1.ap-southeast-2.rds.amazonaws.com 



        | ONLINE |
| 20           | uatreadreplica.ap-southeast-2.rds.amazonaws.com 



 | ONLINE |
+--------------+--------------------------------------------------------------+--------+

ProxySQLAdmin> LOAD MYSQL SERVERS TO RUNTIME;
Query OK, 0 rows affected (0.00 sec)

ProxySQLAdmin> SAVE MYSQL SERVERS TO DISK;
Query OK, 0 rows affected (0.02 sec)


ProxySQLAdmin> SELECT hostgroup_id, hostname, status FROM mysql_servers;
+--------------+--------------------------------------------------------------+--------+
| hostgroup_id | hostname                                                     | status |
+--------------+--------------------------------------------------------------+--------+
| 20           | uatrds1.ap-southeast-2.rds.amazonaws.com 



        | ONLINE |
| 20           | uatreadreplica.ap-southeast-2.rds.amazonaws.com 



 | ONLINE |
+--------------+--------------------------------------------------------------+--------+
2 rows in set (0.00 sec)

1 个答案:

答案 0 :(得分:0)

首先,检查runtime_mysql_servers的运行时间。

第二,当使用auror而非读取器的只读端点时,还应该使用mysql_replication_hostgroups来设置check_type = 'innodb_read_only'表。否则,您的设置会在故障转移时损坏(在故障转移时,所有的aurora节点都会重新启动)。

MySQL [(none)]> select * from runtime_mysql_servers;
+--------------+---------------------------------------------------------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname                                                      | port | gtid_port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+---------------------------------------------------------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 0            | some-aurora-node    | 3306 | 0         | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |
| 1            | an other-aurora-node| 3306 | 0         | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |
+--------------+---------------------------------------------------------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
2 rows in set (0.00 sec)

MySQL [(none)]> select * from runtime_mysql_replication_hostgroups;
+------------------+------------------+------------------+---------+
| writer_hostgroup | reader_hostgroup | check_type       | comment |
+------------------+------------------+------------------+---------+
| 0                | 1                | innodb_read_only |         |
+------------------+------------------+------------------+---------+
1 row in set (0.00 sec)

MySQL [(none)]> select rule_id, active, destination_hostgroup, match_pattern from runtime_mysql_query_rules;
+---------+--------+-----------------------+-------------------------+
| rule_id | active | destination_hostgroup | match_pattern           |
+---------+--------+-----------------------+-------------------------+
| 1       | 1      | 1                     | ^SELECT                 |
| 2       | 1      | 0                     | ^SELECT.*FOR UPDATE$    |
+---------+--------+-----------------------+-------------------------+
2 rows in set (0.00 sec)

此外,别忘了向极光添加monitor凭据。比proxysql能够(在故障转移之后)动态地确定自身的读取器和写入器端点。

CREATE USER 'proxysql'@'%' IDENTIFIED BY 'monitor';
GRANT USAGE ON *.* TO 'proxysql'@'%';

monitor是proxysql的监视用户的默认密码。

我强烈建议您阅读proxysql https://github.com/sysown/proxysql/wiki的维基百科,它有很好的文档记录,并且有很多示例。
关于proxysql的第二个信任来源是percona博客:https://www.percona.com/doc/percona-xtradb-cluster/5.7/howtos/proxysql.html
不要依赖营销博客:)