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
$ 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: 220.127.116.11 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: 18.104.22.168 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: 22.214.171.124
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: 126.96.36.199 (started) - galera-cluster/1: 188.8.131.52 (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';
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.