首页 > 代码库 > Build MySQL Cluster Environment

Build MySQL Cluster Environment

This post documents how build MySQL cluster environment with 4 machines. Their IP addresses and roles are listed below.

  • Host #1: 192.168.1.100, management node
  • Host #2: 192.168.1.101, SQL node
  • Host #3: 192.168.1.102, data node #1
  • Host #4: 192.168.1.103, data node #2 

 

Download MySQL Cluster on each host

wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.3/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gztar zxvf mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gzcd mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/

 

Setup the cluster

On Management Node, run the following commands to copy ndb_mgm and ndb_mgmd to /usr/local/bin/.

cp bin/ndb_mgm /usr/local/bin/cp bin/ndb_mgmd /usr/local/bin/

On Data Node, run the following commands to copy ndbd and ndbmtd to /usr/local/bin/.

cp bin/ndbd /usr/local/bin/cp bin/ndbmtd /usr/local/bin/

On SQL Node

Check if the library libaio1 installed on the host, if not, execute the following command to install the library.

apt-get install libaio1

If the library can‘t be installed by running apt-get, you can download this package first, and then install it with dpkg -i like below.

wget http://archive.ubuntu.com/ubuntu/pool/main/liba/libaio/libaio1_0.3.109-4_amd64.debdpkg -i libaio1_0.3.109-4_amd64.deb

Run the following commands to install MySQL.

#groupadd mysqluseradd -g mysql mysql #tar zxvf mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ln -s /usr/local/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64 /usr/local/mysql#cd /usr/loca/mysqlscripts/mysql_install_db --user=mysql#chown -R root .chown -R mysql datachgrp -R mysql . #cp support-files/mysql.server /etc/init.d/update-rc.d mysql.server defaults

 

Configure the Cluster

On the SQL and data nodes, type the following lines in /etc/my.cnf.

[mysqld]ndbcluster[mysql_cluster]ndb-connectstring=1092.168.1.100

On the management node, type the following lines in /etc/mysql/config.ini.

[ndbd default]NoOfReplicas=2    # Number of replicasDataMemory=80M    # How much memory to allocate for data storageIndexMemory=18M   # How much memory to allocate for index storage                 [tcp default]# TCP/IP options:portnumber=2202                 [ndb_mgmd]# Management process options:hostname=192.168.1.100datadir=/var/lib/mysql-cluster  # Directory for MGM node log files[ndbd]# Options for data node #1:                                hostname=192.168.1.102datadir=/usr/local/mysql/data   # Directory for this data nodes data files[ndbd]# Options for data node #2:hostname=192.168.1.103datadir=/usr/local/mysql/data   # Directory for this data nodes data files[mysqld]# SQL node #1:hostname=192.168.1.101

 

Start the cluster

Start the management node first.

ndb_mgmd -f /var/lib/mysql-cluster/config.ini

Start the data nodes.

ndbd

Start the SQL node.

service mysql.server start

On the management node, run the following command to see if the cluster goes well.

ndb_mgmndb_mgm> show

On the SQL node, set password for root.

mysqladmin -u root password your password

Finally, try to create a database to test.

 

Build MySQL Cluster Environment