主要内容
1. 获取; 2. 安装; 3. 配置; 4. 运行; 5. 测试; 6. 停止; 7. 总结
1. 获取这个不必多言吧,到 mysql 网站上面下载就是了。mysql cluster 的英文部署测试手册很简明,这里和其内容基本一样。喜欢读英文版的朋友可以直接下载,略过本文。
mysql cluster 的英文部署测试手册下载地址:
免费下载地址在
用户名与密码都是
具体下载目录在 /2012年资料/2月/29日/mysql cluster 开发环境简明部署(中文)/
2. 安装先解压,然后创建一个 symbolic link:
michael@linux:~$ tar xvf mysql-cluster-gpl-7.2.4-linux2.6-x86_64.tarmichael@linux:~$ ln -s mysql-cluster-gpl-7.2.4-linux2.6-x86_64 mysqlc如果你愿意,可以将~/mysqlc/bin加入到你的 path 里,方便使用。
3. 配置作为在开发环境上第一次部署,还是以测试为主要目的。一个完整的 mysql cluster 由 mysql server,data nodes,management node 三部分组成。首先我们为它们创建一些必须的目录:
michael@linux:~$ mkdir mysql-clustermichael@linux:~$ cd mysql-clustermichael@linux:~$ mkdir conf ndb_data mysqld_data然后在conf目录下创建如下两个文件,分别是config.ini和my.cnf,,内容如下:
config.ini用于 mysql server 的配置,端口号port根据你自己的情况设定。
[mysqld]ndbclusterdatadir=/home/user1/my_cluster/mysqld_databasedir=/home/user1/mysqlcport=5050my.cnf该文件用于配置各结点的 nodeid 和 data nodes 与 management node 的数据目录。
[ndb_mgmd]hostname=localhostdatadir=/home/user1/my_cluster/ndb_datanodeid=1[ndbd default]noofreplicas=2datadir=/home/user1/my_cluster/ndb_data[ndbd]hostname=localhostnodeid=3[ndbd]hostname=localhostnodeid=4[mysqld]nodeid=50这时你的目录结构应该如下:
~+-- /mysql-cluster-gpl-7.2.4-linux2.6-x86_64+-- /mysqlc -> mysql-cluster-gpl-7.2.4-linux2.6-x86_64+-- /mysql-cluster+-- /conf+-- /ndb_data+-- /mysqld_data4. 运行mysql cluster 的启动顺序是有要求的,如下:
management node data nodes mysql server命令如下:
michael@linux:~$ cd ../mysql-clustermichael@linux:~/mysql-cluster$ $home/mysqlc/bin/ndb_mgmd -f conf/config.ini --initial --configdir=$home/mysql-cluster/conf/michael@linux:~/mysql-cluster$ $home/mysqlc/bin/ndbd -c localhost:1186michael@linux:~/mysql-cluster$ $home/mysqlc/bin/ndbd -c localhost:1186检查已经启动的结点的状态,命令为:
poecahnt@linux:~$ $home/mysqlc/bin/ndb_mgm -e show输出如下:
connected to management server at: localhost:1186cluster configuration---------------------[ndbd(ndb)]2 node(s)id=3 @127.0.0.1 (mysql-5.5.19 ndb-7.2.4, nodegroup: 0, master)id=4 @127.0.0.1 (mysql-5.5.19 ndb-7.2.4, nodegroup: 0)[ndb_mgmd(mgm)] 1 node(s)id=1 @127.0.0.1 (mysql-5.5.19 ndb-7.2.4)[mysqld(api)] 1 node(s)id=50 @127.0.0.1 (mysql-5.5.19 ndb-7.2.4)表示已经可以启动 mysql server 了。最后启动 mysql server,命令为:
michael@linux:~/mysql-cluseter$ $home/mysqlc/bin/mysqld --defaults-file=conf/my.cnf &输出信息如下:
120223 15:29:02 innodb: the innodb memory heap is disabled120223 15:29:02 innodb: mutexes and rw_locks use gcc atomic builtins120223 15:29:02 innodb: compressed tables use zlib 1.2.3120223 15:29:02 innodb: using linux native aio120223 15:29:02 innodb: initializing buffer pool, size = 128.0m120223 15:29:02 innodb: completed initialization of buffer pool120223 15:29:02 innodb: highest supported file format is barracuda.120223 15:29:02 innodb: waiting for the background threads to start120223 15:29:03 innodb: 1.1.8 started; log sequence number 1595675120223 15:29:04 [note] ndb: nodeid is 50, management server 'localhost:1186'120223 15:29:04 [note] ndb[0]: nodeid: 50, all storage nodes connected120223 15:29:04 [warning] ndb: server id set to zero - changes logged to bin log with server id zero will be logged with another server id by slave mysqlds120223 15:29:04 [note] starting cluster binlog thread120223 15:29:04 [note] event scheduler: loaded 0 events120223 15:29:04 [note] $home/mysqlc/bin/mysqld: ready for connections.version: '5.5.19-ndb-7.2.4-gpl' socket: '/tmp/mysql.sock' port: 5050 mysql cluster community server (gpl)120223 15:29:05 [note] ndb: creating mysql.ndb_schema120223 15:29:08 [note] ndb binlog: create table event: repl$mysql/ndb_schema120223 15:29:09 [note] ndb binlog: logging ./mysql/ndb_schema (updated,use_write)120223 15:29:09 [note] ndb: creating mysql.ndb_apply_status120223 15:29:09 [note] ndb binlog: create table event: repl$mysql/ndb_apply_status120223 15:29:09 [note] ndb binlog: logging ./mysql/ndb_apply_status (updated,use_write)120223 15:29:09 [note] ndb: missing frm for mysql.ndb_index_stat_sample, discovering...120223 15:29:09 [note] ndb: missing frm for mysql.ndb_index_stat_head, discovering...2012-02-23 15:29:10 [ndbapi] info-- flushing incomplete gci:s 连接 mysql server 进行测试,确认可以用ndb存储引擎来创建数据库中的表,如下:michael@linux:~$ $home/mysqlc/bin/mysql -h 127.0.0.1 -p 5050mysql> create database clusterdb;mysql> use clusterdb;mysql> insert into simples values (1),(2),(3),(4);mysql> select * from simples;+----+| id |+----+| 3 || 1 || 2 || 4 |+----+6. 停止mysql cluster 必须手动停止,data nodes 可以用 ndb_mgm 来停止:
michael@linux:~$ $home/mysqlc/bin/mysqladmin -h 127.0.0.1 -p 5050 shutdown如果提示:
/home/michael/mysqlc/bin/mysqladmin: shutdown failed; error: 'access denied; you need (at least one of) the shutdown privilege(s) for this operation'则在shutdown命令前加上sudo。
michael@linux:~$ $home/mysqlc/bin/ndb_mgm -e shutdown正常停止的信息类似如下:
120223 16:44:11 [note] /home/michael/mysqlc/bin/mysqld: normal shutdownmichael@linux:~/mysql-cluster$ 120223 16:44:11 [note] event scheduler: purging the queue. 0 events120223 16:44:13 [warning] /home/michael/mysqlc/bin/mysqld: forcing close of thread 2 user: 'michael'120223 16:44:13 [note] stopping cluster utility thread120223 16:44:13 [note] stopping cluster index stats thread120223 16:44:13 [note] stopping cluster binlog120223 16:44:13 [note] stopping cluster index statistics thread120223 16:44:14 innodb: starting shutdown...120223 16:44:15 innodb: shutdown completed; log sequence number 1595675120223 16:44:15 [note] /home/michael/mysqlc/bin/mysqld: shutdown complete7. 总结有序启动:management node,data nodes,mysql server 配置项与各节点的对应 每个结点都单独启动 management node 提供状态查看等多种功能
