MySQL cluster configuration practices: Dual-Server Protection against system crashes

Source: Internet
Author: User
Tags node server
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 theoretically a MySQL cluster can be created based on only two servers

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 theoretically a MySQL cluster can be created based on only two servers

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 [url] [/url.pdf note: mySQL must be 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!

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 [url] [/url.pdf

# 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]
After the IP address of ndb-connectstring = 192.168.0.3 # Server3 is saved and exited, 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 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

================== Go Back To The management node server Server3 and start the Management Terminal:

#/Usr/bin/ndb_mgm type 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 above, test MySQL now: note that this document does not set the root password for MySQL. We recommend that you set the root password for MySQL in Server 1 and Server 2. In Server1:

#/Usr/local/mysql/bin/mysql-u root-p
> Use test;
> CREATETABLE ctest (I INT) ENGINE = NDBCLUSTER;
> INSERTINTO 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 works 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 will see all ndbd process information:

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 and then kill an ndbd process to destroy the MySQL Cluster Server:

# Run the SELECT query test on another cluster server after kill-9 5578 5579. 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!

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.