How to install MySQL in a MySQL cluster on Server 1 and Server 2

Source: Internet
Author: User
Tags node server

Today, we will mainly introduce MySQL clusters, including introduction to the concept of MySQL clusters and how to correctly install MySQL on Server 1 and Server 2, configure the Cluster Server and start MySQL.

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

Slave

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

 
 
  1. # mv MySQL-max-4.1.9-pc-linux-gnu-i686.tar.gz /usr/local/   
  2. # cd /usr/local/   
  3. # groupadd MySQL   
  4. # useradd -g MySQL MySQL   
  5. # tar -zxvf MySQL-max-4.1.9-pc-linux-gnu-i686.tar.gz   
  6. # rm -f MySQL-max-4.1.9-pc-linux-gnu-i686.tar.gz   
  7. # mv MySQL-max-4.1.9-pc-linux-gnu-i686 MySQL   
  8. # cd MySQL   
  9. # scripts/MySQL_install_db --user=MySQL   
  10. # chown -R root .   
  11. # chown -R MySQL data   
  12. # chgrp -R MySQL .   
  13. # cp support-files/MySQL.server /etc/rc.d/init.d/MySQLd   
  14. # chmod x /etc/rc.d/init.d/MySQLd   
  15. # 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:

 
 
  1. # mkdir /usr/src/MySQL-mgm   
  2. # cd /usr/src/MySQL-mgm   
  3. # tar -zxvf MySQL-max-4.1.9-pc-linux-gnu-i686.tar.gz   
  4. # rm MySQL-max-4.1.9-pc-linux-gnu-i686.tar.gz   
  5. # cd MySQL-max-4.1.9-pc-linux-gnu-i686   
  6. # mv bin/ndb_mgm .   
  7. # mv bin/ndb_mgmd .   
  8. # chmod x ndb_mg*   
  9. # mv ndb_mg* /usr/bin/   
  10. # cd   
  11. # rm -rf /usr/src/MySQL-mgm  

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

 
 
  1. # mkdir /var/lib/MySQL-cluster   
  2. # cd /var/lib/MySQL-cluster   
  3. # vi config.ini  

Add the following content to config. ini:

 
 
  1. [NDBD DEFAULT]   
  2. NoOfReplicas=2   
  3. [MySQLD DEFAULT]   
  4. [NDB_MGMD DEFAULT]   
  5. [TCP DEFAULT]   
  6. # Managment Server   
  7. [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:

 
 
  1. # mkdir /var/lib/MySQL-cluster   
  2. # cd /var/lib/MySQL-cluster   
  3. # /usr/local/MySQL/bin/ndbd --initial   
  4. # /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!

The above content is an introduction to some of the content of the MySQL cluster. I hope you will have some gains.

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.