November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

MariaDB Galera Cluster deployment

MariaDB Galera Cluster deployment (how quickly deploy MariaDB cluster)

MariaDB is a branch of Mysql, has been widely used in open source projects, such as hot openstack, therefore, in order to ensure high availability of services, while increasing the load capacity of the system, clustered deployment is essential.

MariaDB Galera Cluster Introduction

MariaDB MariaDB cluster is synchronous multi-master cluster. It only supports XtraDB / InnoDB storage engine (although experimental support for MyISAM – see wsrep_replicate_myisam system variable).

The main function:

Replication
True multi-master, that is, all nodes can read and write the database at the same time
Automatic control node members, the failed node is automatically cleared
The new node joins the data is automatically copied
True parallel copy, row-level
Users can directly connect to the cluster, use exactly the same experience with MySQL
Advantage:

Because it is multi-master, Slavelag so there is no (delayed)
There is no case of lost transactions
But also has the ability to read and write extended
Smaller client latencies
Data synchronization between nodes, and the Master / Slave mode is asynchronous, the binlog on different slave may be different
technology:

Galera Cluster replication based Galeralibrary achieve, in order to allow MySQL and Galera library communications, developed specifically for MySQL wsrep API.

Galera Cluster Synchronization Plug-assurance data, maintaining data consistency, can rely on certified copy, it works in the following figure:

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

write-set will be certification testing at each node, the node test results determine whether to apply the write-set change data.

If the authentication test fails, the node will discard the write-set; if the certification test is successful, the transaction commits.

1. Installation Environment Preparation

Install MariaDB cluster requires at least 3 servers (if only two words requires special configuration, please refer to the official documentation)

Here, I list the configuration of the test machine:

Operating system version: CentOS 7

node4: 192.168.1.16 Node5: 192.168.1.17 Node6: 192.168.1.18

The first line as an example, node4 for the hostname, 192.168.1.16 for the ip, the three machines to modify / etc / hosts file, my file as follows:
192.168.1.16 Node4
192.168.1.17 Node5
192.168.1.18 Node6

In order to ensure mutual communication between nodes, need to disable the firewall settings (if you need a firewall, refer to the official website to increase the firewall settings)

Execute commands three nodes are:
systemctl STOP firewalld

Then the / etc / sysconfig / selinux selinux is set to disabled, so that the initialization is complete environment.

2. Install the Cluster Galera MariaDB
[Node4 the root @ ~] # yum the install -Y-MariaDB MariaDB MariaDB Galera-Server-Common-Galera Galera the 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. MariaDB Galera Cluster

Initialize the database service, only one node

[root@node4 mariadb]# systemctl start mariadb
[root@node4 mariadb]# mysql_secure_installation

NOTE: 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 current
password for the root user. If you’ve just installed MariaDB, and
you 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 MariaDB
root 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 anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n
… skipping.

Normally, root should only be allowed to connect from ‘localhost’. This
ensures 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 can
access. This is also intended only for testing, and should be removed
before 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 far
will 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 MariaDB
installation should now be secure.

Thanks for using MariaDB!

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

[mysqld]
……
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address = “gcomm://node4,node5,node6″
wsrep_node_name = node4
wsrep_node_address=192.168.1.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 have a way ssl certification, please put wsrep_provider_options commented.

Copy this file to node5, node6, attention should wsrep_node_name and wsrep_node_address into the corresponding node hostname and ip.

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

?????
[root@node4 ~]# tail -f /var/log/mariadb/mariadb.log

150701 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

Ready for connections appear to prove that we started successfully, continue to start another node:
[root @ Node5 ~] # systemctl Start MariaDB
[root @ Node6 ~] # systemctl Start MariaDB

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

Warning ?: – wsrep-new-cluster This cluster initialization parameters can only be used, and can only be used in a node.

5. Check the cluster status

We can focus on a few key parameters:

wsrep_connected = on the link is on

wsrep_local_index = 1 the cluster index value

wsrep_cluster_size = the number of nodes in the cluster 3

wsrep_incoming_addresses = 192.168.1.17:3306,192.168.1.16:3306,192.168.1.18:3306 access nodes in the cluster address

6. verification data synchronization

Our new database on node4 galera_test, then a query on node5 and node6, if you can check galera_test library, a data synchronization is successful, the cluster is operating normally.

[root@node4 ~]# mysql -uroot -p root -e “create database galera_test”

[root@node5 ~]# mysql -uroot -p root -e “show databases”
+——————–+
| Database |
+——————–+
| information_schema |
| galera_test |
| mysql |
| performance_schema |
+——————–+

[root@node6 ~]# mysql -uroot -p root -e “show databases”
+——————–+
| Database |
+——————–+
| information_schema |
| galera_test |
| mysql |
| performance_schema |
+——————–+

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

————————————–Dividing line———- —————————-

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>