MySQL configuration F5 load balancing for database Series

Posted by hostfreak on Sat, 18 Sep 2021 09:26:25 +0200

The previous article introduced the configuration of F5 virtual machine environment. Refer to“ F5 load balancing configuration of database Series ”, here we continue to introduce MySQL configuration F5 load balancing.

2. F5 configure load balancing

The F5 virtual machine is configured with three network cards. The information is as follows:

  1. VMnet2, host only mode, the ip address segment is 192.168.1.0, which will be used as the external vlan address of F5
  2. VMnet3, host only mode, the ip address segment is 192.168.198.0, which will be used as the ip address of the management node of F5
  3. VMnet8, NAT mode, the ip address segment is 192.168.112.0, which is used for communication and bridging between virtual machines

2.1 configuring Platform

Initialize the configuration, enter the management node ip and configure the hostname

2.2 add VLAN

Just add a few. Generally, you will add two, one intranet and one extranet



2.3 configuring self IP

Internal and external are configured with two IPS respectively, and one is floating IP



2.4 add monitor

The default detection strategy of F5 is TCP. F5 sends a SYN packet to a member in the resource pool pool every fixed time and waits for the server to return SYN_ACK, after receiving SYN_ After ACK, F5 will use RST to reset the connection. If F5 fails to receive SYN within the specified time after sending SYN package_ ACK, the member is considered unavailable and the application traffic is no longer allocated to the member. TCP can only judge whether the TCP port of the target server is in the listen state and whether the target server has the ability to establish a TCP connection. It can not be used to judge the availability of the application.

When the application is in the false active state, the Telnet port can respond normally, but the application cannot provide services normally. Therefore, a monitor detection mechanism compatible with MySQL protocol is added. By connecting to the MySQL database and executing the SQL statement "select 1", the returned result 1 indicates normal. If it cannot be returned normally, it is judged that the member is unavailable.

2.5 creating pools

Create two pools, add the ip and port of the back-end service, and specify the monitor detection method, which is the default TCP method and the mysql protocol compatible detection method.


2.6 creating Virtual Servers

Create a virtual server, that is, the IP of external services, which is in the same network segment as the external VLAN. At the same time, you need to configure the address forwarding setting as Auto Map, and specify the pool names as MGR01 and MGR02.



2.7 access service port

1) Visit 192.168.1.200:3306

[root@tango-centos03 mysql]# ./bin/mysql -h192.168.1.200 -P3306 -uroot -p
Enter password: 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
11 rows in set (0.22 sec)

mysql>

2) Visit 192.168.1.201:3306

[root@tango-centos03 mysql]# ./bin/mysql -h192.168.1.201 -P3306 -uroot -p
Enter password: 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |

mysql>
2.8 viewing server traffic

Click "Overview" - > "Statistics" in the right menu, and select "Pools" in the Statistics Type to see the traffic of the corresponding server

3. F5 load balancing strategy test

1) MGR configuration multi write mode

mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+----------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST    | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+----------------+-------------+--------------+
| group_replication_applier | be42da32-eb35-11ea-9505-000c2937f917 | tango-centos02 |        3306 | ONLINE       |
| group_replication_applier | de623c4b-eb35-11ea-b1e4-000c2959d3e3 | tango-centos03 |        3306 | ONLINE       |
| group_replication_applier | e5fb2194-eb27-11ea-b838-000c2992e812 | tango-centos01 |        3306 | ONLINE       |
+---------------------------+--------------------------------------+----------------+-------------+--------------+
3 rows in set (0.00 sec)

2) Test with sysbench

[root@tango-01 sysbench]# sysbench ./tests/include/oltp_legacy/select.lua --mysql-host=192.168.1.201 --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=sbtest  --oltp-tables-count=5 --oltp-table-size=50000 --threads=100 --time=600 --report-interval=1 run
[ 6s ] thds: 100 tps: 725.29 qps: 725.29 (r/w/o: 725.29/0.00/0.00) lat (ms,95%): 144.97 err/s: 0.00 reconn/s: 0.00
[ 7s ] thds: 100 tps: 724.89 qps: 724.89 (r/w/o: 724.89/0.00/0.00) lat (ms,95%): 144.97 err/s: 0.00 reconn/s: 0.00
[ 8s ] thds: 100 tps: 732.12 qps: 732.12 (r/w/o: 732.12/0.00/0.00) lat (ms,95%): 144.97 err/s: 0.00 reconn/s: 0.00
[ 9s ] thds: 100 tps: 710.10 qps: 710.10 (r/w/o: 710.10/0.00/0.00) lat (ms,95%): 170.48 err/s: 0.00 reconn/s: 0.00
[ 10s ] thds: 100 tps: 745.56 qps: 745.56 (r/w/o: 745.56/0.00/0.00) lat (ms,95%): 153.02 err/s: 0.00 reconn/s: 0.00
[ 11s ] thds: 100 tps: 729.63 qps: 729.63 (r/w/o: 729.63/0.00/0.00) lat (ms,95%): 142.39 err/s: 0.00 reconn/s: 0.00
[ 12s ] thds: 100 tps: 730.20 qps: 730.20 (r/w/o: 730.20/0.00/0.00) lat (ms,95%): 144.97 err/s: 0.00 reconn/s: 0.00

3) hang the process of one of the nodes with the kill -19 command to view the traffic in F5

Because the MySQL protocol is configured, select 1 does not return a normal result after the process hang lives. F5 will mark the member status as unavailable, and the traffic will not flow to the member.

reference material:

  1. https://blog.csdn.net/weixin_37569048/article/details/100053487
  2. https://blog.csdn.net/qq_35611533/article/details/51917279
  3. https://blog.csdn.net/solihawk/article/details/120315419

Please indicate the original address for Reprint: https://blog.csdn.net/solihawk/article/details/120321153
The article will be synchronized in the official account of "shepherd's direction". Interested parties can official account. Thank you!

Topics: Database MySQL Load Balance