1. Home
  2. Linux
  3. Ubuntu
  4. How to install Galera on Ubuntu 16

How to install Galera on Ubuntu 16

How to install Galera on Ubuntu 16
How to install Galera on Ubuntu 16

Getting Started

Make sure to confirm that you have the following things installed before you follow the guide:
• 1 Node (Cloud Server or Dedicated Server) running Ubuntu 16.
• Root access to the node or one sudo non-root user.

Installation process

A Galera installation is not as useful without multiple nodes; please be aware that you must always have an odd number of nodes in order to have a quorum for a production use.
This example will simulate a cluster by running two distinct local instances on separate IPs. For production use, you can perform this installation on a couple of separate servers that can communicate directly with each other
Start with installing the software-properties package. That will give you a command to easily install Ubuntu Personal Package Archives (PPAs) with separate repositories that users and teams can use to provide custom software or updates to the existing packages.

apt-get install software-properties-common -y
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

You will now need to use a utility shipped as part of the software-properties package to add the MariaDB PPA. That repository will contain the Galera plugin.

add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.utexas.edu/mariadb/repo/10.1/ubuntu xenial main'

The repository is installed, but you will still need to update the list of available packages. You will also need to install the MariaDB server package.

apt-get update
apt-get install mariadb-server rsync -y

Configuration Process

Now you must create a configuration file for Galera.

nano /etc/mysql/conf.d/galera.cnf
[mysqld]
#mysql settings
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_doublewrite=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
#galera settings
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_name="test_cluster"
wsrep_cluster_address=gcomm://10.0.0.119,10.0.0.120
wsrep_sst_method=rsync

In the example shown above, you will use the IPs ’10.0.0.119′ and ’10.0.0.120’.
For Galera to start, you will need to make sure that MySQL is stopped on both of the nodes.

systemctl stop mysql.service

To start the Galera cluster on the first node.

galera_new_cluster

You will have to make sure that the cluster is up and running so the second node can confirm it has something it can connect to.

mysql -u root -p -e "show status like 'wsrep_cluster_size'"

If all is working correctly, you should see the below.

+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 1 |
+--------------------+-------+

In your second node, launch the MySQL daemon.

systemctl start mysql.service

Testing the cluster’s functionality

Your second node should have automatically linked to the cluster. You can verify this using the following command.

mysql -u root -p -e "show status like 'wsrep_cluster_size'"

If everything is working accordingly, you should see the below.

+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 2 |
+--------------------+-------+

Now, create a database and see if it propagates across the Galera cluster. Type the below command on your first node.

mysql -u root -p
create database galera_test;
show databases like 'galera_test';
+------------------------+
| Database (galera_test) |
+------------------------+
| galera_test |
+------------------------+
1 row in set (0.00 sec)

Now verify that the change is confirmed on the second node.

mysql -u root -p
show databases like 'galera_test';
+------------------------+
| Database (galera_test) |
+------------------------+
| galera_test |
+------------------------+
1 row in set (0.00 sec)

Conclusion

This is just an example of a cluster; the information written here can be easily scaled up to a dozen nodes.

Updated on December 23, 2018

Was this article helpful?

Related Articles

Leave a Comment

[apsl-login-lite login_text='Please login with a social account']