管理节点:192.168.10.243
Data节点1:192.168.10.244
Data节点2:192.168.10.245
SQL节点1:192.168.30.244
SQL节点2:192.168.30.245
下载cmake
https://cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
下载mysql cluster
到网页http://dev.mysql.com/downloads/cluster下下载mysql-cluster-gpl-7.4.8.tar.gz
安装cmake
#tar zxvf mysql-cluster-gpl-7.4.8.tar.gz -C /usr/local/cmake-2.8.12.2
#cd /usr/local/cmake-2.8.12.2
#./configure
#make && make install
安装MySQL cluster
解压即按照步骤与安装MySQL Server几乎完全相同,操作步骤如下:
#tar xvfz mysql-cluster-gpl-7.3.3.tar.gz
#cd mysql-cluster-gpl-7.3.3
#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_NDB_JAVA=OFF \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_NDBCLUSTER_STORAGE_ENGINE=1 \
-DCOMPILATION_COMMENT='MysqlCluster' \
-DWITH_READLINE=ON \
-DSYSCONFDIR=/data01 \
-DMYSQL_UNIX_ADDR=/data01/mysql.sock
#make&&make install
创建数据库
#chown mysql:mysql /usr/local/mysql -R
#chown mysql:mysql /data01 -R
#cd /usr/local/mysql/scripts/
#chmod +x mysql_install_db
#./mysql_install_db --basedir=/usr/local/mysql --datadir=/data01
管理节点添加控制文件
$vim /data/config.ini
[root@localhost scripts]# cat /data01/config.ini
[ndbd default]
NoOfReplicas=2
DataMemory=200M
IndexMemory=30M
[ndb_mgmd]
nodeid=1
hostname=192.168.10.243
[ndbd]
nodeid=2
hostname=192.168.10.244
datadir=/data01
[ndbd]
nodeid=3
hostname=192.168.10.245
datadir=/data01
[mysqld]
nodeid=4
hostname=192.168.10.244
[mysqld]
nodeid=5
hostname=192.168.10.245
244、245点:
#vim /data01/my.cnf
[root@localhost data01]# cat /data01/my.cnf
[mysqld]
datadir=/data01
socket=/data01/mysql.sock
user=mysql
symbolic-links=0
ndbcluster
ndb-connectstring=192.168.10.243
[MYSQL_CLUSTER]
ndb-connectstring=192.168.10.243
[mysqld_safe]
log-error=/data01/mysqld.log
pid-file=/data01/mysqld.pid
配置工作至此全部完成。然后可以启动MySQL Cluster了,启动Cluster中各节点的顺序正是前面配置节点的顺序:
#ndb_mgmd -f /data/mysql-cluster/config.ini
执行ndb_mgm管理命令:
ndb_mgm>show
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]2 node(s)
id=2 (not connected, accepting connect from 192.168.10.244)
id=3 (not connected, accepting connect from 192.168.10.245)
[ndb_mgmd(MGM)]1 node(s)
id=1@192.168.10.243 (mysql-5.6.27 ndb-7.4.8)
[mysqld(API)]2 node(s)
id=4 (not connected, accepting connect from 192.168.10.244)
id=5 (not connected, accepting connect from 192.168.10.245)
切换到244、245节点服务器,加--initial初始化Data节点并启动Data节点:
#ndbd --defaults-file=/data01/my.cnf --initial
注:下次启动只用执行ndbd --defaults-file=/data01/my.cnf
244,245节点启动:
#mysqld_safe --defaults-file=/data/my.cnf &
然后再回过头来查看节点
ndb_mgm>show
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]2 node(s)
id=2@192.168.10.244 (mysql-5.6.27 ndb-7.4.8, Nodegroup: 0, *)
id=3@192.168.10.245 (mysql-5.6.27 ndb-7.4.8, Nodegroup: 0)
[ndb_mgmd(MGM)]1 node(s)
id=1@192.168.10.243 (mysql-5.6.27 ndb-7.4.8)
[mysqld(API)]2 node(s)
id=4@192.168.10.244 (mysql-5.6.27 ndb-7.4.8)
id=5@192.168.10.245 (mysql-5.6.27 ndb-7.4.8)
测试:
在244节点创建数据库、表,并向表中插入一条数据。
mysql> create database dd;
Query OK, 1 row affected (0.13 sec)
mysql> use dd
Database changed
mysql> create table abc(id int) engine=ndbcluster;
Query OK, 0 rows affected (0.32 sec)
mysql> use dd
Database changed
mysql> show tables;
+--------------+
| Tables_in_dd |
+--------------+
| abc |
+--------------+
1 row in set (0.00 sec)
mysql> insert into abc values(1);
Query OK, 1 row affected (0.07 sec)
mysql> commit;
在245中查询在244中创建的表是否存在。
Query OK, 0 rows affected (0.00 sec)
mysql> select * from abc;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.04 sec)