MySQL5.7 MHA+MaxScale2.0构建高可用环境(5)

Part2:负载均衡
我们配置的read比例为1:1
[root@HE3 ~]# maxadmin -pmariadb show service "Read-Write Service"
Service 0xef5570
Service:                            Read-Write Service
Router:                              readwritesplit (0x7ff5e8fa6ec0)
State:                              Started
Number of router sessions:          15
Current no. of router sessions:      0
Number of queries forwarded:          41
Number of queries forwarded to master:2 (4.88%)
Number of queries forwarded to slave: 39 (95.12%)
Number of queries forwarded to all:  0 (0.00%)
Connection distribution based on myweight server parameter.
Server              Target %    Connections  Operations
                              Global  Router
server1              50.0%    0      0      0
server2              50.0%    0      0      0
server3              100.0%    0      0      0
Started:                            Thu Nov  3 23:46:27 2016
Root user access:                    Enabled
Backend databases:
192.168.1.248:3306  Protocol: MySQLBackend
192.168.1.249:3306  Protocol: MySQLBackend
192.168.1.100:3306  Protocol: MySQLBackend
Routing weight parameter:            myweight
Users data:                          0xf09370
Total connections:                  16
Currently connected:                1

[root@HE3 ~]# for i in `seq 1 10`; do mysql -h 192.168.1.250 -P 4006 -usys_admin -pMANAGER maxscale -e "select @@hostname; select sleep(10)" 2>/dev/null & done
[root@HE3 ~]# +------------+
| @@hostname |
+------------+
| HE1        |
+------------+
+------------+
| @@hostname |
+------------+
| HE1        |
+------------+
+------------+
| @@hostname |
+------------+
| HE1        |
+------------+
+------------+
| @@hostname |
+------------+
| HE1        |
+------------+
+------------+
| @@hostname |
+------------+
| HE1        |
+------------+
+------------+
| @@hostname |
+------------+
| HE2        |
+------------+
+------------+
| @@hostname |
+------------+
| HE2        |
+------------+
+------------+
| @@hostname |
+------------+
| HE2        |
+------------+
+------------+
| @@hostname |
+------------+
| HE2        |
+------------+
+------------+
| @@hostname |
+------------+
| HE2        |
+------------+

OK!That's how it works!~

故障测试
Part1:stop slave故障
停止HE1的复制
[root@HE1 ~]# mysql
-uroot -p
Enter password:
Welcome to the MySQL
monitor.  Commands end with ; or \g.
Your MySQL
connection id is 74
Server version:
5.7.16-log MySQL Community Server (GPL)
 
Copyright (c) 2000,
2016, 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.
 
mysql> stop
slave;
Query OK, 0 rows
affected (0.05 sec)
 
[root@HE3 ~]#
maxadmin -pmariadb list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server            | Address        | Port 
| Connections | Status             
-------------------+-----------------+-------+-------------+--------------------
server1            | 192.168.1.248  | 
3306 |          0 | Running
server2            | 192.168.1.249  | 
3306 |          0 | Slave,
Running
server3            | 192.168.1.250  | 
3306 |          0 | Master,
Running
-------------------+-----------------+-------+-------------+--------------------
 
[root@HE3 ~]#  mysql -h192.168.1.250 -P 4006 -usys_admin
-pMANAGER maxscale -e"select * from helei;"
mysql: [Warning]
Using a password on the command line interface can be insecure.
+--------+
| a      |
+--------+
| HE3    |
| HE2    |
| 写入 
|
+--------+
[root@HE3 ~]#  mysql -h192.168.1.250 -P 4006 -usys_admin
-pMANAGER maxscale -e"select * from helei;"
mysql: [Warning]
Using a password on the command line interface can be insecure.
+--------+
| a      |
+--------+
| HE3    |
| HE2    |
| 写入 
|
+--------+


可以看出,在slave1故障后,所有的读操作都进入了HE2(slave2);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b359578e79f9490f04c16ee61984b2a0.html