Galera Load Balancer (GLB) is a third-party tool produced by FromDual. Downloads and official documentation is available on their site: http://www.fromdual.com/. Similar to Galera, GLB only runs on Linux.
It consists of a daemon called glbd
.
There is no client to manage GLB. To send administrative commands to GLB, for example to add or drop nodes, the generic nc
tool can be used. The nc
tool can communicate with a TCP daemon and print the reply on the screen, which is basically all we need to manage GLB. Here's the general syntax to send a command to glbd
from the command line:
echo "<command>" | nc -q 1 <host_address> <port>
The host_address
variable is the hostname or IP address, which glbd
is running on, probably 127.0.0.1. The port
variable is the port which glbd
is listening to. There is no standard port; we have to specify it when we start the daemon.
The syntax to start glbd
is as follows:
glbd [OPTIONS] <port> <node_list>
The port
variable can be a complete address if the machine has multiple network interfaces: address:port
.
The
node_list
variable is a space-separated list of Galera nodes. Each node can be specified as address:port:weight
. The weight is an important concept for glbd
, but it is only used if the daemon was started with the --top
or --single
option, or if the used policy (described next) takes the node's weight into account. With the
--top
option, the nodes with a higher weight will always be used if at least one of them is running. This option has no effect if all the running nodes have the same weight. With the
--single
option, only one node with the highest weight is used until it crashes. The node's weight is a useful feature if some servers run on machines with low resources, and should only be used for replication, unless the other nodes crash.
The standard informative options are supported in glbd
. The --help
and --version
options can be used, respectively, to print a help message or the version number and exit the program. The --verbose
option can be used to print more information on the screen.
Some of the most important options are:
--daemon
option runs glbd
as a daemon.--control <port>
option specifies which port will be used to accept administrative commands via nc
.--discovery
option enables the autodiscovery of new nodes when they are added to the cluster. The list of nodes is obtained from running known nodes.--top
and --single
options instruct glbd
to take the node's weight into account, as explained previously.--max_con <number>
option sets the maximum number of accepted connections to avoid overloading the cluster. Even if this option is not specified, a limit is imposed by the operating system.--threads <number>
option specifies the number of threads to be used. By default, only one thread is used.glbd
merges small packets of data into bigger packets to optimize the network usage. The --nodelay
option disables this mechanism.Unless the --single
option is used, we usually want to determine the policy that glbd
will use to choose the destination of each SQL statement. The policy can be chosen by specifying the corresponding option. The following are the supported policies:
--round
option, glbd
uses a circular list of nodes. When a connection request is received, it is redirected to the current node, and the cursor advances or goes back to the first node in the list.--random
option, each connection is redirected to a random node.--source
option, each client is assigned to a different server. All connection requests from the same client will always be redirected to the same node, unless the node crashes.Here are a couple of examples of the glbd
invocations:
glbd --daemon --control 8765 --threads 4 3306 host1:4567:1 host2:4567:1 host3:4567:1
In this example, the daemon will listen to the 3306
port (the standard MariaDB and MySQL port) for client connections, and the 8765
port for administrative commands. We have three hosts with the same weight and the standard policy is used. The glbd
variable will use four concurrent threads:
glbd --daemon --single 3306 host1:4567:3 host2:4567:2 host3:4567:1
In this example, glbd
runs on the standard MariaDB port but does not listen to any port for the administrative commands, so it will not be possible to modify the list of nodes at runtime. There are three nodes with different heights, but only host1
will be used. If host1
crashes, host2
will be used, and if that node crashes too, glbd
will use host3
.
In the following example, we will use nc
to add a new host:
echo "host4:4567:1" | nc -q 1 127.0.0.1 8765
The daemon is supposed to run on the local machine and listen to the 8765
port for administrative commands. The added node is node4
. Its weight is 1
.
The following example shows how to eliminate a host from the list:
echo "host2:4567:-1" | nc -q 1 127.0.0.1 8765
In the preceding example, we are setting host2
with a negative weight (-1
). Negative weights are used to drop servers from the list, so host2
will not be used anymore.
We can also use nc
to get some usage statistics from the daemon, as shown in the following example:
echo "getinfo" | nc -q 1 127.0.0.1 8765 Router: ---------------------------------------------------- Address : weight usage conns 191.52.7.1:4567 : 1.000 0.000 0 191.52.7.2:4567 : 1.000 0.000 0 191.52.7.3:4567 : 1.000 0.000 0 ---------------------------------------------------- Destinations: 3, total connections: 0