For a reliable MariaDB cluster, it is required to have at least 3 hosts (with Ubuntu 14.04) running together.
You will also need to install
mariadb-galera-server on all the three nodes, as described further.
The MariaDB and Galera packages are not available in the default Ubuntu repositories. However, the MariaDB project maintains its own repositories for Ubuntu, which contain all the packages that we need.
On each of the three servers that will be configured for this cluster, do the following:
Add the key files for the MariaDB repository.
Add the repository.
You can now install the Galera patches through the apt interface.
During the installation process you will be asked to configure the root password for the MariaDB, so make sure that you configured the same root password on all the three nodes:
Once the installation of these packages is done, you will get a MariaDB server on each one of your three nodes. However, they are yet to be configured.
If, for some reason, you do not already have rsync installed on your machines, you should install it now by typing:
First of all, open the "/etc/mysql/
my.cnf" file and comment the following lines on all the three nodes:
Then, change the
Add the following lines under
Proceed to set the wsrep configurations on each node under the
[mysqld], using the specific hostname, root password and IP address of each node.
To finish, save and close the file "/etc/mysql/my.cnf" on all the three nodes.
Currently, Ubuntu and Debian's MariaDB servers use a special maintenance user to do routine maintenance. Some tasks that fall outside of the maintenance category are also executed by this user, including some important functions such as stopping MySQL.
In the case of a cluster environment shared between individual nodes, the maintenance user, which randomly generates login credentials on each node, is unable to execute its commands correctly. In such a case only the initial server will have the correct maintenance credentials, and the others will attempt to use their local settings to access the shared cluster environment.
To fix this, copy the contents of the maintenance file to each individual node as follows:
On one of your servers, open the Debian maintenance configuration file.
You will see a file that looks like this:
You will simply need to copy this information and paste it into the same file on each node.
On your second and third nodes, open the same file.
Delete the current information and paste the parameters from the first node's configuration file into these other servers' files.
They should be exactly the same now. Save and close the files.
To start the MariaDB cluster, do the following:
Please check ports 4444 and 4567. This ports must be free.
Stop the running MariaDB service by typing the following line on each of the nodes.
Start up your first node with a special parameter.
In the cluster configuration, each node that comes online tries to connect to at least one other node specified in its configuration file to get its initial state. Without the
--wsrep-new-cluster parameter, this command would fail because the first node is unable to connect to any other nodes.
On each of the other nodes, start MariaDB as you normally would.
Your cluster should now be online and communicating.
You can also confirm the status of your running cluster and its replication by running the following command on each of your node. The cluster size will be also displayed in the output of this command.
If you want to create a new user, do as follows:
Don't use "ALL PRIVILEGES" when you create a user for your database.
For more information about "privileges" provided by MySQL refer to http://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html