ProxySQL+MHA的各自搭建在这里不再描述了。具体的搭建可以自行谷歌,但是需要注意的是MHA在进行故障转移的时候不需要做VIP切换操作即可。
admin@mysqldb 10:51: [(none)]> select username,password,active,default_hostgroup from mysql_users;+----------+-------------+--------+-------------------+| username | password | active | default_hostgroup |+----------+-------------+--------+-------------------+| rpl | Redhat_2018 | 1 | 10 |+----------+-------------+--------+-------------------+1 row in set (0.01 sec)
admin@mysqldb 11:48: [(none)]> select hostgroup_id,hostname,port,weight from mysql_servers;+--------------+------------+------+--------+| hostgroup_id | hostname | port | weight |+--------------+------------+------+--------+| 11 | 172.16.3.6 | 3307 | 100 || 10 | 172.16.3.5 | 3307 | 100 || 10 | 172.16.3.7 | 3307 | 100 || 11 | 172.16.3.7 | 3306 | 100 || 11 | 172.16.3.7 | 3307 | 100 |+--------------+------------+------+--------+5 rows in set (0.00 sec)
配置mysql_replication_hostgroups。主要目的是监控后端的MySQL实例是master还是slave。
admin@mysqldb 11:50: [(none)]> select * from mysql_replication_hostgroups;+------------------+------------------+---------+| writer_hostgroup | reader_hostgroup | comment |+------------------+------------------+---------+| 10 | 11 | |+------------------+------------------+---------+1 row in set (0.00 sec)
admin@mysqldb 14:28: [(none)]> select rule_id,active,match_pattern,apply from mysql_query_rules;+---------+--------+-----------------------+-------+| rule_id | active | match_pattern | apply |+---------+--------+-----------------------+-------+| 1 | 1 | ^SELECT .*FOR UPDATE$ | 1 || 2 | 1 | ^SELECT | 1 |+---------+--------+-----------------------+-------+2 rows in set (0.00 sec)admin@mysqldb 14:29: [(none)]>
set global mysql-monitor_username=‘username‘;set global mysql-monitor_password=‘new_password‘
rpl@mysqldb 14:58: [(none)]> use yeahDatabase changedrpl@mysqldb 14:58: [yeah]> use zabbix
admin@mysqldb 15:02: [(none)]> select * from mysql_servers;+--------------+------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+| hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |+--------------+------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+| 11 | 172.16.3.6 | 3307 | ONLINE | 100 | 0 | 1000 | 0 | 0 | 0 | slave || 10 | 172.16.3.5 | 3307 | ONLINE | 100 | 0 | 1000 | 0 | 0 | 0 | master || 10 | 172.16.3.7 | 3307 | ONLINE | 100 | 0 | 1000 | 0 | 0 | 0 | slave || 11 | 172.16.3.7 | 3306 | ONLINE | 100 | 0 | 1000 | 0 | 0 | 0 | slave || 11 | 172.16.3.7 | 3307 | ONLINE | 100 | 0 | 1000 | 0 | 0 | 0 | slave |+--------------+------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+5 rows in set (0.00 sec)admin@mysqldb 15:05: [(none)]>
可以很明显的看得到在第三行172.16.3.7:3307这个实例出现了俩次,但是实际情况是我只insert了1次,并且将其insert 到hostgroup_id为11的组上面,但是实际情况却在10,11俩组分别出现了。
rpl@mysqldb 15:19: [yeah]> show tables;ERROR 9001 (HY000): Max connect timeout reached while reaching hostgroup 0 after 10000msrpl@mysqldb 15:20: [yeah]>