- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
Creating a Galera Cluster with LXD
LXD offers a quick-to-deploy, highly-efficient environment in which we can host a fault-resistant Galera cluster. In this hands-on lab, we'll do just that by creating and configuring an initial container, then using that as a basis for a three-node Galera cluster.
Lab Info
Table of Contents
-
Challenge
Configure the Initial Cluster Containers
Create the container:
lxc launch ubuntu:18.04 galera01Access the container and run initial updates:
lxc exec galera01 -- bash apt update apt upgradeAdd the MariaDB repository:
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 add-apt-repository 'deb [arch=amd64,ppc64el] http://ftp.utexas.edu/mariadb/repo/10.1/ubuntu bionic main' apt updateInstall MariaDB:
apt install mariadb-server -yRun
mysql_secure_installation:mysql_secure_installationUpdate the
innodb_buffer_pool_sizefor the MariaDB configuration:vim /etc/mysql/my.cnfinnodb_buffer_pool_size = 16MConfigure the firewall:
ufw enable ufw allow 3306/tcp ufw allow 4444/tcp ufw allow 4567/tcp ufw allow 4568/tcp ufw allow 4567/udp ufw statusExit the container and take a snapshot:
exit lxc snapshot galera01 initCreate the two additional containers and start them:
lxc copy galera01/init galera02 lxc copy galera01/init galera03 lxc start galera02 lxc start galera03 -
Challenge
Configure Galera
View all containers and make note of each IP address:
lxc listOpen the
galera.cnfconfiguration in thecloud_user's home directory and update thewsrep_cluster_addressto list all IP addresses. Update thewsrep_node_addressandwsrep_node_namefor thegalera01node:vim galera.cnf[mysqld] binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 # Galera Provider Configuration wsrep_on=ON wsrep_provider=/usr/lib/galera/libgalera_smm.so # Galera Cluster Configuration wsrep_cluster_name="galera_cluster" wsrep_cluster_address="gcomm://<IP_ADDRESS>,<IP_ADDRESS>,<IP_ADDRESS>" # Galera Synchronization Configuration wsrep_sst_method=rsync # Galera Node Configuration wsrep_node_address="<IP_ADDRESS>" wsrep_node_name="galera01"Push to the first container:
lxc file push galera.cnf galera01/etc/mysql/conf.d/galera.cnfUpdate the configuration file again, changing the
addressandnameso it works withgalera02:vim galera.cnfwsrep_node_address="<IP_ADDRESS>" wsrep_node_name="galera02"lxc file push galera.cnf galera02/etc/mysql/conf.d/galera.cnfDo the same for
galera03:vim galera.cnfwsrep_node_address="<IP_ADDRESS>" wsrep_node_name="galera03"lxc file push galera.cnf galera03/etc/mysql/conf.d/galera.cnf -
Challenge
Start the Cluster
Stop MySQL on all nodes:
lxc exec galera01 -- systemctl stop mysql lxc exec galera02 -- systemctl stop mysql lxc exec galera03 -- systemctl stop mysqlStart the Galera cluster:
lxc exec galera01 -- galera_new_cluster lxc exec galera02 -- systemctl start mysql lxc exec galera03 -- systemctl start mysqlTo confirm that everything is working, view the cluster size on all containers:
lxc exec galera01 -- mysql -u root -p -e "show status like 'wsrep_cluster_size'" lxc exec galera02 -- mysql -u root -p -e "show status like 'wsrep_cluster_size'" lxc exec galera03 -- mysql -u root -p -e "show status like 'wsrep_cluster_size'"
About the author
Real skill practice before real-world application
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.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.