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]>