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. 1. This document describes how to install and configure
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. 1. This document describes how to install and configure
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
- # mv MySQL-max-4.1.9-pc-linux-gnu-i686.tar.gz /usr/local/
- # cd /usr/local/
- # groupadd MySQL
- # useradd -g MySQL 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
- # mv 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:
- # 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!
The above content is an introduction to some of the content of the MySQL cluster. I hope you will have some gains.