Andrew Mercer
on this page

Galera Cluster: Load Balancer (GLB)

Galera Load Balancer (GLB) is a simple TCP connection balancer purpose-built for scalability and performance in front of a Galera cluster. Since every node in a Galera cluster is technically writable, GLB is what lets you actually implement one of the access patterns described in Overview: Deployment Topologies — e.g. routing all writes to one preferred node to avoid certification conflicts.

Balancing Policies

  • Least connected — send to the node with the fewest active connections
  • Round robin — cycle through nodes in order
  • Single — send everything to one node (highest-weight available)
  • Random — send to nodes at random
  • Source tracking — connections from the same source address stick to the same node (useful for geo-distributed clients)
  • Top — restrict balancing to the subset of destinations with the top weight tier — e.g. with servers weighted 1 and 2, all traffic stays among weight-2 servers as long as at least one is available

Installation

sudo yum -y install git autoconf automake libtool gcc-c++ nmap-ncat
git clone https://github.com/codership/glb
cd glb
./bootstrap.sh
./configure
make
sudo make install

Configuration

sudo cp /home/cloud_user/glb/files/mysql.sh /usr/local/bin/mysql-check.sh
sudo cp /home/cloud_user/glb/files/glbd.sh /etc/init.d/glb
# /etc/sysconfig/glbd

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

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

# 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="10.0.1.100:3306:10 10.0.1.110:3306:1"

# Other glbd options if any as they would appear on the command line.
OTHER_OPTIONS="--single --watchdog exec:'/usr/local/bin/mysql-check.sh -uremote -pmypasswd'"

⚠️ Port note: GLB's default control port is 4444 — the same port Galera itself uses for rsync-based SST (see Overview: Ports). If GLB is running on the same host as a Galera node, one of these needs to move, or you'll get a bind conflict. This is easy to miss when auditing firewall rules across both layers.

The default watchdog only checks that the TCP port is open, which doesn't confirm the database is actually healthy. The --watchdog exec: option above runs a real health-check script (mysql-check.sh) instead, so a node that's up but not wsrep_ready gets pulled out of rotation.

Node Management

Nodes are added/removed at runtime via the control port, in ip_address:port:weight format (weight defaults to 1):

Add a node

echo "10.0.1.110:3306:5" | nc 127.0.0.1 4444

Remove a node

echo "10.0.1.110:3306:-1" | nc 127.0.0.1 4444

A negative weight deletes the node entirely — any connections currently open to it are closed immediately, not drained.

Performance Stats

echo "getstat" | nc 127.0.0.1 4444

Reference