This article uses Debian Sarge Linux systems for each of our nodes. Other Linux distributions may be installed a little bit
Difference. The version of MySQL we use 5.0.19. If you don't want to use MySQL 5, you can also use MySQL 4.1 to do
I haven't tested it yet.
This article is a practical application guide; it does not involve too many theories. On the theory of clustering you can find a lot on the Internet.
One server
I use the following Debian servers, all of which are on the same network segment (this example: 192.168.0.x):
SQL1.TEST.COM:192.168.0.101 MySQL cluster Node 1
sql2.test.com:192.168.0.102 MySQL cluster Node 2
loadb1.test.com:192.168.0.103 Load Balancing 1/mysql Cluster Management Server
loadb2.test.com:192.168.0.104 Load Balancing 2
In addition we need a virtual IP address: 192.168.0.105. It will arrange load balancing for this MySQL cluster so that
The application accesses the cluster by unifying a separate IP address.
Although we want to use two nodes in a MySQL cluster, we still need a third node, the MySQL cluster Management Server
, one of the main reasons is that if one of the MySQL cluster nodes is broken and the MySQL cluster Management Server is not running, that
Two the data on the cluster nodes will be inconsistent ("split brain"). We need it to configure the MySQL cluster.
As a result, our installation typically requires five machines:
2 MySQL cluster nodes + 1 cluster Management Servers + 2 Load Balancing = 5
Because the cluster Management Server does not use much resources, the system will be free to do nothing, so we can put our first
Load balancing with it on the same machine, so that we can save a server, so it is best we only need four units
Machine.
Two configuration MySQL Cluster Management Server
First we want to download the MySQL 5.0.19 and install the Cluster Management Server (NDB_MGMD) and cluster Management client (NDB_MGM-it
can be used to monitor the operation of the cluster). The following steps are performed on Loadb1.test.com (192.168.0.103):
The code is as follows |
Copy Code |
Loadb1.test.com: Mkdir/usr/src/mysql-mgm Cd/usr/src/mysql-mgm wget http://dev.mysql.com/get/downloads/mysql-5.0/mysql-max-5.0.19-linux-i686- glibc23.tar.gz/from/http://www.mirrorservice.org/sites/ftp.mysql.com/ Tar Xvfz mysql-max-5.0.19-linux-i686-glibc23.tar.gz CD mysql-max-5.0.19-linux-i686-glibc23 MV Bin/ndb_mgm/usr/bin MV Bin/ndb_mgmd/usr/bin chmod 755/usr/bin/ndb_mg* Cd/usr/src Rm-rf/usr/src/mysql-mgm |
Next, we must create the cluster's configuration file,/var/lib/mysql-cluster/config.ini:
code is as follows |
copy code |
loadb1.test.com: Mkdir/var/lib/mysql-cluster cd/var/lib/ Mysql-cluster VI config.ini ———- [ndbd DEFAULT] noofreplicas=2 [MYSQLD DEFAULT] [NDB_MGMD DEFAULT] [TCP DEFAULT] # section for the ' Cluster Management node [NDB_MGMD] # IP address of the management Node (this system) hostname=192.168.0.103 # section for the ' storage nodes [NDBD] # IP address of the Firs T storage node hostname=192.168.0.101 datadir=/var/lib/mysql-cluster [ndbd] # IP address of the second St Orage node hostname=192.168.0.102 Datadir=/var/lib/mysql-cluster # One [MYSQLD] per storage node [MYSQLD ] [MYSQLD] |
———-
In the actual application, please replace the IP address in the file with your corresponding IP.
Then we start the Cluster Management Server:
The code is as follows |
Copy Code |
Loadb1.test.com: Ndb_mgmd-f/var/lib/mysql-cluster/config.ini |
We should also be able to start the Management Server automatically when the server starts, so we created a very simple initialization
Script and the corresponding boot connection:
The code is as follows |
Copy Code |
Loadb1.test.com: Echo ' ndb_mgmd-f/var/lib/mysql-cluster/config.ini ' >/ETC/INIT.D/NDB_MGMD chmod 755/ETC/INIT.D/NDB_MGMD UPDATE-RC.D NDB_MGMD Defaults |