Galera 集群负载均衡部署

Galera 集群负载均衡部署

我们有多个网站连接到一台正在运行的服务器MariaDB - 10.3.11,由于负载过重,我们决定实施Galera Cluster replication,该措施已实施,​​并且当数据库内的记录更新时,我们得到了预期的结果。

我们需要在这些 Galera Cluster 节点之间分配流量(代替单个服务器连接),因此我们需要部署Galera Cluster Load Balancer。我们将其安装在新服务器上,配置/etc/default/glbd如下所示:(所有服务器都在上运行Ubuntu 16.04。)

# This is a configuration file for glbd service script
#
# On Red Hat and derivatives it should be placed in /etc/sysconfig/glbd
#
# On Debian  and derivatives it should be placed in /etc/default/glbd
#
# All settings besides LISTEN_ADDR are optional.
#

# Address to listen for client connections at. Mandatory parameter.
# To bind to all interfaces only port should be specified.
LISTEN_ADDR="3306"

# Address for controlling connection. Mandatory part is port.
# If not specified control socket will not be opened
CONTROL_ADDR="4444"

# Control FIFO name. It is opened always. glbd will refuse to start if
# this file already exists.
CONTROL_FIFO="/var/run/glbd.fifo"

# Number of threads (connection pools) to use. It is always a good idea
# to have a few per CPU core.
THREADS="3"

# Maximum connections. System open files limit will be modified to accommodate
# at least that many client connections provided sufficient privileges.
# Normally you should set it if you plan to go above 500.
#MAX_CONN=

# Target servers for client connections, space separated.
# Target specification: IP[:PORT[:WEIGHT]] (WEIGHT and PORT optional)
# WEIGHT defaults to 1, PORT defaults to LISTEN_ADDR port.
DEFAULT_TARGETS="node1_ip:3306:1 node2_ip:3306:1 node3_ip:3306:1"

# Other glbd options if any as they would appear on the command line.
OTHER_OPTIONS="--round"

我们假设LISTEN_ADDR为 3306,因为我们需要将数据库的连接与安装了 Galera Cluster Load Balancer 的新服务器切换,该服务器在 3306 上安装并监听,而不是单个服务器(运行 MariaDB)。如果我们对端口的猜测是错误的,请纠正我们。

Section ASection B在下图中定义当前架构并定义建议的架构变更:

架构变化概述

这是服务启动时的 Galera Cluster Load Balancer 日志。

Jan 24 12:49:54 galera-lb-server systemd[1]: Starting LSB: run glbd daemon...
Jan 24 12:49:54 galera-lb-server glb[12112]: [Thu Jan 24 12:49:54 UTC 2019] glbd: starting...
Jan 24 12:49:54 galera-lb-server glb[12112]:    INFO: glb_daemon.c:44: Changing effective user to 'daemon'
Jan 24 12:49:54 galera-lb-server glb[12112]: glb v1.0.1 (epoll)
Jan 24 12:49:54 galera-lb-server glb[12112]: Incoming address: 0.0.0.0:3306, control FIFO: /var/run/glbd.fifo
Jan 24 12:49:54 galera-lb-server glb[12112]: Control  address:  127.0.0.1:4444
Jan 24 12:49:54 galera-lb-server glb[12112]: Number of threads: 3, max conn: 493, nodelay: ON, keepalive: ON, defer accept: OFF, linger: OFF, daemon: YES, lat.count: 0, policy: 'round-robin', top: NO, verbose: NO
Jan 24 12:49:54 galera-lb-server glb[12112]: Destinations: 3
Jan 24 12:49:54 galera-lb-server glb[12112]:    0:   node1_ip:3306 , w: 1.000
Jan 24 12:49:54 galera-lb-server glb[12112]:    1:  node2_ip:3306 , w: 1.000
Jan 24 12:49:54 galera-lb-server glb[12112]:    2:  node3_ip:3306 , w: 1.000
Jan 24 12:49:54 galera-lb-server glb[12112]: glb v1.0.1 (epoll)
Jan 24 12:49:54 galera-lb-server glb[12112]: Incoming address: 0.0.0.0:3306, control FIFO: /var/run/glbd.fifo
Jan 24 12:49:54 galera-lb-server glb[12112]: Control  address:  127.0.0.1:4444
Jan 24 12:49:54 galera-lb-server glb[12112]: Number of threads: 3, max conn: 493, nodelay: ON, keepalive: ON, defer accept: OFF, linger: OFF, daemon: YES, lat.count: 0, policy: 'round-robin', top: NO, verbose: NO
Jan 24 12:49:54 galera-lb-server glb[12112]: Destinations: 3
Jan 24 12:49:54 galera-lb-server glb[12112]:    0:   node1_ip:3306 , w: 1.000
Jan 24 12:49:54 galera-lb-server glb[12112]:    1:  node2_ip:3306 , w: 1.000
Jan 24 12:49:54 galera-lb-server glb[12112]:    2:  node2_ip:3306 , w: 1.000
Jan 24 12:49:54 galera-lb-server glbd[12133]: glb_main.c:194: Started.
Jan 24 12:49:54 galera-lb-server glb[12112]: [Thu Jan 24 12:49:54 UTC 2019] glbd: started, pid=12133
Jan 24 12:49:54 galera-lb-server systemd[1]: Started LSB: run glbd daemon.

但我们注意到日志中有如下错误:

Jan 24 13:36:58 galera-lb-server glbd[12133]: glb_pool.c:687: Async connection to node1_ip:3306 failed: 111 (Connection refused)
Jan 24 13:36:58 galera-lb-server glbd[12133]: glb_pool.c:699: Reconnecting to node1_ip:3306

以下是输出service glb getinfo

root@galera-lb-server:/# service glb getinfo
Router:
------------------------------------------------------
        Address       :   weight   usage    map  conns
 node1_ip:3306  :    1.000   0.000    N/A      0
 node2_ip:3306  :    1.000   0.000    N/A      0
 node3_ip:3306  :    1.000   0.000    N/A      0
------------------------------------------------------
Destinations: 3, total connections: 0 of 493 max

我们可以直接将不同的网站组连接到复制中的任何一个节点,但这不是正确的方法。请告诉我们如何部署,并让我们知道我们是否遗漏了什么。

答案1

我们在所有节点内绑定了相同的 IP 地址。

[mysqld]
bind-address = IP

Granted privileges为所有用户MariaDB to load balancer IP更改了所有网站的连接。设置正确的 MariaDB 用户访问权限时出现了愚蠢的错误。答案似乎很愚蠢,但希望对其他用户有所帮助。

相关内容