MySQL NDB 安装的安装,配置与测试

[color=blue]MySQL NDB 安装的安装,配置与测试
MySQL NDB 安装
下载:mysql-cluster-gpl-7.1.10-linux-x86_64-glibc23.tar.gz

配置之前,需要先从理论上好好系统把握一下mysql ndb的配置方法,这样可以少走很多弯路.

一:配置前的规划
管理节点IP: 192.168.133.98 节点ID: id=1
NDB数据节点1: 192.168.133.101 节点ID: id=2
NDB数据节点2: 192.168.133.102 节点ID: id=3
mysql节点1: 192.168.133.62 节点ID: id=4
mysql节点2: 192.168.133.100 节点ID: id=5

OS:Centos 5.4 64位,4GB内存,5台都是虚拟机,都是运行在Vmware vsphere上的.
# uname -a
#:Linux localhost.localdomain 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
--------------------------------------------------------------------------------
二:开始安装
A,安装数据节点与mysql节点,以下操作重复4次,在除管理节点以外的其他的节点上执行:
#groupadd mysql
#useradd –g mysql mysql
#tar zxvf mysql-cluster-gpl-7.1.10-linux-x86_64-glibc23.tar.gz
#chown mysql:mysql mysql-cluster-gpl-7.1.10-linux-x86_64-glibc23
#cd mysql-cluster-gpl-7.1.10-linux-x86_64-glibc23
#mv * /usr/local/mysql
上述命令先创建mysql组和mysql用户,并且把MySQL分配到MySQL组,然后将安装文件解压,把它放置到/usr/local/mysql目录。
---------------------------------------------------------------------------------
三:配置
配置管理节点[192.168.133.98]:
创建以下文件/var/lib/mysql-cluster/config.ini,并在其中添加如下内容:
[NDBD DEFAULT]
NoOfReplicas=2 #2表示节点
DataMemory=100M
IndexMemory=100M

[TCP DEFAULT]
portnumber=2202

#管理节点
[NDB_MGMD]
id=1
hostname=192.168.133.98
datadir=/var/lib/mysql-cluster


#第一个ndbd节点
[NDBD]
id=2
hostname=192.168.133.101
datadir=/usr/local/mysql/ndbdata

#第二个ndbd节点
[NDBD]
id=3
hostname=192.168.133.102
datadir=/usr/local/mysql/ndbdata

#SQL node

[mysqld]
id=4
hostname=192.168.133.62

[mysqld]
id=5
hostname=192.168.133.100
在这个文件里,我们分别给四个节点分配了ID,这有利于更好的管理和区分各个节点。当然,要是不指定,MySQL也会动态分配一个。上述几个Datadir如果还不存在的需要手动创建。用mkdir –p命令即可。
--------------------------------------------------------------------------------
四:配置数据节点[192.168.133.101, 192.168.133.102]:

创建/etc/my.cnf文件,内容如下

# Options for mysqld process:

[mysqld]
datadir=/usr/local/mysql/ndbdata

[mysql_cluster]
ndb-connectstring = 192.168.133.98
--------------------------------------------------------------------------------
五:配置SQL节点[192.168.133.62,192.168.133.100]

创建/etc/my.cnf文件,内容如下

# Options for mysqld process:

[mysqld]
ndbcluster # run NDB storage engine
ndb-connectstring=192.168.133.98 # location of management server

# Options for ndbd process:
[mysql_cluster]
ndb-connectstring=192.168.133.98 # location of management server


./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf

Installing MySQL system tables...

OK

Filling help tables...

OK

到这里,所有配置已经完成了。
--------------------------------------------------------------------------------
六:启动
启动管节点[192.168.133.98]:

# ./ndb_mgmd -f /var/lib/mysql-cluster/config.ini

# ./ndb_mgm

-- NDB Cluster -- Management Client --

ndb_mgm> show

Connected to Management Server at: 192.168.133.98:1186

Cluster Configuration

---------------------

[ndbd(NDB)] 2 node(s)

id=2 (not connected, accepting connect from 192.168.133.101)

id=3 (not connected, accepting connect from 192.168.133.102)

[ndb_mgmd(MGM)] 1 node(s)

id=1 @192.168.133.98 (Version: 7.1.10)

[mysqld(API)] 1 node(s)

id=4 (not connected, accepting connect from 192.168.133.62)
id=5 (not connected, accepting connect from 192.168.133.100)

我们可以看到集群的状态都还没有启动,都是not connected状态。
--------------------------------------------------------------------------------
七:启动数据节点[192.168.133.101, 192.168.133.102]:

#cd /usr/local/mysql/bin

#./ndbd

启动SQL节点[192.168.133.62,192.168.133.100]:

# ./bin/mysqld_safe &

至此,所有节点已经启动完成,让我们来查看系统状态:

Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.133.101 (Version: 7.1.10, Nodegroup: 0, Master)
id=3 @192.168.133.102 (Version: 7.1.10, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.133.98 (Version: 7.1.10)

[mysqld(API)] 2 node(s)
id=4 @192.168.133.62 (Version: 7.1.10)
id=5 @192.168.133.100 (Version: 7.1.10)
--------------------------------------------------------------------------------
八:测试:
在192.168.133.62上执行以下命令:
#mysql
mysql> use ndbdatabase;
Database changed
mysql> create table test (id int) engine=ndb;
Query OK, 0 rows affected (0.10 sec)

mysql> show create table test\G;
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(11) DEFAULT NULL
) ENGINE=ndbcluster DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

ERROR:
No query specified

mysql> insert into test values(1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)

mysql>

在192.168.133.100上执行以下命令,验证以上操作:
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.51-ndb-7.1.10-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| ndbdatabase |
| ndbinfo |
| test |
+--------------------+
5 rows in set (0.01 sec)

mysql> use ndbdatabase;
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_ndbdatabase |
+-----------------------+
| test |
+-----------------------+
1 row in set (0.00 sec)

mysql> show create table test\G;
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(11) DEFAULT NULL
) ENGINE=ndbcluster DEFAULT CHARSET=latin1
1 row in set (0.02 sec)

ERROR:
No query specified

mysql> select * from test;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.01 sec)

mysql>

验证表明,集群工作正常.
--------------------------------------------------------------------------------
九:破坏性测试:
1,关闭其中一个数据节点,验证结果表明,集群工作正常,

以下操作在数据节点2[192.168.133.102]上执行,如下:
# ps -ef | grep ndbd
root 7541 1 0 01:52 ? 00:00:00 ./ndbd –nodeid=3 –initial
root 7542 7541 0 01:52 ? 00:02:39 ./ndbd –nodeid=3 –initial
root 9931 3295 0 20:47 pts/1 00:00:00 grep ndbd
# kill 7541 7542
# ps -ef | grep ndbd
root 9933 3295 0 20:47 pts/1 00:00:00 grep ndbd
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:B8:00:13
inet addr:192.168.133.102 Bcast:192.168.133.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:feb8:13/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:19511513 errors:0 dropped:0 overruns:0 frame.:0
TX packets:19957492 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1781288143 (1.6 GiB) TX bytes:1899963551 (1.7 GiB)
Base address:0x2000 Memory:d8920000-d8940000


lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:597990 errors:0 dropped:0 overruns:0 frame.:0
TX packets:597990 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:51521498 (49.1 MiB) TX bytes:51521498 (49.1 MiB)

#
--------------------------------------------------------------------------------
十:去管理节点看集群的状态:
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.133.101 (Version: 7.1.10, Nodegroup: 0, Master)
id=3 (not connected, accepting connect from 192.168.133.102)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.133.98 (Version: 7.1.10)

[mysqld(API)] 2 node(s)
id=4 @192.168.133.62 (Version: 7.1.10)
id=5 @192.168.133.100 (Version: 7.1.10)

ndb_mgm>

表明192.168.133.102上的数据节点确实当掉了.

去mysql节点1[192.168.133.62]做如下操作:
# mysql
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:B8:00:0F
inet addr:192.168.133.62 Bcast:192.168.133.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:feb8:f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7603400 errors:0 dropped:0 overruns:0 frame.:0
TX packets:4072260 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:684602777 (652.8 MiB) TX bytes:402432650 (383.7 MiB)
Base address:0x2000 Memory:d8920000-d8940000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:203352 errors:0 dropped:0 overruns:0 frame.:0
TX packets:203352 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11961759 (11.4 MiB) TX bytes:11961759 (11.4 MiB)

# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.51-ndb-7.1.10-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| ndbdatabase |
| ndbinfo |
| test |
+--------------------+
5 rows in set (0.00 sec)

mysql> use ndbdatabase;
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_ndbdatabase |
+-----------------------+
| test |
+-----------------------+
1 row in set (0.01 sec)

mysql> select * from test;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)

mysql>

以上操作表明在一个数据节点当机后,集群依然工作正常[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值