MySQL double-click Server Load balancer configuration process

Source: Internet
Author: User
Tags node server

 

I. Introduction
==========
This document describes how to install and configure a MySQL cluster based on two servers. MySQL can continue to run when any server encounters a problem or goes down.

Note!
Although this is a MySQL cluster based on two servers, there must be an additional third server as the management node, but this server can be closed after the cluster is started. At the same time, it is not recommended to disable the server as the management node after the cluster is started. Although a MySQL cluster with only two servers can be established theoretically, the cluster cannot continue to work normally once one server goes down, in this way, the meaning of the cluster is lost. For this reason, a third server is required to run as a management node.

In addition, many friends may not have the actual environment of three servers. You can consider conducting experiments in VMWare or other virtual machines.

The following describes the three services:

Server1: mysql1.vmtest.net 192.168.0.1
Server2: mysql2.vmtest.net 192.168.0.2
Server3: mysql3.vmtest.net 192.168.0.3

Servers1 and Server2 serve as servers for configuring the MySQL cluster. Server3, as a management node, has low requirements. You only need to make minor adjustments to the Server3 system and do not need to install MySQL, server3 can use a low-configuration computer and run other services on server3.

2. Install MySQL on Server 1 and Server 2
======================================
Download mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz from http://www.mysql.com
Note: It must be MySQL of max version. Standard version does not support cluster deployment!

Perform the following steps on Server 1 and Server 2
# Music mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz/usr/local/
# Cd/usr/local/
# Groupadd mysql
# Useradd-g mysql
# Tar-zxvf mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz
# Rm-f mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz
# Music mysql-max-4.1.9-pc-linux-gnu-i686 mysql
# Cd mysql
# Scripts/mysql_install_db -- user = mysql
# Chown-R root.
# Chown-R mysql data
# Chgrp-R mysql.
# Cp support-files/mysql. server/etc/rc. d/init. d/mysqld
# Chmod + x/etc/rc. d/init. d/mysqld
# Chkconfig -- add mysqld

Do not start MySQL at this time!

3. install and configure the management node server (Server3)
============================================
As a management node server, Server3 requires two files: ndb_mgm and ndb_mgmd:

Download mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz from http://www.mysql.com

# Mkdir/usr/src/MySQL-MGM
# Cd/usr/src/MySQL-MGM
# Tar-zxvf mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz
# Rm mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz
# Cd mysql-max-4.1.9-pc-linux-gnu-i686
# Mv bin/ndb_mgm.
# Mv bin/ndb_mgmd.
# Chmod + x ndb_mg *
# Mv ndb_mg */usr/bin/
# Cd
# Rm-RF/usr/src/MySQL-MGM

Now, create a configuration file for this management node Server:

# Mkdir/var/lib/MySQL-Cluster
# Cd/var/lib/MySQL-Cluster
# Vi config. ini

Add the following content to config. ini:

[Ndbd default]
Noofreplicas = 2
[Mysqld default]
[Ndb_mgmd default]
[TCP default]
# Managment Server
[Ndb_mgmd]
Hostname = 192.168.0.3 # manage the IP address of node server server3
# Storage engines
[Ndbd]
Hostname = 192.168.0.1 # IP address of MySQL cluster server1
Datadir =/var/lib/MySQL-Cluster
[Ndbd]
Hostname = 192.168.0.2 # IP address of MySQL cluster server2
Datadir =/var/lib/MySQL-Cluster
# The following two [mysqld] hostnames can be set to server1 and server2.
# However, to replace the servers in the cluster more quickly, we recommend that you leave it blank. Otherwise, you must change the configuration after changing the server.
[Mysqld]
[Mysqld]

After saving and exiting, start the management node server server3:
# Ndb_mgmd

After starting a management node, you should note that this is only a management node service, not a management terminal. Therefore, you cannot see any output information after startup.

4. Configure the Cluster Server and start MySQL
==================================
The following changes must be made in both server1 and server2:

# Vi/etc/My. CNF

[Mysqld]
Ndbcluster
NDB-connectstring = 192.168.0.3 # server3 IP Address
[Mysql_cluster]
NDB-connectstring = 192.168.0.3 # server3 IP Address

After saving and exiting, create a data directory And start MYSQL:

# Mkdir/var/lib/MySQL-Cluster
# Cd/var/lib/MySQL-Cluster
#/Usr/local/MySQL/bin/ndbd -- Initial
#/Etc/rc. d/init. d/mysqld start

You can add/usr/local/MySQL/bin/ndbd to/etc/rc. Local to enable startup.
Note: you must use the -- Initial Parameter only when you start ndbd for the first time or modify config. ini of server3!

5. Check the working status
======================
Return to Server 3 of the Management node and start the Management Terminal:

#/Usr/bin/ndb_mgm
Enter the show command to view the current working status: (The following is an example of status output)

[Root @ mysql3 root] #/usr/bin/ndb_mgm
-- NDB Cluster -- management client --
Ndb_mgm> show
Connected to management server at: localhost: 1186
Cluster configuration
---------------------
[Ndbd (NDB)] 2 node (s)
Id = 2 @ 192.168.0.1 (Version: 4.1.9, Nodegroup: 0, Master)
Id = 3 @ 192.168.0.2 (Version: 4.1.9, Nodegroup: 0)

[Ndb_mgmd (MGM)] 1 node (s)
Id = 1 @ 192.168.0.3 (Version: 4.1.9)

[Mysqld (API)] 2 node (s)
Id = 4 (Version: 4.1.9)
Id = 5 (Version: 4.1.9)

Ndb_mgm>

If there is no problem, test MySQL now:
Note: This document does not set the root password for MySQL. We recommend that you set the root password for MySQL of Server1 and server2.

In Server1:

#/Usr/local/mysql/bin/mysql-u root-p
> Use test;
> Create table ctest (I INT) ENGINE = NDBCLUSTER;
> Insert into ctest () VALUES (1 );
> SELECT * FROM ctest;

We can see 1 row returned information (return value 1 ).

If the above is normal, switch to Server2 and repeat the above test to observe the effect. If the operation succeeds, execute INSERT in Server2 and return to Server1 to check whether the operation is normal.
If no problem exists, congratulations!

Vi. Destructive Testing
====================
Unplug the network cable of Server 1 or server 2 and check whether the server in the other cluster is working properly (you can use the SELECT query test ). After testing, re-insert the network cable.

If you do not have access to the physical server, that is, you cannot unplug the network cable. You can also test it as follows:
On Server1 or Server2:

# Ps aux | grep ndbd
All ndbd processes are displayed:

Root 5578 0.0 0.3 6220 1964? S ndbd
Root 5579 0.0 20.4 492072 102828? R ndbd
Root 23532 0.0 0.1 3680 684 pts/1 S grep ndbd

Then, kill an ndbd process to destroy the MySQL Cluster Server:

# Kill-9 5578 5579

Then use the SELECT query test on another cluster server. In addition, execute the show command on the management terminal of the Management node server to view the State of the damaged server.
After the test is complete, you only need to restart the ndbd process of the damaged server:

# Ndbd
Note! As mentioned above, the -- inparameters parameter is not required!

Now, the MySQL cluster configuration is complete!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.