准备工作:
下载二进制mysql_cluster集群 http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.9-linux-glibc2.5-x86_64.tar.gz
安装:
======================== SQL nodes.(SQL节点) ======================== 1、创建Mysql用户组 shell> groupadd mysql shell> useradd -g mysql -s /bin/false mysql
2、解压mysql_cluster源文件,如:
shell> cd /var/tmp shell> tar -C /usr/local -xzvf mysql-cluster-gpl-7.4.9-linux2.6.tar.gz shell> ln -s /usr/local/mysql-cluster-gpl-7.4.9-linux2.6-i686 /usr/local/mysql
3、安装系统数据库 shell> cd mysql shell> scripts/mysql_install_db –user=mysql
4、设置mysql服务权限组为mysql, data权限mysql:mysql
shell> chown -R root . shell> chown -R mysql data shell> chgrp -R mysql .
5、复制启动脚本,设置为可执行
shell> cp support-files/mysql.server /etc/rc.d/init.d/ shell> chmod +x /etc/rc.d/init.d/mysql.server shell> chkconfig –add mysql.server
======================= Data nodes.(数据节点) =======================
1、复制编译好的可执行文件ndbd、ndbmtd到相应目录/usr/local/bin shell> cd /var/tmp shell> tar -zxvf mysql-5.6.27-ndb-7.4.9-linux-i686-glibc23.tar.gz shell> cd mysql-5.6.27-ndb-7.4.9-linux-i686-glibc23 shell> cp bin/ndbd /usr/local/bin/ndbd 【单线程】 shell> cp bin/ndbmtd /usr/local/bin/ndbmtd 【多线程】
2、将其设置为可执行
shell> cd /usr/local/bin shell> chmod +x ndb*
Note:数据节点的存储 路径为/usr/local/mysql/data,可在管理节点点配置文件中设置
The data directory on each machine hosting a data node is /usr/local/mysql/data. This piece of information is essential when configuring the management node. (See Section 18.2.4, “Initial Configuration of MySQL Cluster”.)
============================= Management nodes.(管理节点) ============================= 1、复制编译好的可执行文件 ndb_mgm(client管理客户端) 、 ndb_mgmd(管理服务端)到相应目录/usr/local/bin shell> cd /var/tmp shell> tar -zxvf mysql-5.6.27-ndb-7.4.9-linux2.6-i686.tar.gz shell> cd mysql-5.6.27-ndb-7.4.9-linux2.6-i686 shell> cp bin/ndb_mgm* /usr/local/bin
2、将其设置为可执行 shell> cd /usr/local/bin shell> chmod +x ndb_mgm*
配置:
1、配置SQL nodes 和 Data nodes节点 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
[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
2、管理节点配置 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 as root):
shell> mkdir /var/lib/mysql-cluster shell> cd /var/lib/mysql-cluster shell> vi config.ini
[ndbd default]
Options affecting ndbd processes on all data nodes:
NoOfReplicas=2 # Number of replicas DataMemory=80M # How much memory to allocate for data storage IndexMemory=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 node datadir=/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 address datadir=/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 address datadir=/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)
======= 修改远程访问权限,密码 ./mysqladmin -password newpassword; ./mysqladmin -poldpassword password newpassword;
grant all privileges on . to ‘root’@’%’ identified by ‘123456’; flush privileges;
=======
============ 创建、修改数据表 ============
SQL节点
需要使用 ENGINE=NDBCLUSTER; 或ENGINE=NDB For a table to be replicated in the cluster, it must use the NDBCLUSTER storage engine. To specify this, use the ENGINE=NDBCLUSTER or ENGINE=NDB option when creating the table:
CREATE TABLE tbl_name (col_name column_definitions) ENGINE=NDBCLUSTER;
create table person
(id
int(11) not null auto_increment,name
varchar(30) not null default ‘‘,primary key (id
)) engine=ndbcluster default charset=utf8;
insert into person
(name) values(‘hello’);
Alternatively, for an existing table that uses a different storage engine, use ALTER TABLE to change the table to use NDBCLUSTER:
ALTER TABLE tbl_name ENGINE=NDBCLUSTER;
====== 导入mysql ======
利用mysqldump导入SQL文件,2个方法
1、导入之前,需要替换为ENGINE=NDBCLUSTER; 2、不需要替换,导入之后用alter table修改引擎ENGINE=NDBCLUSTER;
shell> mysqldump –add-drop-table world City > city_table.sql
本地搭建测试
8986 8922- 8923 8906 8907
172.17.163.203 manager.cluster.com 91bade15b55b 10.0.0.23 91bade15b55b 172.17.163.203 ndb1.cluster.com 1af160e4c354 10.0.0.20 1af160e4c354 172.17.163.203 ndb2.cluster.com 09902374aac7 10.0.0.19 09902374aac7 172.17.163.203 mysqld1.cluster.com ee0629f25a4f 10.0.0.22 ee0629f25a4f 172.17.163.203 mysqld2.cluster.com 8f0654dc44ea 10.0.0.21 8f0654dc44ea