How To Install MariaDB Galera Cluster on Ubuntu 16.04

How To Install MariaDB Galera Cluster on Ubuntu 16.04

MariaDB Galera is a multi-master cluster for MariaDB. Since MariaDB 10.1, the MariaDB Server and MariaDB Galera Server packages have been combined and Galera packages and their dependencies get installed automatically when installing MariaDB. Actuellement, MariaDB Galera Cluster only supports the InnoDB/XtraDB storage engine. In MariaDB 10.0 et 5.5, you will need to download it separately. MariaDB Galera adds redundancy for a site's database. In MariaDB Galera Cluster, multiple database servers interconnected with each other and keep synchronized.

MariaDB Galera provides lots of features, some of them are listed below:

  1. Synchronous replication.
  2. Automatic node joining.
  3. Active-active multi-master topology.
  4. True parallel replication, on row level.
  5. Read and write scalability, Smaller client latencies.
  6. Failed nodes, automatic drop from the cluster.

Dans ce tutoriel, we will explain how to setup MariaDB Galera Cluster 10.1 avec 3 nodes running on Ubuntu 16.04 serveur. We will also test database replication between all the nodes.

Exigences

  • Three Nodes running Ubuntu 16.04 serveur.
  • Node1 with static IP address 192.168.0.102, Node2 with static IP address 192.168.0.103 and Node3 with static IP address 192.168.0.104 configurer sur votre serveur.
  • Non-root user with sudo privileges setup on all the nodes.

Commencer

Premier, you will need to update all the nodes with the latest version. You can update all of them with the following command:

sudo apt-get update -y
sudo apt-get upgrade -y

Prochain, restart all the nodes to apply these changes. alors, log in with sudo user and proceed to the next step.

Install MariaDB Galera

MariaDB Server and MariaDB Galera Server packages are combined in the version MariaDB 10.1. Par défaut, MariaDB 10.1 is not available in the default Ubuntu repositories, so you will need to add the MariaDB repository on all the nodes.

Premier, add the MariaDB repository key with the following command:

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

Prochain, add the repository and update the APT cache with the following command:

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

Once the repository is updated, install MariaDB with the following command:

sudo apt-get install mariadb-server rsync -y

The above command will install MariaDB with Galera and several dependencies. The Galera parts remain dormant until configured, like a plugin or storage engine. Once the MariaDB is installed on all the nodes, you can proceed to secure MariaDB.

Par défaut, l'installation MariaDB est pas sécurisé, so you will need to secure MariaDB installation. You can do this by running the mysql_secure_installation script:

mysql_secure_installation sudo

In this process, you will be asked to set root password, supprimer des utilisateurs anonymes, disallow root login remotely and remove test database. Répondez à toutes les questions comme ci-dessous:

Enter current password for root (enter for none):
Change the root password? [Y/n] n
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Once the MariaDB is secured on all the nodes, vous pouvez passer à l'étape suivante.

Setup MariaDB Cluster on Node1

Premier, go to the Node1 and create a configuration file for Galera. Par défaut, MariaDB reads configuration from /etc/mysql/conf.d/ directory. Faire cela, exécuter la commande suivante:

sudo nano /etc/mysql/conf.d/galera.cnf

Ajoutez les lignes suivantes:

[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://192.168.0.102,192.168.0.103,192.168.0.104"

# Galera Synchronization Configuration
wsrep_sst_method=rsync

# Galera Node Configuration
wsrep_node_address="192.168.0.102"
wsrep_node_name="Node1"

Enregistrez le fichier lorsque vous avez terminé.

Remarque: 192.168.0.102 is the IP address of the Node1

Add Node2 on Galera Cluster

Prochain, go to the Node2 and create a configuration file for Galera:

sudo nano /etc/mysql/conf.d/galera.cnf

Ajoutez les lignes suivantes:

[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://192.168.0.102,192.168.0.103,192.168.0.104"

# Galera Synchronization Configuration
wsrep_sst_method=rsync

# Galera Node Configuration
wsrep_node_address="192.168.0.103"
wsrep_node_name="Node2"

Enregistrez le fichier lorsque vous avez terminé.

Remarque: 192.168.0.103 is the IP address of the Node2.

Add Node3 on Galera Cluster

Prochain, go to the Node3 and create a configuration file for Galera:

sudo nano /etc/mysql/conf.d/galera.cnf

Ajoutez les lignes suivantes:

[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://192.168.0.102,192.168.0.103,192.168.0.104"

# Galera Synchronization Configuration
wsrep_sst_method=rsync

# Galera Node Configuration
wsrep_node_address="192.168.0.104"
wsrep_node_name="Node3"

Enregistrez le fichier lorsque vous avez terminé.

Remarque: 192.168.0.104 is the IP address of the Node3.

Configurer le pare-feu

Galera Cluster uses four ports 3306 for MySQL client connection, 4444 for State Snapshot Transfer, 4567 for Galera Cluster replication traffic and 4568 for Incremental State Transfer. So you will need to allow all these ports using the UFW firewall. You can do this by running the following command on all the nodes:

Premier, enable the UFW firewall with the following command:

sudo ufw activer

Prochain, allow all the ports with the following command:

sudo ufw allow 3306/tcp
sudo ufw allow 4444/tcp
sudo ufw allow 4567/tcp
sudo ufw allow 4568/tcp
sudo ufw allow 4567/udp

You can then check the status of the firewall with the following command:

état ufw sudo

Once the UFW firewall is configured on all the nodes, vous pouvez passer à l'étape suivante.

Start MariaDB Galera Cluster

After successfully configuring all the nodes, go to the Node1 and start Galera Cluster.

Before Galera can start, you need to ensure that MariaDB service is stopped on all the nodes.

Run the following command on all the nodes:

sudo systemctl stop mysql

À présent, start the Galera Cluster on Node1 with the following command:

sudo galera_new_cluster

À présent, check whether the cluster is running or not with the following command:

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

If everything is fine you should see the following output:

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

On the Node2, start the MariaDB service:

mysql de début de sudo

You can check the status of MariaDB service whether it is working or not with the following command:

sudo systemctl status mysql

Si tout va bien, you should see the following output:

?? mariadb.service - MariaDB database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2017-09-17 10:11:20 EDT; 10min ago
  Process: 715 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 713 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
  Process: 545 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set
  Process: 535 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 514 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
 Main PID: 661 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 26 (limite: 4915)
   CGroup: /system.slice/mariadb.service
           ??????661 /usr/sbin/mysqld

Sep 17 10:11:11 debian systemd[1]: Starting MariaDB database server...
Sep 17 10:11:15 debian mysqld[661]: 2017-09-17 10:11:15 140287134630464 [Note] /usr/sbin/mysqld (mysqld 10.1.26-MariaDB-0+deb9u1) starting as process
Sep 17 10:11:20 debian systemd[1]: Started MariaDB database server.

À présent, your second node should've automatically linked to the cluster. You can verify that with the following command:

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

If everything is working well, the cluster size should be set to two:

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

On the Node3, start the MariaDB service:

mysql de début de sudo
mysql -u root -p -e "show status like 'wsrep_cluster_size'"

If everything is working well, the cluster size should be set to three:

+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+

You cluster is now working and communicating each other.

Test Database Replication

À présent, all the nodes are online, it's time to test database replication across the Galera Cluster. Let's start by creating a database on Node1 and check whether it is replicated on all the nodes.

Premier, login to MariaDb console with the following command:

mysql -u root -p

Enter your root password and create a database with name test_db:

MariaDB [(aucun)]> create database test_db;
MariaDB [(aucun)]> bases de données montrent;

+--------------------+
| Database           |
+--------------------+
| test_db            |
+--------------------+

Now go to the Node2 and Node3, then check replication is working or not:

mysql -u root -p
MariaDB [(aucun)]> bases de données montrent;

+--------------------+
| Database           |
+--------------------+
| test_db            |
+--------------------+

Congratulations! you have successfully installed and configured MariaDB Galera Cluster on Ubuntu 16.04 serveur.

Conclusion

I hope you have now enough knowledge to install and configure MariaDB Galera Cluster on Ubuntu 16.04. You can now easily scaled up to several, or even dozens, of distinct nodes. If you have any doubt or more query, then refer the link Galera Cluster Doc

La source

Laisser un commentaire

Ce site utilise Akismet pour réduire le spam. Découvrez comment vos données de commentaire est traité.

Nous utilisons des cookies pour vous donner la meilleure expérience en ligne. En vous acceptant acceptez l'utilisation de cookies conformément à notre politique de cookies.