我们有多个网站连接到正在运行的单个服务器,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 A
Section 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
我们可以直接将不同的网站组连接到复制中的任何一个节点,但这不是正确的方法。请告诉我们如何部署,如果我们在这里遗漏任何东西,请告诉我们。
我们在所有节点中绑定了 IP 地址,所有节点都相同。
Granted privileges
对于所有网站的所有用户MariaDB to load balancer IP
和更改的连接。设置正确的 MariaDB 用户访问权限存在愚蠢的错误。答案似乎很愚蠢,但希望对其他用户有所帮助。