ProxySQL service discovery mechanism

Internal ProxySQL have a Monitor module, to monitor the back-end database via a monitor accounts, monitoring should include: database availability, whether read_only and slave delay.

Configuration Monitoring Account

First, configure the monitor account ProxySQL. It is through global variables to configure.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
mysql> select * from global_variables where variable_name like '%monitor%';
+-----------------------------------------------------+----------------+
| variable_name | variable_value |
+-----------------------------------------------------+----------------+
| mysql-monitor_enabled | true |
| mysql-monitor_connect_timeout | 600 |
| mysql-monitor_ping_max_failures | 3 |
| mysql-monitor_ping_timeout | 1000 |
| mysql-monitor_read_only_max_timeout_count | 3 |
| mysql-monitor_replication_lag_interval | 10000 |
| mysql-monitor_replication_lag_timeout | 1000 |
| mysql-monitor_groupreplication_healthcheck_interval | 5000 |
| mysql-monitor_groupreplication_healthcheck_timeout | 800 |
| mysql-monitor_replication_lag_use_percona_heartbeat | |
| mysql-monitor_query_interval | 60000 |
| mysql-monitor_query_timeout | 100 |
| mysql-monitor_slave_lag_when_null | 60 |
| mysql-monitor_wait_timeout | true |
| mysql-monitor_writer_is_also_reader | true |
| mysql-monitor_username | monitor |
| mysql-monitor_password | monitor |
| mysql-monitor_history | 600000 |
| mysql-monitor_connect_interval | 60000 |
| mysql-monitor_ping_interval | 10000 |
| mysql-monitor_read_only_interval | 1500 |
| mysql-monitor_read_only_timeout | 500 |
+-----------------------------------------------------+----------------+
22 rows in set (0.00 sec)

As indicated above: mysql-monitor_username monitor account user name; mysql-monitor_password is the password. They are the monitor, of course, you can update this table will be updated them to any string you want. The above configuration associated monitor these variables may be needed to update itself.

Here to say a variable: when mysql-monitor_writer_is_also_reader, it means that the reader may wirter node is a node, provided herein is true when a node read_only = ON, turns read_only = OFF, the table is copied in a mysql_servers Similarly record, put in writer_hostgroup. I.e., the machine will have two records, one belonging Writer, belongs to another reader. When mysql-monitor_writer_is_also_reader is false, the machine will move to the writer group, the machine will not be repeated in the presence mysql_servers table.

Next step is to create a monitor in the back-end database account. Grant permission as follows:

1
GRANT REPLICATION CLIENT ON *.* TO 'monitor'@'%' identified by 'monitor';

Permission is granted to copy for monitoring replication latency, or only enough usage rights.

Monitor the read-only attribute

For traditional replication architecture, to monitor the read-only attribute, you must configure the table mysql_replication_hostgroups. Each row in this table represents a replication group.

1 
2
3
4
5 major column   service discovery mechanism ProxySQL of AN>
6
7
mysql> select * from mysql_replication_hostgroups;
+------------------+------------------+----------+
| writer_hostgroup | reader_hostgroup | comment |
+------------------+------------------+----------+
| 0 | 1 | |
| 2 | 3 | test_app |
+------------------+------------------+----------+

You can see the contents of this table is very simple, only three fields. Writer_hostgroup respectively specify the ID and reader_hostgroup, these ID and table mysql_servers hostgroup_id associated table.

1
2
3
4
5
6
7
mysql> select * from mysql_servers;
+--------------+-----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+-----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 0 | 192.168.216.203 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
| 1 | 192.168.216.204 | 3306 | ONLINE | 1 | 0 | 1000 | 0 | 0 | 0 | |
+--------------+-----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+

When a mysql server in read_only property changes, Monitor module automatically updates hostgroup_id. The IP 203 host hostgroup_id is 0, the writer group, if it is read_only set to ON, it hostgroup_id is updated to 1, i.e. assigned to reader groups. But in default_hostgroup mysql_users table will not change. Also important to note is that after you configure the mysql_servsers, only the implementation of load mysql servsers to runtime; the monitor will work!

Monitoring replication latency

How to enable replication latency monitoring it? It is also very simple, just to max_replication_lag set from a library of greater than 0 (second) value in the table mysql_servers it. When the replica delay exceeds this threshold, ProxySQL will shield off the host, not SQL route to him, until it copies the delay is less than the threshold value set.

View monitoring logs

Monitoring information record log table used in ProxySQL performed show tables from monitor; can see the tables.

1
2
3
4
5
6
7
8
9
10
11
mysql> show tables from monitor;
+------------------------------------+
| tables |
+------------------------------------+
| mysql_server_connect_log |
| mysql_server_group_replication_log |
| mysql_server_ping_log |
| mysql_server_read_only_log |
| mysql_server_replication_lag_log |
+------------------------------------+
5 rows in set (0.00 sec)

  • Log mysql_server_connect_log record mysql connection background, the success / failure
  • mysql_server_ping_log log ping backstage instance. When the value exceeds the failure mysql-monitor_ping_max_failures variable established at this time, the notification MySQL_Hostgroups_Manager kill off the connection instance.
  • mysql_server_replication_lag_log check Seconds_Behind_Master, and the results recorded in the information table. If Seconds_Behind_Master> max_replication_lag the node are blocked until Seconds_Behind_Master <max_replication_lag.
  • mysql_server_read_only_log checklist mysql_replication_hostgroups arranged all hosts mysql read_only properties, and the results recorded in the table. Read_only = 1 if the host is copied / moved to reader_hostgroup, otherwise copied / moved to the writer_hostgroup.

ProxySQL This feature may be combined with the rear end of the automatic failover mysql tool (MHA, mysqlfailover, etc.), such that when the failover occurs, notifies the upper layer without performing ip_failover, MySQL ProxySQL automatically detects the master-slave architecture changes, and adjustments in write hostgroup host. The entire failover process is more understanding. But ProxySQL layer and there new high-availability issues, a proxy instance hung gracefully notify upper-layer applications connect to the other? (Vip? DNS? Zookeeper?)

Guess you like

Origin www.cnblogs.com/liuzhongrong/p/11961105.html