MariaDB galera Cluster Deployment (How to quickly deploy MariaDB clusters)

Source: Internet
Author: User
Tags documentation rsync

MARIADB, as a branch of MySQL, is already widely used in open source projects, such as hot OpenStack, so the cluster deployment is essential to ensure high availability of the service while increasing the load capacity of the system.

MariaDB Galera Cluster Introduction

The MARIADB cluster is a MARIADB synchronous multi-host cluster. It only supports the XTRADB/INNODB storage engine (although there are support for MyISAM experiments-see WSREP_REPLICATE_MYISAM system variables).

Main functions:

    • Synchronous replication
    • True multi-master that all nodes can read and write to the database at the same time
    • Automatic node member control, failed nodes are automatically cleared
    • New node joins data automatic replication
    • True parallel replication, row-level
    • Users can connect directly to the cluster, using the same feeling on MySQL exactly

Advantage:

    • Because it is multi-master, there is no slavelag (delay)
    • There is no loss of transaction condition
    • Ability to expand both read and write
    • Smaller client latency
    • Data between nodes is synchronous, and Master/slave mode is asynchronous, and binlog on different slave may be different

Technology:

The replication capabilities of the Galera cluster are based on the galeralibrary implementation, and in order to enable MySQL to communicate with the Galera library, the Wsrep API has been developed specifically for MySQL.

Galera plug-in to ensure that the cluster synchronization of data, maintain data consistency, relying on the replication of authentication, working principle such as:

When the client issues a commit instruction, all changes to the database are collected and the write-set write-set contents of the record are sent to the other nodes before the transaction is committed.

write-setThe authentication test is performed on each node, and the test results determine whether the node applies the write-set change data.

If the authentication test fails, the node discards the Write-set and if the authentication test succeeds, the transaction commits.

1. Installation Environment Preparation

At least 3 servers are required to install the MARIADB cluster (if only two units are required, please refer to the official documentation for special configuration)

Here, I list the configuration of the test machine:

Operating system version: Centos7

node4:10.128.20.16 node5:10.128.20.17 node6:10.128.20.18

With the first act example, node4 for hostname , 10.128.20.16 for ip , in three machines to modify the /etc/hosts file, my file is as follows:

10.128.20.16 node410.128.20.17 node510.128.20.18 node6

To ensure that the nodes communicate with each other, you need to disable the firewall settings (if a firewall is required, refer to the official website to increase firewall information settings)

Execute the command on three nodes, respectively:

systemctl stop firewalld

/etc/sysconfig/selinuxthe settings are then selinux set so that the disabled initialization environment is complete.

2. Install MariaDB Galera Cluster
[[email protected] ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync
[[email protected] ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync
[[email protected] ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync
3. Configure MariaDB Galera Cluster

Initializes the database service with only one node


[[email protected] mariadb]# systemctl start mariadb[[email protected] mariadb]# mysql_secure_ Installationnote:running all PARTS of this SCRIPT are 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 would be a blank,so you should just Press ENTER here. Enter current password to 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 had an anonymous user, allowing Anyoneto log into MariaDB without had to had a user Account created Forthem. This was 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 is allowed to connect from ' localhost '. Thisensures that someone cannot guess at the root of password from the network. Disallow Root login remotely? [y/n] Y ... success! By default, the MariaDB comes with a database named ' Test ' anyone canaccess. This was also intended only for testing, and should was removedbefore moving into a production environment. Remove test database and access to it? [y/n] n ... skipping. Reloading the privilege tables would 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 is secure. Thanks for using mariadb!

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

[[email protected] mariadb]# systemctl stop mariadb[[email protected] ~]# 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 you do not use SSL authentication, please wsrep_provider_options comment out.

Copy this file to Node5, Node6, and change it to wsrep_node_name wsrep_node_address the corresponding node hostname ip .

4. Start MariaDB galera Cluster Service
[[email protected] ~]# /usr/libexec/mysqld --wsrep-new-cluster --user=root &

Observation log:

[[email protected] ~]# 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

Appear ready for connections to prove that we started successfully and continue to start other nodes:

[[email protected] ~]# systemctl start mariadb[[email protected] ~]# systemctl start mariadb

You can see /var/log/mariadb/mariadb.log that the nodes are joined to the cluster in the log.

Warning?: --wsrep-new-cluster This parameter can only be used in the initialization cluster and can only be used on a single node.

5. View cluster status

We can focus on a few key parameters:

wsrep_connected = onLink is turned on

wsrep_local_index = 1Index values 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:3306The access address of the node in the cluster

6. Verifying data synchronization

We are on the node4 new database galera_test , and then on node5 and on the node6 query, if you can query to galera_test this library, indicating that the data synchronization success, the cluster is working properly.


[[email protected] ~]# mysql -uroot -proot -e "create database galera_test"


[[email protected] ~]# mysql -uroot -proot -e "show databases"+--------------------+| Database |+--------------------+| information_schema || galera_test || mysql || performance_schema |+--------------------+


[[email protected] ~]# mysql -uroot -proot -e "show databases"+--------------------+| Database |+--------------------+| information_schema || galera_test || mysql || performance_schema |+--------------------+

At this point, our MariaDB Galera Cluster has been successfully deployed.

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

This article is a ONEAPM engineer original article. ONEAPM is the emerging leader in China's basic software industry, helping enterprise users and developers easily implement slow program code and real-time crawling of SQL statements. To read more technical articles, please visit the ONEAPM Official technology blog.

MariaDB galera Cluster Deployment (How to quickly deploy MariaDB clusters)

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.