F5负载均衡是网络控制设备将负载均衡的分发到多个操作单元,本文在虚拟机环境部署F5虚拟机,并配置TCP和兼容mysql协议探测方式连接mysql服务进行测试,以观察不同检测方式的影响。
1、VMware虚拟机部署F5虚拟环境
参考“数据库系列之F5负载均衡配置”配置部署F5虚拟环境,并激活license
这样就可以正常使用F5了
2、F5配置负载均衡
VMnet2,仅主机模式,ip地址段为192.168.1.0,这个将作为F5的external vlan地址
VMnet3,仅主机模式,ip地址段为192.168.198.0,这个将作为F5的管理节点的ip地址
VMnet8,NAT模式,ip地址段为192.168.112.0,用于虚拟机之间的通信和桥接
2.1 配置Platform
2.2 添加VLAN
2.3 配置Self-IP
2.4 新增monitor
F5默认的探测策略是TCP方式,F5每隔一个固定的时间,发送一个SYN包给资源池pool中的一个member,等待服务器返回SYN_ACK,在收到SYN_ACK后,F5会使用RST,将该连接重置。若F5在发出SYN包后,超过规定的时间仍未收到SYN_ACK,则认为这个member不可用,不再向这个member分配应用流量。TCP这种方式只能判断目标服务器的tcp端口是否处于listen状态,判断目标服务器是否有建立TCP连接的能力,不能完全用来判断应用的可用性。
2.5 创建pools
2.6 创建Virtual Servers
2.7 访问服务端口
1)访问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)访问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 查看服务器流量
3、F5负载均衡策略测试
1)MGR配置多写模式
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)使用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)将其中一个节点的进程使用kill -19命令hang住,查看F5中的流量
由于配置了MySQL协议,当进程hang住以后,select 1没有正常返回结果,F5会把这个member状态标志为不可用,流量也不会flow到这个member。
参考资料:
https://blog.csdn.net/weixin_37569048/article/details/100053487
https://blog.csdn.net/qq_35611533/article/details/51917279
https://blog.csdn.net/solihawk/article/details/120315419