Book Image

High Availability MySQL Cookbook

By : Alexander Davies
Book Image

High Availability MySQL Cookbook

By: Alexander Davies

Overview of this book

High Availability is something that all web sites hope to achieve, especially those that are linked to big companies.MySQL, an open source relational database management system (RDBMS), can be made highly available to protect from corruption, hardware failure, software crashes, and user error. Running a MySQL setup is quite simple. Things start getting complex when you start thinking about the best way to provide redundancy. There are a large number of techniques available to add 'redundancy' and 'high availability' to MySQL, but most are both poorly understood and documented.This book will provide you with recipes showing how to design, implement, and manage a MySQL Cluster and achieve high availability using MySQL replication, block level replication, shared storage, and the open source Global File System (GFS).This book covers all the major techniques available for increasing availability of your MySQL databases. It demonstrates how to design, implement, troubleshoot and manage a highly available MySQL setup using any one of several techniques, which are shown in different recipes. It is based on MySQL Cluster 7.0, MySQL (for non clustered recipes) 5.0.77, and CentOS / RedHat Enterprise Linux 5.3.The book starts by introducing MySQL Cluster as a technology and explaining how to set up a simple cluster. It will help you to master the options available for backing up and restoring a file in the MySQL Cluster. By following the practical examples in this book, you will learn how to manage the MySQL Cluster. Further, we will discuss some troubleshooting aspects of the MySQL Cluster.We also have a look at achieving high availability for MySQL databases with the techniques of MySQL Replication, block level replication, shared storage (a SAN or NAS), and DRBD.Finally, you will learn the principles of Performance tuning and tune MySQL database for optimal performance.
Table of Contents (17 chapters)
High Availability MySQL Cookbook
Credits
About the Author
About the Reviewers
Preface
Base Installation
Index

Installing and starting SQL nodes


SQL nodes are the most common form of API nodes, and are used to provide a standard MySQL interface to the cluster. To do this, they use a standard version of the MySQL server compiled to include support for the MySQL Cluster storage engine—NDBCLUSTER.

In earlier versions, this was included in most binaries, but to use more current and future versions of MySQL, you must specifically select the MySQL Cluster server downloads. It is highly recommended to install a mysql client on each SQL node for testing.

Note

Terminology sometimes causes confusion. A MySQL server is a mysqld process. A MySQL client is the mysql command that communicates with a MySQL server. It is recommended to install both on each SQL node, but of course, it is only required to have the server (which can be connected to by the clients on the other machines).

How to do it…

Download and install the following two files. For the sake of brevity, the process of using wget to download a file and rpm to install a package is not shown in this recipe, but it is identical to the procedure in the previous two recipes:

  • Server (from the cluster section)—MySQL-Cluster-gpl-server-7.a.b-c.rhel5.x86_64.rpm

  • Client (this is identical to the standard MySQL client and has the same filename)—MySQL-client-community-5.a.b-c.rhel5.x86_64.rpm

After installing these RPMs, a very simple /etc/my.cnf file will exist. We need to add two parameters to the [mysqld] section of this file to tell the mysqld server to enable support for MySQL Cluster and where to find its management node:

[mysqld]
# Enable MySQL Cluster
ndbcluster
# Tell this node where to find its management node 
ndb-connectstring=10.0.0.5

Note

The requirement to add lines to the [mysqld] section in addition to any [mysql_cluster] that may already be there is only read by the ndb_* daemons (but has a similar purpose). If you have a SQL node on the same server as a storage node you would have both.

Some modern versions of MySQL will also use a [mysql_cluster] section, but it is feasible to stick to defining the parameters in a [mysqld] section.

With these lines added, start the SQL node as follows:

[root@node1 ~]# service mysql start
Starting MySQL.                                            [  OK  ]

At this point, even if there is an error connecting to the cluster, it is unlikely that you will get anything other than okay here. However, if you see the following error in the standard mysql log (often /var/lib/mysqld.log or /var/lib/mysql/hostname.err), you should go and check that you have installed the correct server (the cluster server and not the standard server):

090708 23:48:14 [ERROR] /usr/sbin/mysqld: unknown option '--ndbcluster'
090708 23:48:14 [ERROR] Aborting

Even if your SQL node (MySQL server) starts without an error, it is important to verify that it has successfully joined the cluster. There are three tests to carry out:

On the management node, run the SHOW command and ensure that this node is now connected:

ndb_mgm> SHOW
Cluster Configuration
---------------------
[ndbd(NDB)]  4 node(s)
id=3  @10.0.0.1  (mysql-5.1.34 ndb-7.0.6, Nodegroup: 0, Master)
id=4  @10.0.0.2  (mysql-5.1.34 ndb-7.0.6, Nodegroup: 0)
id=5  @10.0.0.3  (mysql-5.1.34 ndb-7.0.6, Nodegroup: 1)
id=6  @10.0.0.4  (mysql-5.1.34 ndb-7.0.6, Nodegroup: 1)

[ndb_mgmd(MGM)]  1 node(s)
id=1  @10.0.0.5  (mysql-5.1.34 ndb-7.0.6)

[mysqld(API)]	4 node(s)
id=11  @10.0.0.1  (mysql-5.1.34 ndb-7.0.6)
id=12  @10.0.0.2  (mysql-5.1.34 ndb-7.0.6)
id=13  @10.0.0.3  (mysql-5.1.34 ndb-7.0.6)
id=14  @10.0.0.4  (mysql-5.1.34 ndb-7.0.6)

Now that you have confirmed that the SQL node is connected to the management node, in the mysql client on the SQL node confirm the status of the NDB engine:

[root@node1 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.34-ndb-7.0.6-cluster-gpl MySQL Cluster Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW ENGINE NDB STATUS;
+------------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Type       | Name                  | Status                                                                                                                                                       |
+------------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ndbcluster | connection            | cluster_node_id=11, connected_host=10.0.0.5, connected_port=1186, number_of_data_nodes=4, number_of_ready_data_nodes=4, connect_count=0                      | 

Also check the output of the SHOW ENGINES command:

mysql> SHOW ENGINES;
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                        | Transactions | XA   | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ndbcluster | YES     | Clustered, fault-tolerant tables                               | YES          | NO   | NO         | 

If the node is not connected, the status from the first command, SHOW ENGINE NDB STATUS, will typically be something like:

cluster_node_id=0, connected_host=(null), connected_port=0, number_of_data_nodes=0, number_of_ready_data_nodes=0, connect_count=0

Otherwise, the command will fail with ERROR 1286 (42000): Unknown table engine 'NDB'. If the second command does not have a YES in the supported column for ndbcluster there is a problem.

If any of these commands fail, check the following:

  • /etc/my.cnf [mysqld] section

  • That you have installed the cluster-specific mysqld binary

If the commands work, follow the steps in the next recipe to create a test MySQL Cluster table and ensure that your cluster is working correctly.