Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Introduction

Clustering will add high availability to our database by distributing changes to different servers.
In the event that one of the instances fails, others are quickly available to continue serving.

Clusters come in two general configurations, active-passive and active-active. In active-passive


clusters, all writes are done on a single active server and then copied to one or more passive
servers that are poised to take over only in the event of an active server failure. Some
active-passive clusters also allow SELECT operations on passive nodes. In an active-active
cluster, every node is read-write and a change made to one is replicated to all.

A MySQL Cluster consists of one or more management nodes (ndb_mgmd) that store the
cluster’s configuration and control the data nodes (ndbd), where cluster data is stored. After
communicating with the management node, clients (MySQL clients, servers, or native APIs)
connect directly to these data nodes.

We need 3 types of nodes to set up the complete cluster. They are management node, data
nodes & SQL node.

* Management node/server is used to manage other servers/nodes in the cluster, to add new
nodes in the cluster, start/restart/delete nodes in the cluster.
* Data node/server is the main storage server of the database files, it replicates databases with
other data nodes. This is the database cluster. High memory and storage should be avail on
data node servers.
* SQL node/server is the MySQL server/client which is used by application/php to connect to the
database cluster, working as an API. Actually, SQL node is the gateway engine between
application/php and database file.

Fig: ndbd cluster configuration


We are going to use five different server:
1. 192.168.7.130 - db node
2. 192.168.7.132 - sql node
3. 192.168.7.133 - management node
4. 192.168.7.134 - sql node
5. 192.168.7.135 - db node

System config:
We are using all cenOs 7 servers.

Start config:
We have to download the cluster bundle package in root directory. We can use wget to
download this rpm bundle on all these servers.

Link:
https://dev.mysql.com/get/Downloads/MySQL-Cluster-8.0/mysql-cluster-community-8.0.
21-1.el7.x86_64.rpm-bundle.tar
tar -xvzf

This command will extract all tar files from this downloaded bundle.

This package need to install and remove from all these server:
yum -y install perl-Data-Dumper
yum -y remove mariadb-libs

Management server config:


This package needs to be installed and remove first.
rpm -Uvh mysql-cluster-community-common-8.0.21-1.el7.x86_64.rpm
rpm -Uvh mysql-cluster-community-libs-8.0.21-1.el7.x86_64.rpm
yum localinstall
mysql-cluster-community-client-8.0.21-1.el7.x86_64.rpm
rpm -Uvh mysql-cluster-community-server-8.0.21-1.el7.x86_64.rpm
rpm -Uvh
mysql-cluster-community-management-server-8.0.21-1.el7.x86_64.rpm

Now we need to configure the MySQL cluster. Create a new directory where we want to setup
the cluster configureation.
mkdir -p /var/lib/mysql-cluster
cd /var/lib/mysql-cluster
nano -w config.ini

Write the configuration in config file.


[ndb_mgmd default]
# Directory for MGM node log files
DataDir=/var/lib/mysql-cluster

[ndb_mgmd]
NodeId=1
HostName=192.168.7.133

[ndbd default]
NoOfReplicas=2
DataMemory=256M
IndexMemory=128M
DataDir=/var/lib/mysql-cluster

[ndbd]
NodeId=2
HostName=192.168.7.130

[ndbd]
NodeId=3
HostName=192.168.7.135

[mysqld]
NodeId =5
HostName=192.168.7.132
[mysqld]
NodeId=6
HostName=192.168.7.134

We can skip to mention nodeId, it will select the default nodeId then.
Save the file.

Then start the management node.

ndb_mgmd --config-file=/var/lib/mysql-cluster/config.ini

Check the cluster status.


ndb_mgm -e show

Setup all data node now.


rpm -Uvh mysql-cluster-community-common-8.0.21-1.el7.x86_64.rpm
rpm -Uvh mysql-cluster-community-libs-8.0.21-1.el7.x86_64.rpm
yum -y install yum-protectbase
yum -y install epel-release
yum localinstall
mysql-cluster-community-client-8.0.21-1.el7.x86_64.rpm
rpm -Uvh mysql-cluster-community-server-8.0.21-1.el7.x86_64.rpm
rpm -Uvh mysql-cluster-community-data-node-8.0.21-1.el7.x86_64.rpm

Update the my.cnf file to configure all node.


[mysqld]
ndbcluster
ndb-connectstring=192.168.7.133

[mysql_cluster]
ndb-connectstring=192.168.7.133

Then create the database cluster data folder.


mkdir -p /var/lib/mysql-cluster

Make sure the firewall port is open for 1186 and SELinux is disable for all nodes.
Try run the command ‘ndbd’ for both node
ndbd

Finally setup the sql node/API


rpm -Uvh mysql-cluster-community-common-8.0.21-1.el7.x86_64.rpm
rpm -Uvh mysql-cluster-community-libs-8.0.21-1.el7.x86_64.rpm
yum install yum-protectbase
yum install epel-release
yum localinstall
mysql-cluster-community-client-8.0.21-1.el7.x86_64.rpm
rpm -Uvh mysql-cluster-community-server-8.0.21-1.el7.x86_64.rpm

Edit my.cnf file for the MySQL node.


[mysqld]
ndbcluster
ndb-connectstring=192.168.7.133
default_storage_engine=ndbcluster

[mysql_cluster]
ndb-connectstring=192.168.7.133
Restart all mysql services:
service mysqld restart

Before start mysqld without security add this under [mysqld]


skip-grant-tables

Complete this:
mysql_secure_installation

GRANT ALL PRIVILEGES ON * . * TO 'root'@'%';


ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY
'your_password';

You might also like