slides cluster mysql

Embed Size (px)

DESCRIPTION

slides sobre instalacion y configuracion de un cluster mysql en maquinas virtuales, 2 nodos de datos, 2 replicas

Citation preview

Septiembre de 2011Samuel Prez

Mysql cluster

Definitions

NDBCLUSTER (also known as NDB) is an in-memory storage engine offering high-availability and data-persistence features. The NDBCLUSTER storage engine can be configured with a range of failover and load-balancing optionsThe Cluster portion of MySQL Cluster is configured independently of the MySQL servers. In a MySQL Cluster, each part of the cluster is considered to be a node (not a machine but a process).

types of cluster nodes

Management node (MGM node, started first)To manage the other nodes within the MySQL Cluster, performing functions as providing configuration data, starting and stopping nodes, running backup, and so forth.Data node (has to be a multiple of NbrOfReplicas)This type of node stores cluster dataSQL node: This is a node that accesses the cluster dataa traditional MySQL server (mysqld process) that uses the NDBCLUSTER storage engine

Cluster components

On mysql nodes

One creates tables with Engine=NDBCluster

CREATE TABLE t1 (a int, b int, c int, d int, e int,primary key(a), index(a,b))TABLESPACE ts1 STORAGE DISKengine=ndb;

Important

Although a MySQL Cluster SQL node uses the mysqld server damon, it differs in a number of critical respects from the mysqld binary supplied with the MySQL 5.1 distributions, and the two versions of mysqld are not interchangeable. In addition, a MySQL server that is not connected to a MySQL Cluster cannot use the NDB storage engine and cannot access any MySQL Cluster data.

Node, groups, partition and replica

(Data) Node. An ndbd process, which stores a replica that is, a copy of the partition assigned to the node group of which the node is a member. Node Group. A node group consists of one or more nodes, and stores partitions, or sets of replicasPartition. A portion of the data stored by the cluster. There are as many cluster partitions as nodes participating in the cluster. Each node is responsible for keeping at least one copy of any partitions assigned to it (that is, at least one replica) available to the cluster. A replica belongs entirely to a single node; a node can (and usually does) store several replicas. Replica. This is a copy of a cluster partition. Each node in a node group stores a replica. Also sometimes known as a partition replica. The number of replicas is equal to the number of nodes per node group.

Example: 4 data nodes
in 2 node groups

The data stored by the cluster is divided into four partitions, numbered 0, 1, 2, and 3.

Each partition is storedin multiple copieson the same node group[number_of_node_groups] = number_of_data_nodes / NoOfReplicas

Node groups

Node groups are formed implicitly.The first node group is formed by the set of data nodes with the lowest node IDs, the next node group by the set of the next lowest node identities, and so on.Example, assume that we have 4 data nodes and that NoOfReplicas is set to 2. The four data nodes have node IDs 2, 3, 4 and 5. Then the first node group is formed from nodes 2 and 3, and the second node group by nodes 4 and 5.

It is important to configure the cluster in such a manner that nodes in the same node groups are not placed on the same computer because a single hardware failure would cause the entire cluster to fail.

NoOfReplicas

There is no default value for NoOfReplicas; 2 is recommendedThe maximum possible value is 4; currently, only the values 1 and 2 are actually supported. Setting NoOfReplicas to 1 means that there is only a single copy of all Cluster data; in this case, the loss of a single data node causes the cluster to fail because there are no additional copies of the data stored by that node.The value for this parameter must divide evenly into the number of data nodes in the cluster. For example, if there are two data nodes, then NoOfReplicas must be equal to either 1 or 2, since 2/3 and 2/4 both yield fractional values; if there are four data nodes, then NoOfReplicas must be equal to 1, 2, or 4.

Ubuntu example
virtual machines

For the purposes of the test, we will use the following IP addresses in examples:
192.168.56.101 - Node 1 (cluster-Node1)
192.168.56.102 - Node 2 (cluster-Node2)192.168.56.103 -Management (clusterMGM)192.168.56.104 - Load balancer (SQL-LB)

Base server configuration

When your servers are provisioned, run the following commands on all four servers:apt-get install mysql-server
sudo apt-get install mysql-cluster-serverThe second uninstall te first?

Configuring MGM node

Edit /etc/mysql/ndb_mgmd.cnfThere is a template of the file in /usr/share/doc/mysql-cluster-server-5.1/examples/ndb_mgmd.cnf

[NDBD DEFAULT]
NoOfReplicas=2

# Management Node
[NDB_MGMD]NodeId=1
HostName=10.1.0.10
DataDir=/var/lib/mysql-cluster

# Storage Nodes (one for each node)
[NDBD]
HostName=10.1.0.11
DataDir=/var/lib/mysql-cluster

# SQL Nodes (one for each node)
[MYSQLD]
HostName=10.1.0.11

/etc/init.d/mysql-ndb-mgm start

Setting up SQL and data nodes

make a few changes to /etc/mysql/my.cnfIn [mysqld] section of the config file add:ndbcluster
ndb-connectstring=10.1.0.10 # ip of mgm node

In section for [MYSQL_CLUSTER] (create if it doesnt exist)ndb-connectstring=10.1.0.10 # ip of mgm node

If you are using separate data and sql nodes, the [mysqld] part is relevant to the sql nodes only, and the [MYSQL_CLUSTER] part is relevant to the data nodes only.

Initializing data and sql nodes

Acording to the mgm config file:mkdir /var/lib/mysql-cluster
chown mysql:mysql /var/lib/mysql-cluster

Start daemons/etc/init.d/mysql restart
(which starts the sql node)


/etc/init.d/mysql-ndb restart
(which starts the data node)

Checking in the management node

running ndb_mgm from the command line on the management node

ndb_mgm> show;
Cluster Configuration

[ndbd(NDB)] 2 node(s)
id=1 @ 192.168.56.101 (mysql-5.1.51 ndb 7.1.9, Nodegroup: 0, Master)
id=2 @ 192.168.56.102 (mysql-5.1.51 ndb 7.1.9, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=3 @ 192.168.56.103 (mysql-5.1.51 ndb 7.1.9)

[mysqld(API)] 1 node(s)
id=4 (not connected, accepting connect from 192.168.56.104)

Using the cluster

Any databases already on the servers will continue to work as before.Tables only become part of the cluster when their engine type is changed to ndbclusteralter table tablename engine=ndbcluster;

For new tables:create table clustertest (i int) engine=ndbcluster;

Using the cluster

Applications that use MySQL can employ standard APIs to access NDB tables. It is important to remember that your application must access the SQL node, and not the management or data nodes.

Using the cluster

end

Questions?

6/10/11

Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline Level

Ninth Outline LevelHaga clic para modificar el estilo de subttulo del patrn

Click to edit the title text formatHaga clic para modificar el estilo de ttulo del patrn

Click to edit the title text formatHaga clic para modificar el estilo de ttulo del patrn

Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline Level

Ninth Outline LevelHaga clic para modificar el estilo de texto del patrn

Segundo nivel

Tercer nivel

Cuarto nivel

Quinto nivel

6/10/11