proxySQL with MGR

环境信息

hostname IP port role comm ms81 192.168.188.81 3399 master ms82 192.168.188.82 3399 slave ms83 192.168.188.83 3399 slave ms84 192.168.188.84 6033 proxysql&sysbench

  • ProxySQL version 2.0.11-124-g971c15e, codename Truls
  • MySQL 8.0.19 x86_64
  • mysqlsh 8.0.20
  • CentOS 7.8.2003 on Docker

配置MySQL

通过MySQL Shell配置singlePrimary模式MGR

配置用户

mysql> set global super_read_only=0;

mysql> create user mgr@'192.168.188.%' identified by 'mgr';

mysql> grant all privileges on *.* to mgr@'192.168.188.%' with grant option;

mysql> create user kk@'192.168.188.%' identified by 'kk';

mysql> grant all privileges on *.* to kk@'192.168.188.%';

mysql> create user proxy@'192.168.188.%' identified with mysql_native_password by 'proxy';

mysql> grant all privileges on *.* to proxy@'192.168.188.%';

mysql> create user monitor@'192.168.188.%' identified with mysql_native_password by 'monitor';

mysql> grant replication client on *.* to monitor@'192.168.188.%';

mysql> reset master;

mysql> create database kk;

运行proxysql需要的脚本

[13:46:00] root@ms81:/ofiles # mysql -S /data/mysql/mysql3399/tmp/mysql.sock  < addition_to_sys8.sql

#记得授权!
mysql> grant select on sys.gr_member_routing_candidate_status to 'monitor'@'192.168.188.%';
Query OK, 0 rows affected (0.12 sec)

配置ProxySQL

定义并配置proxysql的HostGroups

gid hostgroup 100 read 111 write 122 backup_write 404 offline

mysql> show create table mysql_group_replication_hostgroups\G
*************************** 1. row ***************************
       table: mysql_group_replication_hostgroups
Create Table: CREATE TABLE mysql_group_replication_hostgroups (
    writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY,
    backup_writer_hostgroup INT CHECK (backup_writer_hostgroup>=0 AND backup_writer_hostgroup<>writer_hostgroup) NOT NULL,
    reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND backup_writer_hostgroup<>reader_hostgroup AND reader_hostgroup>0),
    offline_hostgroup INT NOT NULL CHECK (offline_hostgroup<>writer_hostgroup AND offline_hostgroup<>reader_hostgroup AND backup_writer_hostgroup<>offline_hostgroup AND offline_hostgroup>=0),
    active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
    max_writers INT NOT NULL CHECK (max_writers >= 0) DEFAULT 1,
    writer_is_also_reader INT CHECK (writer_is_also_reader IN (0,1,2)) NOT NULL DEFAULT 0,
    max_transactions_behind INT CHECK (max_transactions_behind>=0) NOT NULL DEFAULT 0,
    comment VARCHAR,
    UNIQUE (reader_hostgroup),
    UNIQUE (offline_hostgroup),
    UNIQUE (backup_writer_hostgroup))
1 row in set (0.00 sec)

这里没修改  max_writers ,默认为1。 不建议增加,即使是multiPromary模式,proxysql也建议使用单写。
mysql> insert into mysql_group_replication_hostgroups(writer_hostgroup,backup_writer_hostgroup,reader_hostgroup,offline_hostgroup,active) values (111,122,100,404,1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from mysql_group_replication_hostgroups;
+------------------+-------------------------+------------------+-------------------+--------+-------------+-----------------------+-------------------------+---------+
| writer_hostgroup | backup_writer_hostgroup | reader_hostgroup | offline_hostgroup | active | max_writers | writer_is_also_reader | max_transactions_behind | comment |
+------------------+-------------------------+------------------+-------------------+--------+-------------+-----------------------+-------------------------+---------+
| 111              | 122                     | 100              | 404               | 1      | 1           | 0                     | 0                       | NULL    |
+------------------+-------------------------+------------------+-------------------+--------+-------------+-----------------------+-------------------------+---------+
1 row in set (0.00 sec)

添加servers

mysql> show create table mysql_servers\G
*************************** 1. row ***************************
       table: mysql_servers
Create Table: CREATE TABLE mysql_servers (
    hostgroup_id INT CHECK (hostgroup_id>=0) NOT NULL DEFAULT 0,
    hostname VARCHAR NOT NULL,
    port INT CHECK (port >= 0 AND port  port OR gtid_port=0) AND gtid_port >= 0 AND gtid_port = 0 AND weight =0) NOT NULL DEFAULT 1000,
    max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag =0) NOT NULL DEFAULT 0,
    comment VARCHAR NOT NULL DEFAULT '',
    PRIMARY KEY (hostgroup_id, hostname, port) )
1 row in set (0.00 sec)

mysql> insert into mysql_servers(hostgroup_id,hostname,port,max_connections) values (100,'192.168.188.81',3399,200);
Query OK, 1 row affected (0.00 sec)

mysql> insert into mysql_servers(hostgroup_id,hostname,port,max_connections) values (100,'192.168.188.82',3399,200);
Query OK, 1 row affected (0.00 sec)

mysql> insert into mysql_servers(hostgroup_id,hostname,port,max_connections) values (100,'192.168.188.83',3399,200);
Query OK, 1 row affected (0.00 sec)

mysql> select hostgroup_id,hostname,port,max_connections from mysql_servers;
+--------------+----------------+------+-----------------+
| hostgroup_id | hostname       | port | max_connections |
+--------------+----------------+------+-----------------+
| 100          | 192.168.188.81 | 3399 | 200             |
| 100          | 192.168.188.82 | 3399 | 200             |
| 100          | 192.168.188.83 | 3399 | 200             |
+--------------+----------------+------+-----------------+
3 rows in set (0.00 sec)

mysql> load mysql servers to run;
Query OK, 0 rows affected (0.01 sec)

mysql> save mysql servers to disk;
Query OK, 0 rows affected (0.83 sec)

添加user

mysql> show create table mysql_users\G
*************************** 1. row ***************************
       table: mysql_users
Create Table: CREATE TABLE mysql_users (
    username VARCHAR NOT NULL,
    password VARCHAR,
    active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
    use_ssl INT CHECK (use_ssl IN (0,1)) NOT NULL DEFAULT 0,
    default_hostgroup INT NOT NULL DEFAULT 0,
    default_schema VARCHAR,
    schema_locked INT CHECK (schema_locked IN (0,1)) NOT NULL DEFAULT 0,
    transaction_persistent INT CHECK (transaction_persistent IN (0,1)) NOT NULL DEFAULT 1,
    fast_forward INT CHECK (fast_forward IN (0,1)) NOT NULL DEFAULT 0,
    backend INT CHECK (backend IN (0,1)) NOT NULL DEFAULT 1,
    frontend INT CHECK (frontend IN (0,1)) NOT NULL DEFAULT 1,
    max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000,
    comment VARCHAR NOT NULL DEFAULT '',
    PRIMARY KEY (username, backend),
    UNIQUE (username, frontend))
1 row in set (0.00 sec)

mysql> insert into mysql_users(username,password,active,default_hostgroup,default_schema) values ('proxy','proxy',1,100,'kk');
Query OK, 1 row affected (0.00 sec)

mysql> insert into mysql_users(username,password,active,default_hostgroup,default_schema) values ('kk','kk',1,100,'kk');
Query OK, 1 row affected (0.00 sec)

mysql> select * from mysql_users;
+----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+---------+
| username | password | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections | comment |
+----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+---------+
| proxy    | proxy    | 1      | 0       | 100               | kk             | 0             | 1                      | 0            | 1       | 1        | 10000           |         |
| kk       | kk       | 1      | 0       | 100               | kk             | 0             | 1                      | 0            | 1       | 1        | 10000           |         |
+----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+---------+
2 rows in set (0.00 sec)

mysql> load mysql users to run;
Query OK, 0 rows affected (0.00 sec)

mysql> save mysql users to disk;
Query OK, 0 rows affected (0.36 sec)

检查一下,可以看到已经根据节点状态进行分组


mysql> select * from monitor.mysql_server_group_replication_log;

mysql> 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 |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 100          | 192.168.188.82 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 111          | 192.168.188.81 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 100          | 192.168.188.83 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
3 rows in set (0.01 sec)

添加规则前做一次性能测试

[15:37:26] root@ms84:~ # sysbench /usr/share/sysbench/oltp_read_write.lua  --db-driver=mysql --mysql-host=192.168.188.84 --mysql-port=6033  --mysql-user=kk --mysql-password=kk --mysql-db=kk --table-size=50000 prepare
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Creating table 'sbtest1'...

FATAL: mysql_drv_query() returned error 1290 (The MySQL server is running with the --super-read-only option so it cannot execute this statement) for query 'CREATE TABLE sbtest1(
  id INTEGER NOT NULL AUTO_INCREMENT,
  k INTEGER DEFAULT '0' NOT NULL,
  c CHAR(120) DEFAULT '' NOT NULL,
  pad CHAR(60) DEFAULT '' NOT NULL,
  PRIMARY KEY (id)
) /*! ENGINE = innodb */ '
FATAL: `sysbench.cmdline.call_command' function failed: /usr/share/sysbench/oltp_common.lua:197: SQL error, errno = 1290, state = 'HY000': The MySQL server is running with the --super-read-only option so it cannot execute this statement

&#x770B;&#x6765;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x4E00;&#x4E0B;&#xFF0C;&#x4E0D;&#x7136;&#x627E;&#x4E0D;&#x5230;rw&#x670D;&#x52A1;&#x5668;&#x2026;&#x2026; &#x9ED8;&#x8BA4;&#x90FD;&#x53D1;&#x7ED9;&#x53EA;&#x8BFB;&#x7EC4;&#x4E86;&#x3002;

&#x8FD9;&#x5757;&#x5B9E;&#x9A8C;&#x4E2D;&#x53D1;&#x73B0;&#x4E86;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;sysbench&#x901A;&#x8FC7;proxysql&#x7684;&#x670D;&#x52A1;&#x7AEF;&#x53E3;&#x8FDE;&#x63A5;&#x540E;&#xFF0C;&#x65E0;&#x6CD5;&#x8FDB;&#x884C;&#x4EFB;&#x4F55;&#x64CD;&#x4F5C;&#xFF1A;
mysql> show tables;
ERROR 1045 (28000): Access denied for user 'kk'@'ms84.net188' (using password: YES)
&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#xFF0C;&#x7528;&#x6237;&#x88AB;&#x89E3;&#x6790;&#x6210;proxysql&#x7684;&#x57DF;&#x540D;&#x6765;&#x6E90;&#x4E86;&#xFF0C;&#x800C;&#x5B9E;&#x9645;&#x4E0A;&#x5BF9;kk&#x7528;&#x6237;&#x7684;&#x6388;&#x6743;&#x505A;&#x7684;&#x662F; kk@'192.168.188.%',
&#x67E5;&#x770B;&#x4E86;&#x4E00;&#x4E0B;MySQL&#x7684;&#x53C2;&#x6570;&#x6587;&#x4EF6;&#xFF0C;&#x539F;&#x56E0;&#x4E3A;&#xFF1A;
mysql> show global variables like '%reso%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| skip_name_resolve | OFF   |
+-------------------+-------+
1 row in set (0.01 sec)
&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x4E3A;1&#xFF0C; &#x6216;&#x91CD;&#x65B0;&#x5EFA;&#x7ACB;&#x7528;&#x6237; kk@'%' &#xFF0C;&#x5728;&#x672C;&#x6B21;&#x5B9E;&#x9A8C;&#x91CC;&#xFF0C;&#x7531;&#x4E8E;&#x8BBE;&#x8BA1;&#x7684;&#x662F;&#x6240;&#x6709;&#x8BBF;&#x95EE;&#x901A;&#x8FC7;proxysql&#xFF0C;proxysql&#x4EE5;kk&#x7528;&#x6237;&#x4E0E;MySQL MGR&#x901A;&#x4FE1;
&#x56E0;&#x6B64;&#x5728;&#x8FD9;&#x91CC;&#x6211;&#x53E6;&#x5916;&#x5EFA;&#x7ACB;&#x4E86;&#x7528;&#x6237;'kk'@'ms84.net188'&#xFF0C;&#x5E76;&#x6388;&#x6743;&#x3002;
&#x518D;&#x6B21;&#x901A;&#x8FC7;&#x5176;&#x5B83;IP&#x4F7F;&#x7528;proxysql&#x7684;&#x670D;&#x52A1;&#x7AEF;&#x53E3;&#x767B;&#x5F55;&#x540E;&#xFF0C;&#x67E5;&#x770B;&#x5F53;&#x524D;&#x7528;&#x6237;&#x4E3A;&#xFF1A;
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| kk@ms84.net188 |
+----------------+
1 row in set (0.00 sec)
&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x65E0;&#x8BBA;&#x53D1;&#x8D77;&#x8FDE;&#x63A5;&#x8BF7;&#x6C42;&#x7684;client&#x5728;&#x54EA;&#x91CC;&#xFF0C;current_user &#x90FD;&#x662F;proxysql&#x7684;domain&#xFF0C;&#x8FD9;&#x4E5F;&#x9A8C;&#x8BC1;&#x4E86;&#x524D;&#x9762;&#x7684;&#x731C;&#x6D4B;&#x3002;

proxysql&#x4FEE;&#x6539;&#xFF1A;
mysql> update mysql_users set default_hostgroup=111 where username='kk';
Query OK, 1 row affected (0.00 sec)

mysql> load mysql users to run;
Query OK, 0 rows affected (0.00 sec)

[15:39:01] root@ms84:~ # sysbench /usr/share/sysbench/oltp_read_write.lua  --db-driver=mysql --mysql-host=192.168.188.84 --mysql-port=6033  --mysql-user=kk --mysql-password=kk --mysql-db=kk --table-size=50000 prepare
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Creating table 'sbtest1'...

Inserting 50000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...

[15:40:57] root@ms84:~ # sysbench /usr/share/sysbench/oltp_read_write.lua  --db-driver=mysql --mysql-host=192.168.188.84 --mysql-port=6033  --mysql-user=kk --mysql-password=kk --mysql-db=kk --table-size=50000 run
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time

Initializing worker threads...

Threads started!

SQL statistics:
    queries performed:
        read:                            714
        write:                           204
        other:                           102
        total:                           1020
    transactions:                        51     (5.00 per sec.)
    queries:                             1020   (100.03 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          10.1929s
    total number of events:              51

Latency (ms):
         min:                                  104.38
         avg:                                  199.83
         max:                                  444.15
         95th percentile:                      297.92
         sum:                                10191.23

Threads fairness:
    events (avg/stddev):           51.0000/0.00
    execution time (avg/stddev):   10.1912/0.00

mysql> select hostgroup,digest, digest_text,count_star from stats.stats_mysql_query_digest;
+-----------+--------------------+--------------------------------------------------------------------+------------+
| hostgroup | digest             | digest_text                                                        | count_star |
+-----------+--------------------+--------------------------------------------------------------------+------------+
| 111       | 0xE52A0A0210634DAC | INSERT INTO sbtest1 (id, k, c, pad) VALUES (?, ?, ?, ?)            | 52         |
| 111       | 0xE365BEB555319B9E | DELETE FROM sbtest1 WHERE id=?                                     | 52         |
| 111       | 0xFB239BC95A23CA36 | UPDATE sbtest1 SET c=? WHERE id=?                                  | 52         |
| 111       | 0xC19480748AE79B4B | SELECT DISTINCT c FROM sbtest1 WHERE id BETWEEN ? AND ? ORDER BY c | 52         |
| 111       | 0xAC80A5EA0101522E | SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ? ORDER BY c          | 52         |
| 111       | 0xC198E52BCCB481C7 | UPDATE sbtest1 SET k=k+? WHERE id=?                                | 52         |
| 111       | 0xDBF868B2AA296BC5 | SELECT SUM(k) FROM sbtest1 WHERE id BETWEEN ? AND ?                | 52         |
| 111       | 0x290B92FD743826DA | SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ?                     | 52         |
| 111       | 0xBF001A0C13781C1D | SELECT c FROM sbtest1 WHERE id=?                                   | 511        |
| 111       | 0x695FBF255DBEB0DD | COMMIT                                                             | 52         |
| 111       | 0xFAD1519E4760CBDE | BEGIN                                                              | 52         |
+-----------+--------------------+--------------------------------------------------------------------+------------+
11 rows in set (0.01 sec)

做完全的读写分离规则

&#x5728;&#x8FD9;&#x91CC;&#x505A;&#x5B8C;&#x5168;&#x7684;&#x8BFB;&#x5199;&#x5206;&#x79BB;.

&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x6765;&#x5728;&#x4E00;&#x53F0;&#x7269;&#x7406;server&#x4E0A;&#x8FD9;&#x6837;&#x641E;&#x662F;&#x6709;&#x635F;&#x5931;&#x7684;&#xFF0C;&#x54C8;&#x54C8;
mysql> insert into mysql_query_rules(rule_id,active,match_pattern,destination_hostgroup,apply) values (1,1,'^SELECT.*FOR UPDATE$',111,1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into mysql_query_rules(rule_id,active,match_pattern,destination_hostgroup,apply) values (2,1,'^SELECT.*',100,1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from mysql_query_rules;
+---------+--------+----------+------------+--------+-------------+------------+------------+--------+--------------+----------------------+----------------------+--------------+---------+-----------------+-----------------------+-----------+--------------------+---------------+-----------+---------+---------+-------+-------------------+----------------+------------------+-----------+--------+-------------+-----------+---------------------+-----+-------+---------+
| rule_id | active | username | schemaname | flagIN | client_addr | proxy_addr | proxy_port | digest | match_digest | match_pattern        | negate_match_pattern | re_modifiers | flagOUT | replace_pattern | destination_hostgroup | cache_ttl | cache_empty_result | cache_timeout | reconnect | timeout | retries | delay | next_query_flagIN | mirror_flagOUT | mirror_hostgroup | error_msg | OK_msg | sticky_conn | multiplex | gtid_from_hostgroup | log | apply | comment |
+---------+--------+----------+------------+--------+-------------+------------+------------+--------+--------------+----------------------+----------------------+--------------+---------+-----------------+-----------------------+-----------+--------------------+---------------+-----------+---------+---------+-------+-------------------+----------------+------------------+-----------+--------+-------------+-----------+---------------------+-----+-------+---------+
| 1       | 1      | NULL     | NULL       | 0      | NULL        | NULL       | NULL       | NULL   | NULL         | ^SELECT.*FOR UPDATE$ | 0                    | CASELESS     | NULL    | NULL            | 111                   | NULL      | NULL               | NULL          | NULL      | NULL    | NULL    | NULL  | NULL              | NULL           | NULL             | NULL      | NULL   | NULL        | NULL      | NULL                | NULL | 1     | NULL    |
| 2       | 1      | NULL     | NULL       | 0      | NULL        | NULL       | NULL       | NULL   | NULL         | ^SELECT.*            | 0                    | CASELESS     | NULL    | NULL            | 100                   | NULL      | NULL               | NULL          | NULL      | NULL    | NULL    | NULL  | NULL              | NULL           | NULL             | NULL      | NULL   | NULL        | NULL      | NULL                | NULL | 1     | NULL    |
+---------+--------+----------+------------+--------+-------------+------------+------------+--------+--------------+----------------------+----------------------+--------------+---------+-----------------+-----------------------+-----------+--------------------+---------------+-----------+---------+---------+-------+-------------------+----------------+------------------+-----------+--------+-------------+-----------+---------------------+-----+-------+---------+
2 rows in set (0.00 sec)

mysql> load mysql query rules to run;
Query OK, 0 rows affected (0.00 sec)

mysql> save mysql query rules to disk;
Query OK, 0 rows affected (0.47 sec)

mysql> select hostgroup,digest, digest_text,count_star from stats.stats_mysql_query_digest_reset;

[15:51:54] root@ms84:~ # sysbench /usr/share/sysbench/oltp_read_write.lua  --db-driver=mysql --mysql-host=192.168.188.84 --mysql-port=6033  --mysql-user=kk --mysql-password=kk --mysql-db=kk --table-size=50000 run
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time

Initializing worker threads...

Threads started!

SQL statistics:
    queries performed:
        read:                            672
        write:                           192
        other:                           96
        total:                           960
    transactions:                        48     (4.79 per sec.)
    queries:                             960    (95.87 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          10.0099s
    total number of events:              48

Latency (ms):
         min:                                  104.58
         avg:                                  208.51
         max:                                  458.81
         95th percentile:                      331.91
         sum:                                10008.26

Threads fairness:
    events (avg/stddev):           48.0000/0.00
    execution time (avg/stddev):   10.0083/0.00

mysql> select hostgroup,digest, digest_text,count_star from stats.stats_mysql_query_digest;
+-----------+--------------------+--------------------------------------------------------------------+------------+
| hostgroup | digest             | digest_text                                                        | count_star |
+-----------+--------------------+--------------------------------------------------------------------+------------+
| 111       | 0xE52A0A0210634DAC | INSERT INTO sbtest1 (id, k, c, pad) VALUES (?, ?, ?, ?)            | 49         |
| 111       | 0xFB239BC95A23CA36 | UPDATE sbtest1 SET c=? WHERE id=?                                  | 49         |
| 111       | 0xC198E52BCCB481C7 | UPDATE sbtest1 SET k=k+? WHERE id=?                                | 49         |
| 100       | 0xC19480748AE79B4B | SELECT DISTINCT c FROM sbtest1 WHERE id BETWEEN ? AND ? ORDER BY c | 49         |
| 100       | 0xAC80A5EA0101522E | SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ? ORDER BY c          | 49         |
| 111       | 0xE365BEB555319B9E | DELETE FROM sbtest1 WHERE id=?                                     | 49         |
| 100       | 0x290B92FD743826DA | SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ?                     | 49         |
| 100       | 0xBF001A0C13781C1D | SELECT c FROM sbtest1 WHERE id=?                                   | 481        |
| 100       | 0xDBF868B2AA296BC5 | SELECT SUM(k) FROM sbtest1 WHERE id BETWEEN ? AND ?                | 49         |
| 111       | 0x695FBF255DBEB0DD | COMMIT                                                             | 49         |
| 111       | 0xFAD1519E4760CBDE | BEGIN                                                              | 49         |
+-----------+--------------------+--------------------------------------------------------------------+------------+
11 rows in set (0.01 sec)

看一下MGR做failover时,proxysql的状态。

  • 当前MGR状态
 MySQL  192.168.188.81:3399 ssl  JS > cl.status()
{
    "clusterName": "kk",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "ms81:3399",
        "ssl": "REQUIRED",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
        "topology": {
            "ms81:3399": {
                "address": "ms81:3399",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": null,
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.19"
            },
            "ms82:3399": {
                "address": "ms82:3399",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "00:00:00.317335",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.19"
            },
            "ms83:3399": {
                "address": "ms83:3399",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "00:00:00.227030",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.19"
            }
        },
        "topologyMode": "Single-Primary"
    },
    "groupInformationSourceMember": "ms81:3399"
}

  • 当前proxysql mysql_servers状态
mysql>  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 |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 100          | 192.168.188.83 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 111          | 192.168.188.81 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 100          | 192.168.188.82 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
3 rows in set (0.01 sec)

  • 将当前master重启,再查看proxysql mysql_servers
master:
mysql> shutdown ;
Query OK, 0 rows affected (0.00 sec)

mysql> mysql>  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 |
+--------------+----------------+------+-----------+---------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 100          | 192.168.188.83 | 3399 | 0         | ONLINE  | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 404          | 192.168.188.81 | 3399 | 0         | SHUNNED | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 111          | 192.168.188.82 | 3399 | 0         | ONLINE  | 1      | 0           | 200             | 0                   | 0       | 0              |         |
+--------------+----------------+------+-----------+---------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
3 rows in set (0.00 sec)

  • 重启master ,再查看
master
[16:12:33] root@ms81:~ # mysqld --defaults-file=/data/mysql/mysql3399/my3399.cnf &

&#x4F7F;&#x7528;MySQL shell&#x6784;&#x5EFA;&#x7684;MGR &#xFF0C;&#x5728;&#x8282;&#x70B9;&#x91CD;&#x542F;&#x540E;&#x4F1A;&#x81EA;&#x52A8;&#x542F;&#x52A8;GR

mysql>  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 |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 100          | 192.168.188.83 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 111          | 192.168.188.82 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 100          | 192.168.188.81 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
3 rows in set (0.00 sec)

个个原创文章

欢迎讨论
https://www.cnblogs.com/konggg/
欢迎转载收藏,转载请注明来源,谢谢支持!

Original: https://www.cnblogs.com/konggg/p/13571589.html
Author: 孔个个
Title: proxySQL with MGR

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/621250/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • Centos静默安装Oracle11G

    环境准备 Oracle 11gR2 64位 Linux版安装包 linux.x64_11gR2_database_1of2.ziplinux.x64_11gR2_database_…

    数据库 2023年6月16日
    064
  • 弱隔离级别 & 事务并发问题

    为什么要有弱隔离级别 如果两个事务操作的是不同的数据, 即不存在数据依赖关系, 则它们可以安全地并行执行。但是当出现某个事务修改数据而另一个事务同时要读取该数据, 或者两个事务同时…

    数据库 2023年6月11日
    069
  • MySQL CREATE TABLE 简单设计模板交流

    我们也可以多台机器部署, 设置不同 AUTO_INCREMENT step, 让每个 sequece 产生不同号码. 例如部署 step = 2 个服务结点, 并行获取数据. 一个…

    数据库 2023年5月24日
    0115
  • Netty-NIO基础

    一. NIO 基础 non-blocking io 非阻塞 IO 1. 三大组件 1.1 Channel & Buffer channel 有一点类似于 stream,它就…

    数据库 2023年6月16日
    070
  • 2022-8-31 jsp el表达式

    jsp 注意:1、JSP脚本片段中只能出现java代码,不能出现HTML元素。在 访问JSP时,JSP引擎翻译JSP页面中的脚本片段。2、JSP脚本片段中的java代码必须严格遵守…

    数据库 2023年6月14日
    066
  • JVM详解

    一、JVM的位置及体系结构 JVM作用在操作系统之上,而Java程序作用在jvm之上,其他的程序则与jvm并列 二、类加载器,及双亲委派机制 1.类加载器 作用:加载Class文件…

    数据库 2023年6月16日
    075
  • 常见的攻击方式以及防护策略

    本文主要给大家介绍一下常见的几种网络攻击方式(包括CC,UDP,TCP)和基础防护策略! 1.0 常见的网络攻击方式 第一种CC攻击 CC攻击( ChallengeCoHapsar…

    数据库 2023年6月9日
    071
  • Jmeter操作ES

    JMeter 是 Apache 组织基于 Java 开发的压力测试工具,用于对软件做压力测试。Elasticsearch 是一个分布式、高扩展、高实时的搜索与数据分析引擎(简称es…

    数据库 2023年6月14日
    084
  • Docker 部署前后端项目

    Docker 部署前后端项目 平生不会相思,才会相思,便害相思。 简介:都是被逼的,从零开始一个Docker 部署九个微服务和三个前端项目。其中,这些服务需要用到Nacos、MyS…

    数据库 2023年6月14日
    075
  • fiddler的mock数据与二次开发示例

    fiddler的使用记录 fiddler了解 上官网下载工具,然后安装使用,https://www.telerik.com/fiddler,如果对该工具不熟悉,还有直白的教程,看过…

    数据库 2023年6月6日
    0102
  • 绕过国内域名备案

    情景:现有域名jsw.top,云服务器1台均在阿里云下。域名jsw.top、www.jsw.top CNAME解析到阿里云OSS的记录值(阿里云OSS会要求备案,导致无法使用),而…

    数据库 2023年6月14日
    078
  • 一个反直觉的sql

    引子 在《容易引起雪崩的两个处理》里,我提到一个慢查询的问题。本文先从整洁架构的角度讲讲慢查询sql完成的功能以及设计,再介绍对sql进行的实施测试现象以及思考。 设计讲解 眼看着…

    数据库 2023年5月24日
    089
  • 9 &和&&的区别

    &运算符有两种用法 在解释按位与&之前,我们先了解一个知识:程序中的所有数在计算机内存中都是以二进制的形式存储的,位运算就是直接对内存中整数的二进制位进行操作。 按…

    数据库 2023年6月6日
    0109
  • Java基础四—泛型、注解、异常、反射

    泛型 泛型的本质是为了参数化类型( 在不创建新的类型的情况下,通过泛型指定的不同类型来控制形参具体限制的类型)。也就是说在泛型使用过程中,操作的数据类型被指定为一个参数,这种参数类…

    数据库 2023年6月6日
    082
  • 新版 google 谷歌浏览器跨域问题

    新版本的firefox火狐浏览器限制了 127.0.0.1 本地部署测试的时候,用火狐浏览器需要把 前端的 后台中的服务地址改成 http://localhost:8081 浏览器…

    数据库 2023年6月6日
    084
  • Linux中的进程的服务和控制

    Linux中的进程 进程:已经启动的可执行程序的运行实例 1、PID:进程的ID(每一个新进程都有一个唯一的PID) 2、PPID:父进程的ID 3、任何一个进程都可以创建一个子进…

    数据库 2023年6月16日
    047
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球