参考:
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-install-configuration.html
一、前期准备
cp mysql-cluster-gpl-7.2.12-linux2.6-x86_64.tar.gz /usr/local/
tar xvf mysql-cluster-gpl-7.2.12-linux2.6-x86_64.tar.gz
mv mysql-cluster-gpl-7.2.12-linux2.6-x86_64 mysql
更改环境变量 进入家目录 # vi ~/.bash_profile 将/usr/local/mysql/bin 添加进去
source ~/.bash_profile
建立mysql的用户账户: #groupadd mysql #useradd -g mysql mysql (-g参数可以不要)
二、配置
(一)、配置data节点和SQL节点
Configuring the data nodes and SQL nodes. The my.cnf
file needed for the data nodes is fairly simple. The configuration file should be located in the /etc
directory and can be edited using any text editor. (Create the file if it does not exist.) For example:
shell> vi /etc/my.cnf
We show vi being used here to create the file, but any text editor should work just as well.
For each data node and SQL node in our example setup, my.cnf
should look like this:
[mysqld]# Options for mysqld process:ndbcluster # run NDB storage engine[mysql_cluster]# Options for MySQL Cluster processes:ndb-connectstring=192.168.0.10 # location of management server
After entering the preceding information, save this file and exit the text editor. Do this for the machines hosting data node “A”, data node “B”, and the SQL node.
Once you have started a mysqld process with the ndbcluster
and ndb-connectstring
parameters in the[mysqld]
and [mysql_cluster]
sections of the my.cnf
file as shown previously, you cannot execute anyCREATE TABLE
or ALTER TABLE
statements without having actually started the cluster. Otherwise, these statements will fail with an error. This is by design.
(二)、配置管理节点
Configuring the management node. The first step in configuring the management node is to create the directory in which the configuration file can be found and then to create the file itself. For example (running asroot
):
shell> mkdir /var/lib/mysql-cluster
shell> cd /var/lib/mysql-cluster
shell> vi config.ini
For our representative setup, the config.ini
file should read as follows:
[ndbd default]# Options affecting ndbd processes on all data nodes:NoOfReplicas=2 # Number of replicas(副本个数)DataMemory=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.10 # 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.30 # 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.40 # Hostname or IP addressdatadir=/usr/local/mysql/data # Directory for this data node's data files[mysqld]# SQL node options:hostname=192.168.0.20 # Hostname or IP address # (additional mysqld connections can be # specified for this node for various# purposes such as running ndb_restore)
The world
database can be downloaded from http://dev.mysql.com/doc/, where it can be found listed under“Examples”.
三、启动
(一)、初始化时候的启动:
(1)、管理节点启动
ndb_mgmd -f /var/lib/mysql-cluster/config.ini
(2)、数据节点启动
ndbd --initial(第一次启动时使用,之后可以不使用此参数)
(3)、SQL节点启动
mkdir /usr/local/mysql/scripts/bin
cp /usr/local/mysql/bin/my_print_defaults /usr/local/mysql/scripts/bin
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/home/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start
(二)、正常启动和关闭
(1)、启动
To restart the cluster on Unix platforms, run these commands:
On the management host (
192.168.0.10
in our example setup):shell>
ndb_mgmd -f /var/lib/mysql-cluster/config.ini
On each of the data node hosts (
192.168.0.30
and192.168.0.40
):shell>
ndbd
Use the ndb_mgm client to verify that both data nodes have started successfully.
On the SQL host (
192.168.0.20
):shell>
mysqld_safe &
(2)、关闭
ndb_mgm -e shutdown
启动顺序:管理节点——data节点——sql节点,关闭正好相反
四、安装结束的验证
shell> 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.31-ndb-7.2.14, Nodegroup: 0, Master)id=3 @192.168.0.40 (Version: 5.5.31-ndb-7.2.14, Nodegroup: 0)[ndb_mgmd(MGM)] 1 node(s)id=1 @192.168.0.10 (Version: 5.5.31-ndb-7.2.14)[mysqld(API)] 1 node(s)id=4 @192.168.0.20 (Version: 5.5.31-ndb-7.2.14)