Hogyan kell telepíteni Ubuntu MariaDB Galera fürt 16.04

Hogyan kell telepíteni Ubuntu MariaDB Galera fürt 16.04

MariaDB Galera egy több főkiszolgálós cluster MariaDB. Óta MariaDB 10.1, a kiszolgáló MariaDB és MariaDB Galera kiszolgáló csomagok összevonásra került és Galera csomagok és a függőségek kap beiktatott gépiesen mikor MariaDB beiktatás. Jelenleg, MariaDB Galera Cluster only supports the InnoDB/XtraDB storage engine. In MariaDB 10.0 és 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.

Ebben a tutorial, we will explain how to setup MariaDB Galera Cluster 10.1 a 3 nodes running on Ubuntu 16.04 szerver. We will also test database replication between all the nodes.

Követelmények

  • Three Nodes running Ubuntu 16.04 szerver.
  • 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 configure on your server.
  • Non-root user with sudo privileges setup on all the nodes.

Első lépések

Első, 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

Következő, restart all the nodes to apply these changes. Majd, 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. Alapértelmezés, MariaDB 10.1 is not available in the default Ubuntu repositories, so you will need to add the MariaDB repository on all the nodes.

Első, add the MariaDB repository key with the following command:

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

Következő, 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.

By default MariaDB installation is not secured, so you will need to secure MariaDB installation. You can do this by running the mysql_secure_installation script:

sudo mysql_secure_installation

Ebben a folyamatban, you will be asked to set root password, remove anonymous users, disallow root login remotely and remove test database. Answer all the questions as shown below:

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, akkor folytassa a következő lépéssel.

Setup MariaDB Cluster on Node1

Első, go to the Node1 and create a configuration file for Galera. Alapértelmezés, MariaDB reads configuration from /etc/mysql/conf.d/ directory. Erre, Futtassa a következő parancsot:

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

Adja hozzá a következő sorokat:

[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"

Mentsd el a fájlt, ha elkészült.

Megjegyzés: 192.168.0.102 is the IP address of the Node1

Add Node2 on Galera Cluster

Következő, go to the Node2 and create a configuration file for Galera:

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

Adja hozzá a következő sorokat:

[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"

Mentsd el a fájlt, ha elkészült.

Megjegyzés: 192.168.0.103 is the IP address of the Node2.

Add Node3 on Galera Cluster

Következő, go to the Node3 and create a configuration file for Galera:

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

Adja hozzá a következő sorokat:

[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"

Mentsd el a fájlt, ha elkészült.

Megjegyzés: 192.168.0.104 is the IP address of the Node3.

Beállítás tűzfal

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:

Első, enable the UFW firewall with the following command:

sudo ufw engedélyezése

Következő, 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:

sudo ufw állapota

Once the UFW firewall is configured on all the nodes, akkor folytassa a következő lépéssel.

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

Most, start the Galera Cluster on Node1 with the following command:

sudo galera_new_cluster

Most, check whether the cluster is running or not with the following command:

mysql -u root -p -eshow 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:

sudo systemctl start mysql

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

sudo systemctl status mysql

Ha minden rendben, 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 (korlát: 4915)
   CGroup: /system.slice/mariadb.service
           ??????661 /usr/sbin/mysqld

Sep 17 10:11:11 debian systemd[1]: Starting MariaDB database server...
Szeptember 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.

Most, your second node should’ve automatically linked to the cluster. You can verify that with the following command:

mysql -u root -p -eshow 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:

sudo systemctl start mysql
mysql -u root -p -eshow 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

Most, 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.

Első, 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 [(nincs)]> create database test_db;
MariaDB [(nincs)]> a következő szálláshely adatbázisok;

+--------------------+
| Adatbázis |
+--------------------+
| test_db            |
+--------------------+

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

MySQL -u root -p
MariaDB [(nincs)]> a következő szálláshely adatbázisok;

+--------------------+
| Adatbázis |
+--------------------+
| test_db            |
+--------------------+

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

Következtetés

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

Forrás

Az egyik válasz