ProxySQL+MHA的各自搭建在这里再也不描述了。具体的搭建能够自行谷歌,可是须要注意的是MHA在进行故障转移的时候不须要作VIP切换操做便可。mysql
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。sql
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 yeah Database changed rpl@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 10000ms rpl@mysqldb 15:20: [yeah]>