Galera Cluster for MySQL - Source Installation

Galera Cluster for MySQL is the reference implementation from Codership Oy. Binary installation packages are available for Debian- and RPM-based distributions of Linux. If your Linux distribution is based upon a different package management system, if your server uses a different unix-like operating system, such as Solaris or FreeBSD, you will need to build Galera Cluster for MySQL from source.

Note

If you built Galera Cluster for MySQL over an existing standalone instance of MySQL, there are some additional steps that you need to take in order to update your system to the new database server. For more information, see Migrating to Galera Cluster.

Installing Build Dependencies

When building from source code, make cannot manage or install dependencies for either Galera Cluster or the build process itself. You need to install these first. For Debian-based systems, run the following command:

# apt-get build-dep mysql-server

For RPM-based distributions, instead run this command:

# yum-builddep MySQL-server

If neither command works on your system or that you use a different Linux distribution or FreeBSD, the following packages are required:

  • MySQL Database Server with wsrep API: Git, CMake, GCC and GCC-C++, Automake, Autoconf, and Bison, as well as development releases of libaio and ncurses.
  • Galera Replication Plugin: SCons, as well as development releases of Boost, Check and OpenSSL.

Check with the repositories for your distribution or system for the appropriate package names to use during installation. Bear in mind that different systems may use different names and that some may require additional packages to run. For instance, to run CMake on Fedora you need both cmake and cmake-fedora.

Building Galera Cluster for MySQL

The source code for Galera Cluster for MySQL is available through GitHub. You can download the source code from the website or directly using git. In order to build Galera Cluster, you need to download both the database server with the wsrep API patch and the Galera Replication Plugin.

To download the database server, complete the following steps:

  1. Clone the Galera Cluster for MySQL database server source code.

    # git clone https://github.com/codership/mysql-wsrep
    
  2. Checkout the branch for the version that you want to use.

    # git checkout 8.4
    

    The main branches available for Galera Cluster for MySQL are:

    • 8.0
    • 8.4

You now have the source files for the MySQL database server, including the wsrep API patch needed for it to function as a Galera Cluster node.

In addition to the database server, you need the wsrep Provider, also known as the Galera Replication Plugin. In a separator directory, run the following command:

# cd ..
# git clone https://github.com/codership/galera.git

Once Git finishes downloading the source files, you can start building the database server and the Galera Replication Plugin. The above procedures created two directories: mysql-wsrep/ for the database server source and for the Galera source galera/

Building the Database Server

The database server for Galera Cluster is the same as that of the standard database servers for standalone instances of MySQL, with the addition of a patch for the wsrep API, which is packaged in the version downloaded from GitHub. You can enable the patch through the wsrep API, requires that you enable it through the WITH_WSREP and WITH_INNODB_DISALLOW_WRITES CMake configuration options.

To build the database server, cd into the mysql-wsrep/ directory and run the following commands:

# cmake -DWITH_WSREP=ON -DWITH_INNODB_DISALLOW_WRITES=ON ./
# make
# make install

Building the wsrep Provider

The Galera Replication Plugin implements the wsrep API and operates as the wsrep Provider for the database server. What it provides is a certification layer to prepare write-sets and perform certification checks, a replication layer and a group communication framework.

To build the Galera Replicator plugin, cd into the galera/ directory and run SCons:

# scons

This process creates the Galera Replication Plugin, (that is, the libgalera_smm.so file). In your my.cnf configuration file, you need to define the path to this file for the wsrep_provider parameter.

Note

For FreeBSD users, building the Galera Replicator Plugin from source raises certain Linux compatibility issues. You can mitigate these by using the ports build at /usr/ports/databases/galera.

Post-installation Configuration

After the build completes, there are some additional steps that you must take in order to finish installing the database server on your system. This is over and beyond the standard configurations listed in System Configuration and Replication Configuration.

Note

Unless you defined the CMAKE_INSTALL_PREFIX configuration variable when you ran cmake above, by default the database server installed to the path /usr/local/mysql/. If you chose a custom path, adjust the commands below to accommodate the change.

  1. Create the user and group for the database server.

    # groupadd mysql
    # useradd -g mysql mysql
    
  2. Install the database.

    # cd /usr/local/mysql
    # ./scripts/mysql_install_db --user=mysql
    

    This installs the database in the working directory. That is, at /usr/local/mysql/data/. If you would like to install it elsewhere or run it from a different directory, specify the desired path with the --basedir and --datadir options.

  3. Change the user and group for the directory.

    # chown -R mysql /usr/local/mysql
    # chgrp -R mysql /usr/local/mysql
    
  4. Create a system unit.

    # cp /usr/local/mysql/supported-files/mysql.server \
          /etc/init.d/mysql
    # chmod +x /etc/init.d/mysql
    # chkconfig --add mysql
    

    This allows you to start Galera Cluster using the service command. It also sets the database server to start during boot.

In addition to this procedure, bear in mind that any custom variables you enabled during the build process, such as a nonstandard base or data directory, requires that you add parameters to cover this in the configuration file, (that is, my.cnf).

Note

This tutorial omits MySQL authentication options for brevity.