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
Labs

Implement a Primary-Replica Cluster Using MariaDB Galera Cluster and Galera Load Balancer

In this activity, you are working as a DBA and have been tasked with configuring a MariaDB Galera Cluster in a Primary-Replica configuration. The cluster is already up and running, but you will need to install the Galera Load Balancer and configure it appropriately.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 4h 0m
Published
Clock icon Jul 23, 2020

Contact sales

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

Table of Contents

  1. Challenge

    Set the root Database User's Password and Create a Database User Account

    The database nodes are running and connected to the cluster, however the root user's password has not been set. You must first set the root user's password by running the mysql_secure_installation script:

    sudo mysql_secure_installation
    

    Now you can connect to the database as the root user and create a user account:

    mysql -u root -p
    

    Once connected, you can use the following SQL to create a user named remote who is able to login remotely. Be sure to replace mypasswd with a password of your choice.

    create user remote identified by 'mypasswd';
    grant usage on *.* to 'remote'@'%' identified by 'mypasswd';
    
  2. Challenge

    Install the Prerequisite Packages

    sudo yum -y install git autoconf automake libtool gcc-c++ nmap-ncat
    
  3. Challenge

    Build the Galera Load Balancer Binaries

    git clone https://github.com/codership/glb
    cd glb
    ./bootstrap.sh
    ./configure
    make
    sudo make install
    
  4. Challenge

    Configure and Start Galera Load Balancer

    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
    

    Create glbd configuration file:

    sudo vi /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'"
    

    Start the service:

    sudo service glb start
    sudo service glb status
    
  5. Challenge

    Confirm Connections to Primary and Replica Nodes

    Connect to the primary node via the load balancer:

    mysql -h 10.0.1.100 -P 13306 -u remote -p
    

    The connection is sent to the single server with the highest weight of those available, in this case node0.

    Connections to the replica can be made directly on port 3306:

    mysql -h 10.0.1.110 -P 3306 -u remote -p
    
  6. Challenge

    Promote Replica to Primary

    A replica node can become the primary node by changing each of their weights:

    service glb add 10.0.1.100:3306:1
    service glb add 10.0.1.110:3306:10
    

    Confirm connections are routed to node1:

    mysql -h 10.0.1.100 -P 13306 -u remote -p
    service glb status
    

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