日期:2014-05-16  浏览次数:20431 次

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