cmndrsp0ck.galera-cluster
galera-cluster
Purpose
This repository helps you set up and manage 2 HAProxy nodes with floating IPs and a MariaDB Galera cluster. We'll use Terraform for creating the resources and Ansible for configuring them.
Prerequisites
- Install Terraform to create the Droplet servers.
- You also need Ansible to apply settings to the new Droplets.
- Terraform will manage Ansible's inventory, so install terraform-inventory.
- Get a DigitalOcean API key. Follow the steps here.
- Use the provided
gen_auth_key
script to create an authentication key for your load balancing setup.
Configuration
Terraform
terraform.tfvars
Edit the sample file terraform.tfvars.sample and remove .sample from the name. Fill in the variables to let Terraform authenticate and deploy your Droplets.
- do_token - Your DigitalOcean API key.
- project - A name to identify different infrastructure groups.
- region - The location of your data center.
- image_slug - Use debian-9-x64 by default for specific Ansible roles.
- keys - Your DigitalOcean SSH key IDs.
- private_key_path - Path to your private key, usually in /home/
/.ssh/id_rsa. - ssh_fingerprint - Your SSH key's MD5 fingerprint.
- public_key - Contents of your SSH public key.
- ansible_user - Username to use for configuring Droplets with Ansible.
Ansible
Install Ansible roles using the requirements.yml file:
$ ansible-galaxy install -r requirements.yml
You'll need to set some sensitive variables in group_vars/. Check the README.md files for details.
Important! You’ll encrypt files using ansible vault. To avoid typing your password each time, save it in a file outside your repository:
$ echo 'password' > ~/.vaultpass.txt
And make sure to uncomment vault_password_file = ~/.vaultpass.txt
in your ansible.cfg file.
Now everything should be set up, and you can start provisioning and configuring your Droplets.
Deploying
Terraform
Begin with Terraform. Go to the root directory of the repository and run terraform init
to download the necessary plugins. Then, create an execution plan with terraform plan
.
Use terraform apply
to create the Droplets and floating IP. This will take about one or two minutes depending on how many nodes you are creating.
Ansible
After Terraform finishes, check network connectivity with ansible all -i /usr/local/bin/terraform-inventory -m ping
. You should see pong from all nodes.
Now you can configure the Droplets. Run the Ansible playbook from the repository root to configure them:
ansible-playbook -i /usr/local/bin/terraform-inventory site.yml
This playbook sets up heartbeat for floating IP reassignment, installs and configures HAProxy load balancers, and sets up the MariaDB Galera cluster. You’ll see output showing the role and progress, and if there are errors, you can trace them back easily.
License
GPL-3.0
Author Information
ansible-galaxy install cmndrsp0ck.galera-cluster