转自:http://www.catharinegeek.com/set-up-mysql-cluster-on-ubuntu-14041/
Overview
Recently, I setup mysql cluster on 4 computers with Ubuntu 14.04.1.
Assume that these 4 computers have names from A to D, ips from 192.168.1.101 to 192.168.1.104.?
The basic structure is as below:
- Computer A is management node.
- Computer B and C are data nodes.
- Computer D is sql node.
Important:
Most the command used below should be perform using root. If you come across errors when running these commands, make a try using root instead.
?
Download Mysql Cluster
First of all, download mysql cluster 7.3.7 (64 bits) from?here, choose the 'linux generic' category.
?
Install Management Node
Install ndb_mgmd and ndb_mgm
After download finish, you will get the file 'mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz'. Perform following steps to install?ndb_mgmd?and?ndb_mgm:
- move to the folder of download file, and?extract the?ndb_mgm?and?ndb_mgmd?binaries?from the archive into?
/usr/local/bin
: ??tar -zxvf mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
cd mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64
cp bin/ndb_mgm* /usr/local/bin
- make?ndb_mgmd?and?ndb_mgm?executable:
cd /usr/local/bin
chmod +x ndb_mgm*
Configuring the management node
Create a directory for config file:
mkdir /var/lib/mysql-cluster
cd /var/lib/mysql-cluster
vim config.ini
The config.ini should be looked like this:
[ndbd default]# Options affecting ndbd processes on all data nodes:NoOfReplicas=2 # Number of replicasDataMemory=80M # How much memory to allocate for data storageIndexMemory=18M # How much memory to allocate for index storage # For DataMemory and IndexMemory, we have used the # default values. Since the "world" database takes up # only about 500KB, this should be more than enough for # this example Cluster setup.[tcp default]# TCP/IP options:portnumber=2202 # This the default; however, you can use any # port that is free for all the hosts in the cluster # Note: It is recommended that you do not specify the port # number at all and simply allow the default value to be used # instead[ndb_mgmd]# Management process options:hostname=192.168.0.101 # Hostname or IP address of MGM nodedatadir=/var/lib/mysql-cluster # Directory for MGM node log files[ndbd]# Options for data node "A": # (one [ndbd] section per data node)hostname=192.168.0.102 # Hostname or IP addressdatadir=/usr/local/mysql/data # Directory for this data node's data files[ndbd]# Options for data node "B":hostname=192.168.0.103 # Hostname or IP addressdatadir=/usr/local/mysql/data # Directory for this data node's data files[mysqld]# SQL node options:hostname=192.168.0.104 # Hostname or IP address # (additional mysqld connections can be # specified for this node for various # purposes such as running ndb_restore)
?
Install Data Node
Install ndbd and ndbmtd
- move to the folder of download file, and?extract the?ndbd?and?ndbmtd?from the archive into?
/usr/local/bin
: ??tar -zxvf mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
cd mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64
cp bin/ndbd /usr/local/bin
- make?ndbd?and?ndbmtdexecutable
cd /usr/local/bin
chmod +x ndb*
Note:
the data directory on each machine hosting a data node is?/usr/local/mysql/data
. This piece of information is essential when configuring the management node. You should make this directory if it does not exist.
Configuring data node
my.cnf?file is needed for each data node, put it in?/etc
?.
vim /etc/my.cnf
my.cnf should be looked like this:
[mysqld]# Options for mysqld process:ndbcluster # run NDB storage engine[mysql_cluster]# Options for MySQL Cluster processes:#原文中节点为192.168.0.102,此处需要配置管理节点ndb-connectstring=192.168.0.101 # location of management server
?
Install Sql Node
Install mysql server
- Check ?
/etc/passwd
?and?/etc/group
?files to see whether there is already a?mysql
?group and?mysql
?user on the system.?If not, create a new?mysql
?user group, and then add a?mysql
?user to this group:groupadd mysql
useradd -g mysql mysql - Unpack the archive, and create a symbolic link named?
mysql
?to the?mysql
?directory.tar -C /usr/local mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
ln -s /usr/local/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64 /usr/local/mysql
- Change location to the?
mysql
?directory and run the supplied script for creating the system databases:cd /usr/local/mysql
scripts/mysql_install_db --user=mysql
- Set the necessary permissions for the MySQL server and data directories:
chown -R root .
chown -R mysql data
chgrp -R mysql .
- Copy the MySQL startup script to the appropriate directory, make it executable, and set it to start when the operating system is booted up:
cp support-files/mysql.server /etc/init.d
chmod +x /etc/init.d/mysql.server
update-rc.d mysql.server defaults
Configuring sql node
This configue file for sql node is the same as data node, just follow the configuration of data node.
?
Start Mysql Cluster
Once configuration has been set properly, the start up process should be easy. Note that the management node should be started first, followed by data nodes, and finally sql nodes.
?
For management node:
/usr/local/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
For each data node:
/usr/local/bin/ndbd
For each sql node:
/etc/init.d/mysql.server start
?
That's all. Once you finish all the process, you can use the?ndb_mgm?management client to see whether your cluster is running correctly. If everything goes well, you should see something like below:
shell>/usr/local/bin/ndb_mgm
-- NDB Cluster -- Management Client --ndb_mgm>SHOW
Connected to Management Server at: localhost:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 @192.168.0.30 (Version: 5.5.41-ndb-7.2.19, Nodegroup: 0, *)id=3 @192.168.0.40 (Version: 5.5.41-ndb-7.2.19, Nodegroup: 0)[ndb_mgmd(MGM)] 1 node(s)id=1 @192.168.0.10 (Version: 5.5.41-ndb-7.2.19)[mysqld(API)] 1 node(s)id=4 @192.168.0.20 (Version: 5.5.41-ndb-7.2.19)