In this article, we will build a most simplified MySQL Cluster system. All the commands in the configuration method are run with the root account. This MySQL Cluster contains a management node, two data nodes, and two SQL nodes. These five nodes are installed on five virtual machines respectively. The virtual machine name and IP address are as follows:
Management Node |
Mysql-mgm |
192.168.124.141 |
Data Node 1 |
Mysql-ndbd-1 |
192.168.124.142 |
Data Node 2 |
Mysql-ndbd-2 |
192.168.124.143 |
SQL Node 1 |
Mysql-sql-1 |
192.168.124.144 |
SQL Node 2 |
Mysql-sql-2 |
192.168.124.145 |
I. Public Configuration
Configure the configuration items here on the three virtual machines.
1. Install virtual machines
Install CentOS 6.4 x86_64 in the virtual machine operating system, use the NAT network, and install vmware-tools. The installation method is not described here.
2. Copy mysql cluster
Download MySQL-Cluster of the following versions:
Http://cdn.mysql.com/Downloads/MySQL-Cluster-7.3/mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64.tar.gz
Copy the downloaded package to the/root/Downloads directory of the VM and run the following command in the shell:
Cd/root/Downloads
Tar-xvzf mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64.tar.gz
Music mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64/usr/local/mysql
3. disable security policies
Disable iptables firewall (or open ports 1186 and 3306 of the firewall) and run the following command in Shell:
Chkconfig -- level 35 iptables off
Close SELinux and run the following command in Shell:
Gedit/etc/selinux/config
Change the SELINUX item in the config file to disabled. The contents of the modified config file are as follows:
# This file controls the state of SELinux on the system.
# SELINUX = can take one of these three values:
# Enforcing-SELinux security policy is enforced.
# Permissive-SELinux prints warnings instead of enforcing.
# Disabled-No SELinux policy is loaded.
SELINUX = disabled
# SELINUXTYPE = can take one of these two values:
# Targeted-Targeted processes are protected,
# Mls-Multi Level Security protection.
SELINUXTYPE = targeted
Finally, restart the system.
Ii. Configuration Management node (192.168.124.141)
1. Configure the config. ini configuration file
Run the following command in shell:
Mkdir/var/lib/mysql-cluster
Cd/var/lib/mysql-cluster
Gedit config. ini
The configuration file config. ini contains the following content:
[Ndbd default]
NoOfReplicas = 2
DataMemory = 80 M
IndexMemory = 18 M
[Ndb_mgmd]
NodeId = 1
Hostname = 192.168.124.141
Datadir =/var/lib/mysql-cluster
[Ndbd]
NodeId = 2
Hostname = 192.168.124.142
Datadir =/usr/local/mysql/data
[Ndbd]
NodeId = 3
Hostname = 192.168.124.143
Datadir =/usr/local/mysql/data
[Mysqld]
NodeId = 4
Hostname = 192.168.124.144
[Mysqld]
NodeId = 5
Hostname = 192.168.124.145
2. Install the management Node
Install the management node without the mysqld binary file. You only need the MySQL Cluster server program (ndb_mgmd) and the listener Client Program (ndb_mgm ). Run the following command in shell:
Cp/usr/local/mysql/bin/ndb_mgm */usr/local/bin
Cd/usr/local/bin
Chmod + x ndb_mgm *
3. configure data nodes (192.168.124.142 and 192.168.124.143)
1. Add mysql groups and users
Run the following command in shell:
Groupadd mysql
Useradd-g mysql
2. Configure the my. cnf configuration file
Run the following command in shell:
Gedit/etc/my. cnf
The content of my. cnf configuration file is as follows:
[Mysqld]
Basedir =/usr/local/mysql
Datadir =/usr/local/mysql/data
Socket =/usr/local/mysql/sock/mysql. sock
User = mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
Symbolic-links = 0
[Mysqld_safe]
Log-error =/var/log/mysqld. log
Pid-file =/var/run/mysqld. pid
[Mysql_cluster]
Ndb-connectstring = 192.168.124.141
3. Create a system database
Run the following command in shell:
Cd/usr/local/mysql
Mkdir sock
Scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql/data
4. Set the data directory
Run the following command in shell:
Chown-R root.
Chown-R mysql. mysql/usr/local/mysql/data
Chown-R mysql. mysql/usr/local/mysql/sock
Chgrp-R mysql.
5. Configure the MySQL Service
Run the following command in shell:
Cp support-files/mysql. server/etc/rc. d/init. d/
Chmod + x/etc/rc. d/init. d/mysql. server
Chkconfig -- add mysql. server