#/Bin/bash
# MySQL Cluster configuration Scheme
# Purpose host name IP
# Management node ndb_mgmd 192.168.40.129
# Data node 1 ndb1 192.168.40.131
# Data node 2 ndb2 192.168.40.132
# SQL Node 1 mysqld1 192.168.40.131
# SQL Node 2 mysqld2 192.168.40.132
# Recommended mysql-max-5.0.24 for required software
# Start Installation
# SQL and data node Installation
# Mysql users are used to run the Cluster on each node computer. Therefore, run the following command to add related users:
Groupadd mysql
Useradd-g mysql
# Install the mysql binary installation package on SQL and data nodes
Wget http://downloads.skysql.com/archives/mysql-5.0/mysql-max-5.0.24-linux-i686.tar.gz
Tar-zxf mysql-max-5.0.24-linux-i686.tar.gz
Music mysql-max-5.0.24-linux-i686/usr/local/mysql
# Copy the MySQL configuration file to/etc/, initialize the database, Set directory permissions, and start MySQL
Cd/usr/local/mysql
\ Cp-rf support-files/my-medium.cnf/etc/my. cnf
Scripts/mysql_install_db -- user = mysql
Chown-R mysql. mysql/usr/local/mysql
Bin/MySQLd_safe -- user = mysql &
# Write MySQL to the service and initialize the MySQL root Password
Cp support-files/mysql. server/etc/rc. d/init. d/mysqld
Chkconfig -- add mysqld
Bin/mysqladmin-u root password 123123
Vi/etc/my. cnf add content at the bottom:
[Mysqld]
Ndbcluster
Ndb-connectstring = 192.168.40.129
[Mysql_cluster]
Ndb-connectstring = 192.168.40.129
# Management node Installation
Tar-zxvf mysql-max-5.0.24-linux-i686.tar.gz
Mkdir/usr/local/mysql
Mkdir/usr/local/mysql/data
Cd mysql-max-5.0.24-linux-i686/bin
Cp ndb_mgm */usr/local/mysql
Chown-R mysql. mysql/usr/local/mysql
# Configuration Management Node
Vim/usr/local/mysql/config. ini
[Ndbd default]
NoOfReplicas = 2
DataMemory = 200 M
IndexMemory = 100 M
[Tcp default]
Portnumber = 4444 # This port is used by the Data Node
[Ndb_mgmd]
# Set Management server
Hostname = 192.168.40.129
# Management save log directory
Datadir =/usr/local/mysql/data/
# Set Storage server
[Ndbd]
Hostname = 192.168.40.131
Datadir =/usr/local/mysql/data/
[Ndbd]
Hostname = 192.168.40.132
Datadir =/usr/local/mysql/data/
# Set SQL server
[Mysqld]
Hostname = 192.168.40.131
[Mysqld]
Hostname = 192.168.40.132
# Start mysql cluster
# The proper sequence of startup is to first start the management node server, then start the storage node server, and finally start the SQL node Server:
# On the Management node server, run the following command to start the MGM node process:
/Usr/local/mysql/ndb_mgmd-f/usr/local/mysql/config. ini
# The "-f" or "-- config-file" parameter must be used to tell the location of the ndb_mgm configuration file, which is in the same directory as ndb_mgmd by default.
# On each storage node server, if the ndbd process is started for the first time, you must first execute the following command:
/Usr/local/mysql/bin/ndbd -- initial
# Note: The "-- initial" parameter should be used only when ndbd is started for the first time, or when data is backed up/restored or ndbd is restarted after the configuration file changes. This parameter causes the node to delete any files created by an earlier ndbd instance for restoration, including log files for restoration.
# If it is not the first time, run the following command:
/Usr/local/mysql/bin/ndbd
# Finally, run the following command to start the SQL node Server:
/Usr/local/mysql/bin/mysqld_safe -- defaults-file =/etc/my. cnf &
# If everything goes well, that is, there is no error message during startup, run the following command on the Management node Server:
[Root @ localhost mysql] #/usr/local/mysql/ndb_mgm
-- NDB Cluster -- Management Client --
Ndb_mgm> show
Connected to Management Server at: localhost: 1186
Cluster Configuration
---------------------
[Ndbd (NDB)] 2 node (s)
Id = 2 @ 192.168.40.131 (Version: 5.0.24, Nodegroup: 0)
Id = 3 @ 192.168.40.132 (Version: 5.0.24, Nodegroup: 0, Master)
[Ndb_mgmd (MGM)] 1 node (s)
Id = 1 @ 192.168.40.129 (Version: 5.0.24)
[Mysqld (API)] 2 node (s)
Id = 4 @ 192.168.40.131 (Version: 5.0.24)
Id = 5 @ 192.168.40.132 (Version: 5.0.24)
# Test
# On the mysqld1 node, use root to create a new table t1 in the test Database
Mysql> use test;
Database changed
Mysql> show tables;
Empty set (0.11 sec)
Mysql> create table t1 (a int) engine = ndb;
Query OK, 0 rows affected (0.74 sec)
Mysql> insert into t1 values (100 );
Query OK, 1 row affected (0.32 sec)
# On mysqld2 Node 2, Use root to view the effect
Mysql> show tables;
+ ---------------- +
| Tables_in_test |
+ ---------------- +
| T1 |
+ ---------------- +
1 row in set (0.00 sec)