Your submission was sent successfully! Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

Fast Galera Cluster Deployments in the Cloud Using Juju

This article is more than 8 years old.


The Galera Cluster Juju Charm was recently released, and it is now possible to start scalable Galera Clusters using the Juju deployment framework on the public or private cloud (OpenStack, Amazon, Azure and bare metal are all supported). All the logic required to fire up Galera is encapsulated in the Charm, which is a small package of scripts and configuration files that is automatically downloaded and added to your environment.

Installing and configuring Juju

The Juju client is available for Ubuntu, OSX and Windows. Installing it is a matter of adding its dedicated package repository:

$ sudo add-apt-repository ppa:juju/stable
$ sudo apt-get update && sudo apt-get install juju-core

Then run

$ juju generate-config

in order to create the Juju configuration file, ~/.juju/environments.yaml, which you can then edit for your particular cloud environment and provide your cloud authentication credentials.

You can now bootstrap Juju. This will create a single machine instance that is used to control all future instances started using Juju:

$ juju bootstrap

Deploying Galera using Juju

Once you have Juju set up, using it to deploy Galera Cluster becomes truly a one-liner. You only need a configuration file with your desired MySQL root password and SST password, as seen in the following template:

galera-cluster:
    root-password: my-root-password
    sst-password: my-sst-password

The SST password serves as a shared secret when transferring entire snapshots of the database from one node to another.

We are now ready to start our first node:

$ juju deploy --config galera.yaml cs:galera-cluster

Added charm “cs:~charmers/trusty/galera-cluster-4″ to the environment.

juju status shows us what this command did:

$ juju status
environment: amazon
machines:
  "0":
    agent-state: started
    agent-version: 1.22.3
    dns-name: 54.91.110.84
    instance-id: i-73516e8e
    instance-state: running
    series: trusty
    hardware: arch=amd64 cpu-cores=1 cpu-power=100 mem=1740M root-disk=8192M availability-zone=us-east-1a
    state-server-member-status: has-vote
  "1":
    agent-state: pending
    instance-id: i-f2db1d0d
    series: trusty
    hardware: arch=amd64 cpu-cores=1 cpu-power=100 mem=1740M root-disk=8192M availability-zone=us-east-1b
services:
  galera-cluster:
    charm: cs:~codership/trusty/galera-cluster-4
    exposed: false
    relations:
      cluster:
      - galera-cluster
    units:
      galera-cluster/0:
        agent-state: allocating
        machine: "1"

Juju has started a cloud server instance, i-f2db1d0d and began deploying the first Galera node. In a bit, the Juju status changes to fully started and running:

$ juju status galera-cluster
environment: amazon
machines:
  "1":
    agent-state: started
    agent-version: 1.22.3
    dns-name: 54.162.183.83
    instance-id: i-f2db1d0d
    instance-state: running
    series: trusty
    hardware: arch=amd64 cpu-cores=1 cpu-power=100 mem=1740M root-disk=8192M availability-zone=us-east-1b
services:
  galera-cluster:
    charm: cs:~codership/trusty/galera-cluster-4
    exposed: false
    relations:
      cluster:
      - galera-cluster
    units:
      galera-cluster/0:
        agent-state: started
        agent-version: 1.22.3
        machine: "1"
        public-address: 54.162.183.83

Now that our first Galera Cluster node has started, we can add another one with a single one-line command:

$ juju add-unit galera-cluster
and in a short while Juju will report that this node is also running:
$ juju status --format short galera-cluster
- galera-cluster/0: 54.162.183.83 (started)
- galera-cluster/1: 54.147.2.106 (started)

The cluster now has two nodes:

$ juju ssh galera-cluster/0 mysql -uroot -pmy-root-password

mysql> show status like '%wsrep_cluster_size%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 2     |
+--------------------+-------+
1 row in set (0.00 sec)
ACCESSING AND EXPOSING THE JUJU-STARTED GALERA CLUSTER

Juju charms are meant to be chained together to other applications that would require their services. For example, a Mediawiki charm that requires a MySQL database can be hooked to the Galera Cluster charm and Juju will internally connect them so that Mediawiki is automatically given the MySQL connection parameters it needs to start using the database. The Juju Documentation has more information about service relationships.

It is also possible to give external applications access to the Galera Cluster. First, we instruct Juju to open the MySQL connection port to external users:

juju expose galera-cluster

and then we can create MySQL users:

$ juju ssh galera-cluster/0 mysql -uroot -pmy-root-password

mysql> CREATE USER 'my-user'@'my-host' IDENTIFIED BY 'my-password';

The Juju Documentation has everything you need to start using Juju. The Galera Cluster Charm Documentation describes the Galera Cluster configuration options.

As we can see, we only had to provide a few configuration variables and run a few commands to have a fully functional Galera Cluster that can now be scaled with additional nodes or connected to other applications that require a fault-tolerant MySQL database. Juju and the Galera Cluster Juju Charm encapsulate all the logic that is required to start Galera Clusters on machine instances in a cloud provider.

About the author

Philip Stoev is a Test Developer at Codership, the company behind Galera Cluster. Philip specialises in automated testing of database products and distributed software including stress testing via fuzzing and stochastic workload generation; resilience testing of distributed systems, crash recovery and transactional durability; ACID compliance (transactional consistency, isolation, repeatable read) under concurrent workloads; automatic verification of SQL parsers and optimizers; and installation and package testing via VM automation. He also has experience with security audits and penetration testing of web sites and network-enabled software.

You can follow Codership on Twitter

Talk to us today

Interested in running Ubuntu in your organisation?

Newsletter signup

Get the latest Ubuntu news and updates in your inbox.

By submitting this form, I confirm that I have read and agree to Canonical's Privacy Policy.

Related posts

NIST CMVP Interim Validation & Jammy FIPS

If you need FIPS-validated cryptographic modules for your deployments, you may be aware that these have been turbulent times in the FIPS world. We have seen...

Space pioneers: Lonestar gears up to create a data centre on the Moon

Why establish a data centre on the Moon? Find out in our blog.

Ubuntu Security Notices now available in OSV format

Canonical is now issuing Ubuntu Security Notices (USNs) in the open source OSV format. Using the information provided, developers can identify known...