创建监控用户,用于[MySQL Monitor]段的配置中:
mysql> create database maxscale_schema ; # maxscale监控用的心跳信息会写到这个库里面
mysql> create user scalemon@‘%‘ identified by"111111";
mysql> grant replication slave, replication client on*.* to scalemon@‘%‘;
mysql> grant all on maxscale_schema.* to scalemon@‘%‘;
创建路由用户 ,用于[Read-Write Service]和[Read-Only Service]段的配置中:
mysql> create user scaleroute@'%' identified by "123456";
mysql> grant select on mysql.* to scaleroute@'%';
MaxScale> list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server | Address | Port | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
server1 | 192.168.137.21 | 3306 | 0 | Master, Running
server2 | 192.168.137.22 | 3306 | 0 | Slave, Running
server3 | 192.168.137.23 | 3306 | 0 | Slave, Running
-------------------+-----------------+-------+-------------+--------------------
MaxScale> list services
Services.
--------------------------+----------------------+--------+---------------
Service Name | Router Module | #Users | Total Sessions
--------------------------+----------------------+--------+---------------
Read-Only Service | readconnroute | 1 | 1
Read-Write Service | readwritesplit | 1 | 1
MaxAdmin Service | cli | 3 | 3
--------------------------+----------------------+--------+---------------
验证读写分离
通过登录Maxscale的读写分离服务, 来执行sql并且查看日志,查看日志路由情况。
[iyunv@normal_11 opt]# mysql -uHH -p -h192.168.137.11 -P4006
Logging to file '/u01/mysql_history/query.log'
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5524
Server version: 5.5.5-10.0.0 2.0.1-maxscale MariaDB Server
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
HH@192.168.137.11 11:13:46 [(none)]>SELECT * FROM test.t1;
+----+------+-----+
| id | name | age |
+----+------+-----+
| 1 | HH1 | 1 |
| 2 | HH2 | 2 |
| 3 | HH3 | 3 |
+----+------+-----+
3 rows in set (0.01 sec)