如何测试MaxScale的负载均衡器

问题描述 投票:0回答:1

我在MariaDB中构建了主/从结构并设置了MaxScale。我尝试测试 MaxScale 是否将 SELECT 查询分发到多个副本数据库,但我不确定如何测试它。 这是我搭建的服务器的信息。

  • MariaDB 10.11

  • 最大缩放23.02.4

  • master数据库:192.168.30.140

  • 副本DB1:192.168.30.141

  • 副本DB2:192.168.30.142

  • 副本DB3:192.168.30.143

  • 最大尺度:192.168.30.145

  • 客户端:192.168.30.160

  • 端口3309:转到masterDB,3310:转到replicaDB

[maxscale]
threads=auto


[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=masterDB, replicaDB1, replicaDB2, replicaDB3
user=monitor
password=alj123
monitor_interval=2s


[masterDB]
type=server
address=192.168.30.140
port=3306
protocol=MariaDBBackend
proxy_protocol=true
persistpoolmax=100
persistmaxtime=3600s
monitoruser=monitor
monitorpw=alj123
max_routing_connections=1000


[replicaDB1]
type=server
address=192.168.30.141
port=3306
protocol=MariaDBBackend
proxy_protocol=true
persistpoolmax=100
persistmaxtime=3600s
monitoruser=monitor
monitorpw=alj123
max_routing_connections=1000


[replicaDB2]
type=server
address=192.168.30.142
port=3306
protocol=MariaDBBackend
proxy_protocol=true
persistpoolmax=100
persistmaxtime=3600s
monitoruser=monitor
monitorpw=alj123
max_routing_connections=1000


[replicaDB3]
type=server
address=192.168.30.143
port=3306
protocol=MariaDBBackend
proxy_protocol=true
persistpoolmax=100
persistmaxtime=3600s
monitoruser=monitor
monitorpw=alj123
max_routing_connections=1000

# definition of Write Service

[Write-Service]
type=service
router=readconnroute
router_options=master, slave
servers=masterDB
user=maxscale
password=alj123
max_connections=100

# definition of Read-Service

[Read-Service]
type=service
router=readconnroute
router_options=slave
servers=replicaDB1,
        replicaDB2,
        replicaDB3
user=read
password=alj123
max_connections=100


# Write-Listener

[Write-Listener]
type=listener
service=Write-Service
protocol=MariaDBClient
port=3309
address=0.0.0.0
proxy_protocol_networks=192.168.30.145/24

# Read-Listener

[Read-Listener]
type=listener
service=Read-Service
protocol=MariaDBClient
port=3310
address=0.0.0.0
proxy_protocol_networks=192.168.30.145/24

这是一个包含 SELECT 查询并从客户端(192.168.30.160)运行的 php 文件

<?php
$start = (new DateTime())->getTimestamp();
echo "start= $start" . PHP_EOL;


for ($i=0; $i<40000; $i++) {
   $mysqli = new mysqli("p:192.168.30.145", "client", "alj123", "TOPGUN", "3310");

   $mysqli->query("SELECT pilot from TOPGUN.pilots");
   $sql = "SELECT @@hostname";
   $result = $mysqli->query($sql);

   if ($result->num_rows > 0) {
       $row = $result->fetch_assoc();
       echo "DB's host: " . $row['@@hostname'] . PHP_EOL;
   } else {
       echo "Failed to get the host of the DB";
   }

   $result->free();
   $mysqli->close();
   unset($tmp, $row, $result, $mysqli);
}
   $end = (new DateTime())->getTimestamp();
   echo 'end= ' . ($end - $start) . PHP_EOL;
?>

我希望 MaxScale 将 SELECT 查询平均分配到三个副本数据库。 然而,结果是MaxScale只将查询传递给一个replicaDB。 我想知道如何测试 MaxScale。

有人可以帮助我吗?

proxy mariadb load-balancing master-slave maxscale
1个回答
0
投票
  1. 使用
  2. 登录到您的读取集群
mysql -ualj123 -p -P3310

用户 alj123 必须具有远程访问权限。即 alj123@'%'

  1. 记录运行后:
select @@hosthame;

然后将显示读取的主机名。默认为循环法。每次运行

select @@hostname;
时,都会显示不同的服务器名称。

© www.soinside.com 2019 - 2024. All rights reserved.