Fast Galera Cluster Deployments in the Cloud Using Juju
Canonical
on 15 June 2015
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
Related posts
Join us for Microsoft Ignite
The Canonical team is gearing up for the next big gathering at Microsoft Ignite 2024, which will take place from November 18 – 22, 2024. Get ready to dive...
Join Canonical in Dallas at Dell Technologies Forum
Canonical is excited to be a sponsor of the Dell Technologies Forum in Dallas, taking place on November 14th. This is a great opportunity to learn about the...
Virtual ECUs, or the future of automotive development and testing
We’ve seen how the automotive industry is rapidly embracing technological advancements, leveraging digital twins and environmental parity. However, there’s a...