MariaDB Galera Cluster deployment (how to quickly deploy MariaDB Cluster)
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 be collected by the write-set before the transaction is committed, and the write-set record content will be sent to other nodes.
Write-set will be tested on each node. The test result determines whether the node uses write-set to change 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 is the hostname and 10.128.20.16 is the ip address. Modify the/etc/hosts file on the three machines. My file is as follows:
10.128.20.16 node4
10.128.20.17 node5
10.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
Set selinux of/etc/sysconfig/selinux to disabled, so that the initialization environment is complete.
2. Install MariaDB Galera Cluster
[Root @ node4 ~] # Yum install-y mariadb-galera-server mariadb-galera-common galera rsync
[Root @ node5 ~] # Yum install-y mariadb-galera-server mariadb-galera-common galera rsync
[Root @ node6 ~] # Yum install-y 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_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 shoshould 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
Them. This is intended only for testing, and to make the installation
Go a bit smoother. You shoshould remove them before moving into
Production environment.
Remove anonymous users? [Y/n] n
... Skipping.
Normally, root shoshould 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 shocould 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 shoshould 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.so
Wsrep_cluster_address = "gcomm: // node4, node5, node6"
Wsrep_node_name = node4
Wsrep_node_address = 10.128.20.16
# Wsrep_provider_options = "socket. ssl_key =/etc/pki/galera. key; socket. ssl_cert =/etc/pki/galera. crt ;"
Tip: If ssl authentication is not required, comment out wsrep_provider_options.
Copy this file to node5 and node6. Change wsrep_node_name and wsrep_node_address to the hostname and ip address of the corresponding node.
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. 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. sock' port: 3306 MariaDB Server, wsrep_25.11.r4026
If ready for connections is displayed, it indicates that the instance is successfully started. Continue to start other nodes:
[Root @ node5 ~] # Systemctl start mariadb
[Root @ node6 ~] # Systemctl start mariadb
You can view/var/log/mariadb. log. The log shows that all nodes are added to the cluster.
Warning -- wsrep-new-cluster: this 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 = on link enabled
Wsrep_local_index = 1 index value in the Cluster
Wsrep_cluster_size = 3 number of nodes in the Cluster
Wsrep_incoming_addresses = 10.128.20.17: 3306, 10.128.20.16: 3306, 10.128.20.18: 3306
6. Verify Data Synchronization
Create a database named galera_test on node4 and query it on node5 and node6. if you can query the database named galera_test, the data is synchronized successfully and the cluster runs normally.
[Root @ node4 ~] # Mysql-uroot-proot-e "create database ‑a_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.
-------------------------------------- Split line --------------------------------------
Install LAMP (Apache with MariaDB and PHP) in CentOS/RHEL/Scientific Linux 6)
Implementation of MariaDB Proxy read/write splitting
How to compile and install the MariaDB database in Linux
Install MariaDB database using yum in CentOS
Install MariaDB and MySQL
How to migrate MySQL 5.5 database to MariaDB 10 on Ubuntu
Install MariaDB on the Ubuntu 14.04 (Trusty) Server