MariaDB Galera Cluster Deployment

Source: Internet
Author: User
Tags documentation rsync

Original http://code.oneapm.com/database/2015/07/02/mariadb-galera-cluster/
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, all changes to the database are collected by Write-set before the transaction is committed, and the contents of the Write-set record are sent to the other nodes.

Write-set will perform authentication tests on each node, and the test results determine whether the node applies 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 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

The/etc/sysconfig/selinux SELinux is then set to disabled so that the initialization environment is complete.

2 Installing 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 Configuration 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 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 comment out the wsrep_provider_options.

Copy this file to Node5, Node6, and notice that you want to change wsrep_node_name and wsrep_node_address to the hostname and IP of the corresponding node.

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 Li Brary ' 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

A ready for connections appears, proving that we started successfully and continued to start the other nodes:

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

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

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

5 Viewing cluster status

We can focus on a few key parameters:

wsrep_connected = On link is turned on

Wsrep_local_index = 1 index value in the cluster

wsrep_cluster_size = number of nodes in cluster 3

Wsrep_incoming_addresses = Access address of the node in the 10.128.20.17:3306,10.128.20.16:3306,10.128.20.18:3306 cluster

6 Verifying data Synchronization

We create a new database on the Node4 galera_test, and then on NODE5 and node6 query, if you can query to galera_test this library, the data synchronization is successful, the cluster is running normally.

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

    • http://galeracluster.com/documentation-webpages/
    • https://mariadb.com/kb/en/mariadb/getting-started-with-mariadb-galera-cluster/

MariaDB Galera Cluster Deployment

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.