Author: zhaorenhai
This article attempts to deploy MariaDB clusters on x86 and arm64 platforms to see if the deployment can be successful.
The deployment environment is carried out on HUAWEI CLOUD. The OS is openEuler 20.03 version and MariaDB version is 10.3.9.
In the official MariaDB documentation, there are two types of high-availability environment deployment methods. The simpler one is replication, and then the Galera cluster.
Let’s try these two high-availability environments separately, whether they support mixed deployment on x86 and arm64 platforms.
Replication
As the name implies, replication is that one or more slave databases replicate data from a master database in real time, so as to ensure that the data of the two databases are the same. This article will only try one primary - one replica scenario.
The purpose of replication:
• You can distribute read requests to multiple databases, thereby dispersing the pressure on the primary database, the most commonly used scenario is the scenario of more reads and less writes.
• Data analysis scenarios. Analyzing the data in the database generally requires more complex SQL. If it is executed on the main database, it will cause a lot of pressure on the main database, because the primary database is generally designed as an OLTP database, which is not suitable for analytical needs. With replication, data analysis can be performed only on the replica database, reducing the pressure on the primary database.
• Backup scenes. The backup itself will also have a relatively large performance impact on the database. With replication, and backup on the replica database can avoid the impact on the primary database. For databases that are frequently updated and inserted, you can disconnect them from the main database when you back up, so that the backup is faster and you can restore it after the backup.
• Data distribution, which can be replicated to distribute data to different regions.
The technical principle of replication: first back up the primary database data, and then restore it on the replica database to ensure that the basic data of the two databases are consistent, and then configure the replica database to apply the binlog of the primary database in real time to ensure the two database data consistency.
The deployment steps of Replication
First, purchase two cloud servers in the same network area of Huawei Cloud, one x86 and one arm64, ensure that the intranet can communicate with each other, and openEuler is selected for OS.
Then deploy the primary database on x86:
1 | yum install mariadb-server |
Create data file directory
1 | mkdir /var/db/mariadbdatadir |
Configure the database configuration file:
Modify /etc/my.cnf.d/mariadb-server.cnf
, add the following configuration under [mariadb]
(specific parameters can be adjusted according to your own environment):
1 | datadir = /var/db/mariadbdatadir |
Start the database:
1 | systemctl start mariadb.service |
Check whether the database started successfully
1 | systemctl status mariadb.service |
Load test data:
For simplicity, we use tpcc-mysql tool to load some tpcc data for testing
1 | yum install mariadb-devel |
Create a user:
1 | mysql -u root |
Now a working primary database with some data is configured.
Next we configure a replica database on the arm machine.
1 | yum install mariadb-server |
Create data file directory:
1 | mkdir /var/db/mariadbdatadir |
Configure the database:
modify /etc/my.cnf.d/mariadb-server.cnf
, add the following configuration under [mariadb]
(specific parameters can be adjusted according to your own environment):
1 | datadir = /var/db/mariadbdatadir |
Next, copy the basic data on the primary to replica.
Log in to the primary :
1 | mysql -u root |
Execute the following sql:
1 | flush tables with read lock; |
Record the results of File and Position in the above output.
Note that this session cannot be interrupted until the data backup of the primary below is completed.
Create a backup directory on primary:
1 | mkdir /var/db/mariadbbackup |
Perform backup:
1 | mariabackup --backup --target-dir=/var/db/mariadbbackup/ --user=root --password="" |
Then you can now unlock the above session, and execute the following sql in the above session:
1 | unlock tables; |
Copy the backed up data to the replica:
On primary:
1 | cd /var/db |
Operations on replica:
1 | scp root@192.168.0.196: /var/db/mariadbbackup.tar.gz /var/db/ |
Configure real-time replication:
1 | cd /var/db/mariadbbackup |
The output is as follows, remember these values, and use them for subsequent operations on replica.
1 | primary1-bin.000011 687 0-1-437 |
Operations on replica:
1 | mysql -u root |
Use the following command to view the replication status
1 | show slave status\G |
If the values of the following two items are both Yes, it is normal.
1 | Slave_IO_Running: Yes |
On the primary, load another database and perform the following test:
1 | cd tpcc-mysql/ |
Query on replica:
1 | mysql -u root |
The output is as follows:
1 | +--------------------+ |
You can see that the tpcc-test database is also generated normally, and
you can execute the following sql for further check:
1 | use database tpcc-test; |
If everything is normal, it means that the data is synchronized normally.
After the above test, it can be basically proved that the replication can be mixed deployment on x86 and arm64 environments.
Galera cluster
Galera cluster is a multi-master, multi-active cluster, data is synchronized between multiple nodes, to ensure that the data of multiple database nodes are consistent, unlike Oracle RAC, Galera cluster does not share storage, each database use an independent storage.
This has many advantages. Any database node will not affect the business if it is hung up. For applications with more read requests, it can also share the pressure well. Of course, for write requests, due to the existence of synchronization requests, the performance will be a little worse than that of a stand-alone database.
The data synchronization between multiple nodes of the Galera cluster is synchronous, not asynchronous, so that the consistency of the database on multiple nodes can be ensured, and there is no data divergence between multiple nodes. For performance considerations, it is not real-time. The synchronization technology uses a kind of virtual synchronization. The principle of virtual synchronization technology is more complicated. You can refer to the following article:
https://blog.csdn.net/wzy0623/article/details/102522268
Galera cluster deployment steps
We plan to deploy a three-node x86 Galera cluster, and then deploy a GLB load balancer on the front end.
First, purchase four x86 and one arm cloud server instances on Huawei Cloud, specifications: 4vCPUs 16GB memory, CPU frequency 2.6GHz. The OS still uses the openEuler20.03 version.
Four x86 cloud servers, one is used to deploy GLB, and the other three are used to deploy MariaDB Galera cluster. An arm cloud server is used to deploy MariaDB nodes that will later join the cluster.
Perform the following operations on the three x86 cluster nodes:
1 | yum install mariadb-server |
Create data file directory
1 | mkdir /var/db/mariadbdatadir |
Configure the database configuration file:
modify /etc/my.cnf.d/mariadb-server.cnf
, add the following configuration under [mariadb]
(specific parameters can be adjusted according to your own environment):
1 | datadir = /var/db/mariadbdatadir |
Then execute systemctl start mariadb
, start the database
Each node then performs the following operations:
1 | yum install mariadb-server-galera |
Modify the /etc/my.cnf.d/galera.cnf
.wsrep_cluster_address
item should be configured to the following values, where the value of each IP address is the intranet IP of the three cluster nodes:
1 | wsrep_cluster_address="gcomm://192.168.0.159,192.168.0.78,192.168.0.23" |
On the first node, stop the database:
1 | systemctl stop mariadb |
Execute the following command on the first node to initialize the cluster:
1 | galera_new_cluster |
Then restart the database on the other two nodes:
1 | systemctl restart mariadb |
You can log in to the database and use the following command to view the cluster status:
1 | show status like 'wsrep%'; |
Now that the cluster is successfully built.
We are going to build a GLB load balancer next.
GLB is a pure TCP layer load balancer, simple and easy to use.
1 | yum install gcc* libtool |
Edit the /etc/default/glbd
configuration as follows:
1 | LISTEN_ADDR="8010" |
Then start the load balancer
1 | cd files |
Then log in to any database of the cluster node and execute the following sql to create a user
1 | create user 'tpcc'@'192.168.0.%' identified by '123456'; |
Now start to load some test data.
On the node where the load balancer is located:
1 | yum install mariadb |
Load test data
1 | mysqladmin -h 127.0.0.1 -P 8010 -u tpcc -p123456 create tpcc10 |
Next, stop one of the x86 cluster nodes and prepare to replace it with an arm64 node.
Log in to one of the cluster nodes:systemctl stop mariadb
and then log in to the other two cluster nodes, change the value of wsrep_cluster_address
in /etc/my.cnf.d/galera.cnf
from the IP of the stopped node to the IP of the am64 node.
Perform the following operations on the arm64 node:
1 | yum install mariadb-server |
Create data file directory
1 | mkdir /var/db/mariadbdatadir |
Configure the database configuration file:
Modify /etc/my.cnf.d/mariadb-server.cnf
, add the following configuration under [mariadb]
(specific parameters can be adjusted according to your own environment):
1 | datadir = /var/db/mariadbdatadir |
Then execute systemctl start mariadb
, start the database
1 | yum install mariadb-server-galera |
Modify the /etc/my.cnf.d/galera.cnf
,wsrep_cluster_address
should be configured to the following values, which is consistent with the other two x86 nodes.
1 | wsrep_cluster_address="gcomm://192.168.0.159,192.168.0.78,192.168.0.173" |
Then execute systemctl restart mariadb
and wait for the restart to succeed, which may be slower.
Then log in to the database and enter the following command to view the cluster status
1 | show status like 'wsrep%'; |
Then log in to the database on the arm64 node to check whether the data is synchronized normally.
If everything is normal, we log in to the load balancer node, we can unload the previous data, then reload the data, and test the large-scale deletion and new data scenarios.
1 | cd tpcc-mysql |
Then log in to each database to query whether the data is consistent.
After the above test, it can be proved that the Galera cluster can also be mixed deployment on x86 and arm64.