mysql NDB的安装配置使用示例

1.到mysql网站下载mysql cluster版本 http://www.mysql.com/downloads/cluster/

  下载到/home/weijianzhongwj/software下

2.安装mysql cluster

 cd /home/weijianzhongwj/software

  tar xvf mysql-cluster-gpl-7.2.8-linux2.6-i686.tar.gz

  ln -s mysql-cluster-gpl-7.2.8-linux2.6-i686 mysqlc 

在$HOME/.bashrc增加 export PATH=$PATH:/home/weijianzhongwj/software/mysqlc/bin 一行,添加mysql的bin目录到path路径中

3.对于一个mysql集群,我们需要启动一个mysql server(mysqld),两个data nodes(NDB),还有一个管理结点(ndb_mgmd),我们测试是在单机中,对于在多台机器上,在data nodes配置的hostname修改为对应机器的ip则可。

  我们先来添加爱mysql集群需要的配置文件

  先进入mysqlc的目录,在这个目录下创建配置文件目录和数据文件目录


cd /home/weijianzhongwj/software/mysqlc
mkdir my_cluster my_cluster/ndb_data my_cluster/mysqld_data my_cluster/conf

然后在my_cluster/conf中创建下面两个文件:

my.cnf

[mysqld]
ndbcluster
datadir=/home/weijianzhongwj/software/mysqlc/my_cluster/mysqld_data
basedir=/home/weijianzhongwj/software/mysqlc
port=5000
        

 config.ini

[ndb_mgmd]
hostname=localhost
datadir=/home/weijianzhongwj/software/mysqlc/my_cluster/ndb_data
NodeId=1
[ndbd default]
noofreplicas=2
datadir=/home/weijianzhongwj/software/mysqlc/my_cluster/ndb_data
[ndbd]
hostname=localhost
NodeId=3
[ndbd]
hostname=localhost
NodeId=4
[mysqld]
NodeId=50

然后在mysqlc的目录下,创建名称为mysql数据库,这是所有mysql需要创建的数据库

cd /home/weijianzhongwj/software/mysqlc/
scripts/mysql_install_db --no-defaults --datadir=/home/weijianzhongwj/software/mysqlc//my_cluster/mysqld_data/

4.启动管理结点,数据结点,mysql server

weijianzhongwj@ubuntu:~/software/mysqlc$ bin/ndb_mgmd -f my_cluster/conf/config.ini --initial --configdir=/home/weijianzhongwj/software/mysqlc/my_cluster/conf/
MySQL Cluster Management Server mysql-5.5.27 ndb-7.2.8
weijianzhongwj@ubuntu:~/software/mysqlc$ ps aufx|grep ndb
1000      2352  0.0  0.0   2256   316 ?        S    21:18   0:00  \_ /usr/lib/chromium-browser/chromium-browser-sandbox /usr/lib/chromium-browser/chromium-browser --type=zygote
1000      3286  0.0  0.0   5832   840 pts/3    S+   21:52   0:00      \_ grep --color=auto ndb
1000      3275  0.4  0.0  35964  2504 ?        Ssl  21:52   0:00 bin/ndb_mgmd -f my_cluster/conf/config.ini --initial --configdir=/home/weijianzhongwj/software/mysqlc/my_cluster/conf/
weijianzhongwj@ubuntu:~/software/mysqlc$ bin/ndbd -c localhost:1186
2012-11-08 21:53:12 [ndbd] INFO     -- Angel connected to 'localhost:1186'
2012-11-08 21:53:12 [ndbd] INFO     -- Angel allocated nodeid: 3
weijianzhongwj@ubuntu:~/software/mysqlc$ bin/ndbd -c localhost:1186
2012-11-08 21:53:14 [ndbd] INFO     -- Angel connected to 'localhost:1186'
2012-11-08 21:53:14 [ndbd] INFO     -- Angel allocated nodeid: 4
weijianzhongwj@ubuntu:~/software/mysqlc$ ps aufx|grep ndbd
1000      3395  0.0  0.0   5832   836 pts/3    S+   21:53   0:00      \_ grep --color=auto ndbd
1000      3316  0.0  0.0  19544  2284 ?        Ss   21:53   0:00 bin/ndbd -c localhost:1186
1000      3317  2.9  5.8 514332 479652 ?       Sl   21:53   0:00  \_ bin/ndbd -c localhost:1186
1000      3355  0.0  0.0  19544  2284 ?        Ss   21:53   0:00 bin/ndbd -c localhost:1186
1000      3356  3.3  5.8 514200 479260 ?       Sl   21:53   0:00  \_ bin/ndbd -c localhost:1186
weijianzhongwj@ubuntu:~/software/mysqlc$ bin/ndb_mgm -e show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]	2 node(s)
id=3	@127.0.0.1  (mysql-5.5.27 ndb-7.2.8, Nodegroup: 0, Master)
id=4	@127.0.0.1  (mysql-5.5.27 ndb-7.2.8, Nodegroup: 0)

[ndb_mgmd(MGM)]	1 node(s)
id=1	@127.0.0.1  (mysql-5.5.27 ndb-7.2.8)

[mysqld(API)]	1 node(s)
id=50 (not connected, accepting connect from any host)

weijianzhongwj@ubuntu:~/software/mysqlc$ bin/mysqld --defaults-file=/home/weijianzhongwj/software/mysqlc/my_cluster/conf/my.cnf &
[1] 3449
weijianzhongwj@ubuntu:~/software/mysqlc$ 121108 21:54:50 [Note] Plugin 'FEDERATED' is disabled.
121108 21:54:50 InnoDB: The InnoDB memory heap is disabled
121108 21:54:50 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
121108 21:54:50 InnoDB: Compressed tables use zlib 1.2.3
121108 21:54:50 InnoDB: Using Linux native AIO
121108 21:54:50 InnoDB: Initializing buffer pool, size = 128.0M
121108 21:54:50 InnoDB: Completed initialization of buffer pool
121108 21:54:50 InnoDB: highest supported file format is Barracuda.
121108 21:54:51  InnoDB: Waiting for the background threads to start
121108 21:54:52 InnoDB: 1.1.8 started; log sequence number 1595675
121108 21:54:52 [Note] NDB: NodeID is 50, management server 'localhost:1186'
121108 21:54:53 [Note] NDB[0]: NodeID: 50, all storage nodes connected
121108 21:54:53 [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
121108 21:54:53 [Note] Starting Cluster Binlog Thread
121108 21:54:53 [Note] Server hostname (bind-address): '0.0.0.0'; port: 5000
121108 21:54:53 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
121108 21:54:53 [Note] Server socket created on IP: '0.0.0.0'.
121108 21:54:53 [Note] Event Scheduler: Loaded 0 events
121108 21:54:53 [Note] bin/mysqld: ready for connections.
Version: '5.5.27-ndb-7.2.8-cluster-gpl'  socket: '/tmp/mysql.sock'  port: 5000  MySQL Cluster Community Server (GPL)
121108 21:54:54 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$mysql/ndb_schema
121108 21:54:54 [Note] NDB Binlog: logging ./mysql/ndb_schema (UPDATED,USE_WRITE)
121108 21:54:54 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$mysql/ndb_apply_status
121108 21:54:54 [Note] NDB Binlog: logging ./mysql/ndb_apply_status (UPDATED,USE_WRITE)
121108 21:54:54 [Note] NDB: Cleaning stray tables from database 'information_schema'
121108 21:54:54 [Note] NDB: Cleaning stray tables from database 'ndbinfo'
121108 21:54:54 [Note] NDB: Cleaning stray tables from database 'performance_schema'
121108 21:54:54 [Note] NDB: Cleaning stray tables from database 'test'
2012-11-08 21:54:54 [NdbApi] INFO     -- Flushing incomplete GCI:s < 1320/5
2012-11-08 21:54:54 [NdbApi] INFO     -- Flushing incomplete GCI:s < 1320/5
121108 21:54:54 [Note] NDB Binlog: starting log at epoch 1320/5
121108 21:54:54 [Note] NDB Binlog: ndb tables writable

5.测试

weijianzhongwj@ubuntu:~/software/mysqlc$ bin/mysql -h 127.0.0.1 -P 5000 -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.27-ndb-7.2.8-cluster-gpl MySQL Cluster Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database clusterdb;use clusterdb;
Query OK, 1 row affected (0.06 sec)

Database changed
mysql> create table simples (id int not null primary key) engine=ndb;
121108 21:55:56 [Note] NDB Binlog: CREATE TABLE Event: REPL$clusterdb/simples
Query OK, 0 rows affected (2.34 sec)

mysql> insert into simples values (1),(2),(3),(4);
Query OK, 4 rows affected (0.01 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> select * from simples;
+----+
| id |
+----+
|  3 |
|  1 |
|  2 |
|  4 |
+----+
4 rows in set (0.02 sec)

mysql> 

我们查看下my_cluster下的文件目录

weijianzhongwj@ubuntu:~/software/mysqlc/my_cluster$ ll mysqld_data/
总用量 28704
drwxrwxr-x 7 weijianzhongwj weijianzhongwj     4096 11月  8 21:55 ./
drwxrwxr-x 5 weijianzhongwj weijianzhongwj     4096 11月  8 15:29 ../
drwx------ 2 weijianzhongwj weijianzhongwj     4096 11月  8 21:55 clusterdb/
-rw-rw---- 1 weijianzhongwj weijianzhongwj 18874368 11月  8 17:22 ibdata1
-rw-rw---- 1 weijianzhongwj weijianzhongwj  5242880 11月  8 21:54 ib_logfile0
-rw-rw---- 1 weijianzhongwj weijianzhongwj  5242880 11月  8 15:52 ib_logfile1
drwx------ 2 weijianzhongwj weijianzhongwj     4096 11月  8 15:53 mysql/
drwx------ 2 weijianzhongwj weijianzhongwj     4096 11月  8 15:38 ndbinfo/
drwx------ 2 weijianzhongwj weijianzhongwj     4096 11月  8 15:38 performance_schema/
drwx------ 2 weijianzhongwj weijianzhongwj     4096 11月  8 15:33 test/
-rw-rw---- 1 weijianzhongwj weijianzhongwj        5 11月  8 21:54 ubuntu.pid
weijianzhongwj@ubuntu:~/software/mysqlc/my_cluster$ ll ndb_data/
总用量 72
drwxrwxr-x 4 weijianzhongwj weijianzhongwj  4096 11月  8 15:49 ./
drwxrwxr-x 5 weijianzhongwj weijianzhongwj  4096 11月  8 15:29 ../
-rw-rw-r-- 1 weijianzhongwj weijianzhongwj 14947 11月  8 21:54 ndb_1_cluster.log
-rw-r--r-- 1 weijianzhongwj weijianzhongwj    76 11月  8 21:52 ndb_1_out.log
-rw-r--r-- 1 weijianzhongwj weijianzhongwj     4 11月  8 21:52 ndb_1.pid
drwxr-x--- 9 weijianzhongwj weijianzhongwj  4096 11月  8 15:49 ndb_3_fs/
-rw-r--r-- 1 weijianzhongwj weijianzhongwj  9961 11月  8 21:54 ndb_3_out.log
-rw-r--r-- 1 weijianzhongwj weijianzhongwj     4 11月  8 21:53 ndb_3.pid
drwxr-x--- 9 weijianzhongwj weijianzhongwj  4096 11月  8 15:49 ndb_4_fs/
-rw-r--r-- 1 weijianzhongwj weijianzhongwj  9783 11月  8 21:54 ndb_4_out.log
-rw-r--r-- 1 weijianzhongwj weijianzhongwj     4 11月  8 21:53 ndb_4.pid

6关闭mysql server和data nodes

weijianzhongwj@ubuntu:~/software/mysqlc$ mysqladmin -u root -h 127.0.0.1 -P 5000 shutdown
121108 22:22:33 [Note] bin/mysqld: Normal shutdown

121108 22:22:33 [Note] Event Scheduler: Purging the queue. 0 events
121108 22:22:33 [Note] Stopping Cluster Utility thread
weijianzhongwj@ubuntu:~/software/mysqlc$ 121108 22:22:33 [Note] Stopping Cluster Index Stats thread
121108 22:22:33 [Note] Stopping Cluster Binlog
121108 22:22:33 [Note] Stopping Cluster Index Statistics thread
121108 22:22:34  InnoDB: Starting shutdown...
121108 22:22:35  InnoDB: Shutdown completed; log sequence number 1595675
121108 22:22:35 [Note] bin/mysqld: Shutdown complete
weijianzhongwj@ubuntu:~/software/mysqlc$ bin/ndb_mgm -e shutdown
Connected to Management Server at: localhost:1186
3 NDB Cluster node(s) have shutdown.
Disconnecting to allow management server to shutdown.

执行出下面这个错误时,需要安装下面这个包

weijianzhongwj@ubuntu:~/software/mysqlc$ sh ./scripts/mysql_install_db --no-defaults --datadir=/home/weijianzhongwj/software/mysqlc/my_cluster/mysqld_data/
Installing MySQL system tables...
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory


Installation of system tables failed!  Examine the logs in
/home/weijianzhongwj/software/mysqlc/my_cluster/mysqld_data/ for more information.


sudo apt-get install libaio1

大家可以参考 http://dev.mysql.com/downloads/cluster/

你可能感兴趣的:(mysql NDB的安装配置使用示例)