[root@HE3 ~]# /etc/init.d/maxscale start
Starting MaxScale: maxscale (pid 28851) is running... [ OK ]
[root@HE3 ~]# netstat -lntp |grep maxscale
tcp 0 0 0.0.0.0:6603 0.0.0.0:* LISTEN 29878/maxscale
tcp 0 0 0.0.0.0:4006 0.0.0.0:* LISTEN 29878/maxscale
[root@HE3 ~]# maxadmin -pmariadb list services
Services.
--------------------------+----------------------+--------+---------------
Service Name | Router Module | #Users | Total Sessions
--------------------------+----------------------+--------+---------------
Read-Only Service | readconnroute | 1 | 5
Read-Write Service | readwritesplit | 1 | 11
MaxAdmin Service | cli | 2 | 3
--------------------------+----------------------+--------+---------------
[root@HE3 ~]# maxadmin -pmariadb list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server | Address | Port | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
server1 | 192.168.1.248 | 3306 | 0 | Slave, Running
server2 | 192.168.1.249 | 3306 | 0 | Slave, Running
server3 | 192.168.1.250 | 3306 | 0 | Master, Running
-------------------+-----------------+-------+-------------+--------------------
至此,MHA+Maxscale的环境就完成了。
读写分离与负载均衡校验
Part1:读写分离
在Master构建相应的测试表
1234567 mysql> select * from helei;
+--------+
| a |
+--------+
| HE3 |
+--------+
3 rows in set (0.00 sec)
在slave1插入数据HE1
mysql> select * from helei;
+------+
| a |
+------+
| HE3 |
| HE1 |
+------+
在slave2插入数据HE2
1234567 mysql> select * from helei;
+------+
| a |
+------+
| HE3 |
| HE2 |
+------+
现在链接4006读写分离端口,进行数据写入
[root@HE3 ~]# mysql -h192.168.1.250 -P 4006 -usys_admin -pMANAGER maxscale -e"insert into helei values('写入');"
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@HE3 ~]# mysql -h192.168.1.250 -P 4008 -usys_admin -pMANAGER maxscale -e"select * from helei;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| a |
+--------+
| HE3 |
| HE1 |
| 写入 |
+--------+
可以看到主库插入完毕后从库已经同步完成,这条查询完成在了HE1(slave1)上