找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 4280|回复: 0

MySQL Cluster 开发环境简明部署(中文)

[复制链接]
发表于 2012-2-24 14:50:42 | 显示全部楼层 |阅读模式
MySQL Cluster 开发环境简明部署(中文)
主要内容
1. 获取; 2. 安装; 3. 配置; 4. 运行; 5. 测试; 6. 停止; 7. 总结
1. 获取
这个不必多言吧,到 MySQL 网站上面下载就是了。MySQL Cluster 的英文部署测试手册很简明,这里和其内容基本一样。喜欢读英文版的朋友可以直接下载,略过本文。
2. 安装
先解压,然后创建一个 symbolic link:
  1. michael@linux:~$ tar xvf mysql-cluster-gpl-7.2.4-linux2.6-x86_64.tar
  2. michael@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 三部分组成。首先我们为它们创建一些必须的目录:
  1. michael@linux:~$ mkdir mysql-cluster
  2. michael@linux:~$ cd mysql-cluster
  3. michael@linux:~$ mkdir conf ndb_data mysqld_data
复制代码
然后在conf目录下创建如下两个文件,分别是config.ini和my.cnf,内容如下:
config.ini
用于 MySQL Server 的配置,端口号port根据你自己的情况设定。
  1. [mysqld]
  2. ndbcluster
  3. datadir=/home/user1/my_cluster/mysqld_data
  4. basedir=/home/user1/mysqlc
  5. port=5050
复制代码
my.cnf
该文件用于配置各结点的 NodeId 和 Data Nodes 与 Management Node 的数据目录。
  1. [ndb_mgmd]
  2. hostname=localhost
  3. datadir=/home/user1/my_cluster/ndb_data
  4. NodeId=1
  5. [ndbd default]
  6. noofreplicas=2
  7. datadir=/home/user1/my_cluster/ndb_data
  8. [ndbd]
  9. hostname=localhost
  10. NodeId=3
  11. [ndbd]
  12. hostname=localhost
  13. NodeId=4
  14. [mysqld]
  15. NodeId=50
复制代码
这时你的目录结构应该如下:
  1. ~
  2. +-- /mysql-cluster-gpl-7.2.4-linux2.6-x86_64
  3. +-- /mysqlc -> mysql-cluster-gpl-7.2.4-linux2.6-x86_64
  4. +-- /mysql-cluster
  5.     +-- /conf
  6.     +-- /ndb_data
  7.     +-- /mysqld_data
复制代码
4. 运行
MySQL Cluster 的启动顺序是有要求的,如下:

  • Management Node
  • Data Nodes
  • MySQL Server
命令如下:
  1. michael@linux:~$ cd ../mysql-cluster
  2. michael@linux:~/mysql-cluster$ $HOME/mysqlc/bin/ndb_mgmd -f conf/config.ini --initial --configdir=$HOME/mysql-cluster/conf/
  3. michael@linux:~/mysql-cluster$ $HOME/mysqlc/bin/ndbd -c localhost:1186
  4. michael@linux:~/mysql-cluster$ $HOME/mysqlc/bin/ndbd -c localhost:1186
复制代码
检查已经启动的结点的状态,命令为:
  1. poecahnt@linux:~$ $HOME/mysqlc/bin/ndb_mgm -e show
复制代码
输出如下:
  1. Connected to Management Server at: localhost:1186
  2. Cluster Configuration
  3. ---------------------
  4. [ndbd(NDB)]     2 node(s)
  5. id=3    @127.0.0.1  (mysql-5.5.19 ndb-7.2.4, Nodegroup: 0, Master)
  6. id=4    @127.0.0.1  (mysql-5.5.19 ndb-7.2.4, Nodegroup: 0)
  7. [ndb_mgmd(MGM)] 1 node(s)
  8. id=1    @127.0.0.1  (mysql-5.5.19 ndb-7.2.4)
  9. [mysqld(API)]   1 node(s)
  10. id=50   @127.0.0.1  (mysql-5.5.19 ndb-7.2.4)
复制代码
表示已经可以启动 MySQL Server 了。最后启动 MySQL Server,命令为:
  1. michael@linux:~/mysql-cluseter$ $HOME/mysqlc/bin/mysqld --defaults-file=conf/my.cnf &
复制代码
输出信息如下:
  1. 120223 15:29:02 InnoDB: The InnoDB memory heap is disabled
  2. 120223 15:29:02 InnoDB: Mutexes and rw_locks use GCC atomic builtins
  3. 120223 15:29:02 InnoDB: Compressed tables use zlib 1.2.3
  4. 120223 15:29:02 InnoDB: Using Linux native AIO
  5. 120223 15:29:02 InnoDB: Initializing buffer pool, size = 128.0M
  6. 120223 15:29:02 InnoDB: Completed initialization of buffer pool
  7. 120223 15:29:02 InnoDB: highest supported file format is Barracuda.
  8. 120223 15:29:02  InnoDB: Waiting for the background threads to start
  9. 120223 15:29:03 InnoDB: 1.1.8 started; log sequence number 1595675
  10. 120223 15:29:04 [Note] NDB: NodeID is 50, management server 'localhost:1186'
  11. 120223 15:29:04 [Note] NDB[0]: NodeID: 50, all storage nodes connected
  12. 120223 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 mysqlds
  13. 120223 15:29:04 [Note] Starting Cluster Binlog Thread
  14. 120223 15:29:04 [Note] Event Scheduler: Loaded 0 events
  15. 120223 15:29:04 [Note] $HOME/mysqlc/bin/mysqld: ready for connections.
  16. Version: '5.5.19-ndb-7.2.4-gpl'  socket: '/tmp/mysql.sock'  port: 5050  MySQL Cluster Community Server (GPL)
  17. 120223 15:29:05 [Note] NDB: Creating mysql.ndb_schema
  18. 120223 15:29:08 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_schema
  19. 120223 15:29:09 [Note] NDB Binlog: logging ./mysql/ndb_schema (UPDATED,USE_WRITE)
  20. 120223 15:29:09 [Note] NDB: Creating mysql.ndb_apply_status
  21. 120223 15:29:09 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_apply_status
  22. 120223 15:29:09 [Note] NDB Binlog: logging ./mysql/ndb_apply_status (UPDATED,USE_WRITE)
  23. 120223 15:29:09 [Note] NDB: missing frm for mysql.ndb_index_stat_sample, discovering...
  24. 120223 15:29:09 [Note] NDB: missing frm for mysql.ndb_index_stat_head, discovering...
  25. 2012-02-23 15:29:10 [NdbApi] INFO     -- Flushing incomplete GCI:s < 579/14
  26. 2012-02-23 15:29:10 [NdbApi] INFO     -- Flushing incomplete GCI:s < 579/14
  27. 120223 15:29:10 [Note] NDB Binlog: starting log at epoch 579/14
  28. 120223 15:29:10 [Note] NDB Binlog: ndb tables writable
复制代码
5. 测试
连接 MySQL Server 进行测试,确认可以用ndb存储引擎来创建数据库中的表,如下:
  1. michael@linux:~$ $HOME/mysqlc/bin/mysql -h 127.0.0.1 -P 5050
  2. mysql> create database clusterdb;
  3. mysql> use clusterdb;
  4. mysql> insert into simples values (1),(2),(3),(4);
  5. mysql> select * from simples;
  6.         +----+
  7.         | id |
  8.         +----+
  9.         |  3 |
  10.         |  1 |
  11.         |  2 |
  12.         |  4 |
  13.         +----+
复制代码
6. 停止
MySQL Cluster 必须手动停止,Data Nodes 可以用 ndb_mgm 来停止:
  1. michael@linux:~$ $HOME/mysqlc/bin/mysqladmin -h 127.0.0.1 -P 5050 shutdown
复制代码
如果提示:
  1. /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。
  1. michael@linux:~$ $HOME/mysqlc/bin/ndb_mgm -e shutdown
复制代码
正常停止的信息类似如下:
  1. 120223 16:44:11 [Note] /home/michael/mysqlc/bin/mysqld: Normal shutdown
  2. michael@linux:~/mysql-cluster$ 120223 16:44:11 [Note] Event Scheduler: Purging the queue. 0 events
  3. 120223 16:44:13 [Warning] /home/michael/mysqlc/bin/mysqld: Forcing close of thread 2  user: 'michael'
  4. 120223 16:44:13 [Note] Stopping Cluster Utility thread
  5. 120223 16:44:13 [Note] Stopping Cluster Index Stats thread
  6. 120223 16:44:13 [Note] Stopping Cluster Binlog
  7. 120223 16:44:13 [Note] Stopping Cluster Index Statistics thread
  8. 120223 16:44:14  InnoDB: Starting shutdown...
  9. 120223 16:44:15  InnoDB: Shutdown completed; log sequence number 1595675
  10. 120223 16:44:15 [Note] /home/michael/mysqlc/bin/mysqld: Shutdown complete
复制代码
7. 总结

  • 有序启动:Management Node,Data Nodes,MySQL Server
  • 配置项与各节点的对应
  • 每个结点都单独启动
  • Management Node 提供状态查看等多种功能
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-12-4 00:55 , Processed in 0.018358 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表