MariaDB Galera Cluster deployment (how to quickly deploy the MariaDB Cluster), galeramariadb

Source: Internet
Author: User

MariaDB Galera Cluster deployment (how to quickly deploy the MariaDB Cluster), galeramariadb

MariaDB, as a branch of Mysql, is widely used in open-source projects, such as the Popular openstack. To ensure the high availability of services and improve the load capacity of the system, cluster deployment is essential.

MariaDB Galera Cluster Introduction

MariaDB cluster is a MariaDB synchronization multi-host cluster. It only supports the XtraDB/InnoDB Storage engine (although there is support for the MyISAM experiment-see wsrep_replicate_myisam system variables ).

Main functions:

  • Synchronous Replication
  • Real multi-master, that is, all nodes can read and write databases at the same time.
  • Automatic node member control, and invalid nodes are automatically cleared
  • Automatic data replication for new nodes
  • Real parallel replication, row-level
  • You can directly connect to the cluster and feel exactly the same as MySQL.

Advantages:

  • Because it is multi-master, Slavelag does not exist (latency)
  • The transaction is not lost.
  • Both read and write scalability
  • Lower client latency
  • Data between nodes is synchronized, while the Master/Slave Mode is asynchronous. binlogs on different slave may be different.

Technology:

The replication function of the Galera cluster is implemented based on Galeralibrary. To allow MySQL to communicate with the Galera library, wsrep API is specially developed for MySQL.

The Galera plugin ensures that the cluster synchronizes data and maintains data consistency. It relies on authenticated replication. The working principle is as follows:

When the client sends a commit command, all changes to the database will bewrite-setCollect andwrite-setThe record content is sent to other nodes.

write-setThe authentication test will be performed on each node. The test result determines whether the node is applied.write-setChange Data.

If the authentication test fails, the node discards the write-set; if the authentication test is successful, the transaction is committed.

1. Prepare the installation environment

Installing the MariaDB cluster requires at least three servers (if only two servers are required, please refer to the official documentation)

Here, I will list the configurations of the test machine:

Operating system version: centos7

Node4: 10.128.20.16 node5: 10.128.20.17 node6: 10.128.20.18

In the first behavior example, node4 ishostname, 10.128.20.16 isip, Modify on three machines/etc/hostsFile. My file is as follows:

10.128.20.16 node410.128.20.17 node510.128.20.18 node6

To ensure mutual communication between nodes, You need to disable firewall settings (if you need a firewall, refer to the official website to add firewall information settings)

Run the following commands on the three nodes:

systemctl stop firewalld

Then/etc/sysconfig/selinuxOfselinuxSetdisabledIn this way, the initialization environment is complete.

2. Install MariaDB Galera Cluster
[root@node4 ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync
[root@node5 ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync
[root@node6 ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync
3. Configure MariaDB Galera Cluster

Initialize the Database Service, only on one node

[root@node4 mariadb]# systemctl start mariadb[root@node4 mariadb]# mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the currentpassword for the root user.  If you've just installed MariaDB, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none):OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [Y/n]New password:Re-enter new password:Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] n ... skipping.Normally, root should only be allowed to connect from 'localhost'.  Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y ... Success!By default, MariaDB comes with a database named 'test' that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] n ... skipping.Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y ... Success!Cleaning up...All done!  If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!

Close the database and modify/etc/my.cnf.d/galera.cnf

[root@node4 mariadb]# systemctl stop mariadb[root@node4 ~]# vim /etc/my.cnf.d/galera.cnf

Modify the following content:

[mysqld]......wsrep_provider = /usr/lib64/galera/libgalera_smm.sowsrep_cluster_address = "gcomm://node4,node5,node6"wsrep_node_name = node4wsrep_node_address=10.128.20.16#wsrep_provider_options="socket.ssl_key=/etc/pki/galera/galera.key; socket.ssl_cert=/etc/pki/galera/galera.crt;"

Tip: If ssl authentication is not requiredwsrep_provider_optionsComment out.

Copy this file to node5 and node6.wsrep_node_nameAndwsrep_node_addressChanged to the corresponding nodehostnameAndip.

4. Start the MariaDB Galera Cluster service
[root@node4 ~]# /usr/libexec/mysqld --wsrep-new-cluster --user=root &

Observe the log:

[root@node4 ~]# tail -f /var/log/mariadb/mariadb.log150701 19:54:17 [Note] WSREP: wsrep_load(): loading provider library 'none'150701 19:54:17 [Note] /usr/libexec/mysqld: ready for connections.Version: '5.5.40-MariaDB-wsrep'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server, wsrep_25.11.r4026

Appearsready for connectionsTo prove that we have started successfully and continue to start other nodes:

[root@node5 ~]# systemctl start mariadb[root@node6 ~]# systemctl start mariadb

You can view/var/log/mariadb/mariadb.logIn the log, the nodes are added to the cluster.

Warning:--wsrep-new-clusterThis parameter can only be used in the initialization cluster and can only be used on one node.

5. view the cluster status

We can focus on several key parameters:

wsrep_connected = onLink Enabled

wsrep_local_index = 1Index value in the Cluster

wsrep_cluster_size =3Number of nodes in the Cluster

wsrep_incoming_addresses = 10.128.20.17:3306,10.128.20.16:3306,10.128.20.18:3306Access address of nodes in the Cluster

6. Verify Data Synchronization

Innode4Create Database ongalera_testAnd thennode5Andnode6.galera_testThis database indicates that the data is synchronized successfully and the cluster runs normally.

[root@node4 ~]# mysql  -uroot  -proot  -e  "create database galera_test"
[root@node5 ~]# mysql  -uroot  -proot  -e  "show databases"+--------------------+| Database           |+--------------------+| information_schema || galera_test        || mysql              || performance_schema |+--------------------+
[root@node6 ~]# mysql  -uroot  -proot  -e  "show databases"+--------------------+| Database           |+--------------------+| information_schema || galera_test        || mysql              || performance_schema |+--------------------+

So far, our MariaDB Galera Cluster has been successfully deployed.

References:
[1] http://galeracluster.com/documentation-webpages/
[2] https://mariadb.com/kb/en/mariadb/getting-started-with-mariadb-galera-cluster/

This article is an original article by OneAPM engineers. OneAPM is a leading enterprise in the field of basic software in China. It helps enterprise users and developers easily achieve slow real-time crawling of program code and SQL statements. For more technical articles, visit the OneAPM official technical blog.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.