Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon

Creating a Galera Cluster with LXD

LXD offers a quick-to-deploy, highly-efficient environment in which we can host a fault-resistant Galera cluster. In this hands-on lab, we'll do just that by creating and configuring an initial container, then using that as a basis for a three-node Galera cluster.

Google Cloud Platform icon

Path Info

Clock icon Intermediate
Clock icon 45m
Clock icon Apr 03, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Configure the Initial Cluster Containers

    Create the container:

    lxc launch ubuntu:18.04 galera01

    Access the container and run initial updates:

    lxc exec galera01 -- bash
    apt update
    apt upgrade

    Add the MariaDB repository:

    apt-key adv --recv-keys --keyserver hkp:// 0xF1656F24C74CD1D8
    add-apt-repository 'deb [arch=amd64,ppc64el] bionic main'
    apt update

    Install MariaDB:

    apt install mariadb-server -y

    Run mysql_secure_installation:


    Update the innodb_buffer_pool_size for the MariaDB configuration:

    vim /etc/mysql/my.cnf
    innodb_buffer_pool_size = 16M

    Configure the firewall:

    ufw enable
    ufw allow 3306/tcp
    ufw allow 4444/tcp
    ufw allow 4567/tcp
    ufw allow 4568/tcp
    ufw allow 4567/udp
    ufw status

    Exit the container and take a snapshot:

    lxc snapshot galera01 init

    Create the two additional containers and start them:

    lxc copy galera01/init galera02
    lxc copy galera01/init galera03
    lxc start galera02
    lxc start galera03
  2. Challenge

    Configure Galera

    View all containers and make note of each IP address:

    lxc list

    Open the galera.cnf configuration in the cloud_user's home directory and update the wsrep_cluster_address to list all IP addresses. Update the wsrep_node_address and wsrep_node_name for the galera01 node:

    vim galera.cnf
    # Galera Provider Configuration
    # Galera Cluster Configuration
    # Galera Synchronization Configuration
    # Galera Node Configuration

    Push to the first container:

    lxc file push galera.cnf galera01/etc/mysql/conf.d/galera.cnf

    Update the configuration file again, changing the address and name so it works with galera02:

    vim galera.cnf
    lxc file push galera.cnf galera02/etc/mysql/conf.d/galera.cnf

    Do the same for galera03:

    vim galera.cnf
    lxc file push galera.cnf galera03/etc/mysql/conf.d/galera.cnf
  3. Challenge

    Start the Cluster

    Stop MySQL on all nodes:

    lxc exec galera01 -- systemctl stop mysql
    lxc exec galera02 -- systemctl stop mysql
    lxc exec galera03 -- systemctl stop mysql

    Start the Galera cluster:

    lxc exec galera01 -- galera_new_cluster
    lxc exec galera02 -- systemctl start mysql
    lxc exec galera03 -- systemctl start mysql

    To confirm that everything is working, view the cluster size on all containers:

    lxc exec galera01 -- mysql -u root -p -e "show status like 'wsrep_cluster_size'"
    lxc exec galera02 -- mysql -u root -p -e "show status like 'wsrep_cluster_size'"
    lxc exec galera03 -- mysql -u root -p -e "show status like 'wsrep_cluster_size'"

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans