具体安装与配置:1)准备工作:6台机器,IP地址分别为192.168.0.(231-236)MGM节点:192.168.0.231(232)SQL 节点:192.168.0.233-234NDBD 节点:192.168.0.235-236系统都是REDHAT AS 5.0装了基本的部件,具有联网功能,而且关闭了防火墙。软件,版本是: mysql-5.1.21-beta-linux-i686-glibc23.tar.gz
2)管理节点的安装:(232和231的机器) shell> cd /var/tmp
shell> tar -zxvf mysql-5.1.21-beta-linux-i686-glibc23.tar.gz
shell> cd /var/tmp/mysql-5.1.21-beta-linux-i686-glibc23
shell> mkdir /usr/local/mysql
shell> cp bin/ndb_mgm* /usr/local/mysql
shell> cd /usr/local/mysql
shell> chmod a+x ndb_mgm*
shell> mkdir data(
用来存放管理节点的数据)
3)SQL节点和NDBD 节点的安装:(233-236 四台机器)
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /var/tmp
shell> tar -C /usr/local -xzvf mysql-5.1.21-beta-linux-i686-glibc23.tar.gz
shell> mv /usr/local/mysql-5.1.21-beta-linux-i686-glibc23 /usr/local/mysql
shell> cd mysql
shell> scripts/mysql_install_db --user=mysql
shell> chown -R mysql:mysql /usr/local/mysql
SQL节点还要增加下面的步骤才可以:
shell> cp support-files/mysql.server /etc/rc.d/init.d/mysqld
shell> chmod a+x /etc/rc.d/init.d/mysqld
shell> chkconfig --add mysqld
shell> chkconfig mysqld on (注册MYSQL为系统的服务)
4)配置NDBD节点:[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
ndbcluster
#ndb-connectstring=192.168.0.231#ndb-connectstring=192.168.0.232这样写是可以连接成功。不过我今天来的时候发现全部DOWN掉了。
ndb-connectstring=192.168.0.231,192.168.0.232[mysql_cluster]
#ndb-connectstring=192.168.0.231#ndb-connectstring=192.168.0.232ndb-connectstring=192.168.0.231,192.168.0.232[root@localhost mysql]#
5)配置SQL 节点:[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
port=3306
user=nobody
socket=/tmp/mysql.sock
ndbcluster
#ndb-connectstring=192.168.0.231#ndb-connectstring=192.168.0.232ndb-connectstring=192.168.0.231,192.168.0.232[ndbd]
connect-string=192.168.0.235
[ndbd]
connect-string=192.168.0.236
[ndbd_mgm]
connect-string=192.168.0.231
[ndbd_mgm]
connect-string=192.168.0.232
[ndbd_mgmd]
config-file=/etc/config.ini
[mysql_cluster]
#ndb-connectstring=192.168.0.231#ndb-connectstring=192.168.0.232ndb-connectstring=192.168.0.231,192.168.0.232[root@localhost mysql]#
6) 配置管理节点: [root@localhost ~]# cat /etc/config.ini
[NDBD DEFAULT]
NoOfReplicas=2
DataMemory=600M
IndexMemory=100M
# TCP/IP options:
[TCP DEFAULT]
portnumber=2202
# Management process options:
[NDB_MGMD]
id=1
hostname=192.168.0.231
datadir=/usr/local/mysql/data
[NDB_MGMD]
id=2
hostname=192.168.0.232
datadir=/usr/local/mysql/data
# Options for data node A
[NDBD]
id=5
hostname=192.168.0.235
datadir=/usr/local/mysql/data
# Options for data node B
[NDBD]
id=6
hostname=192.168.0.236
datadir=/usr/local/mysql/data
# SQL node options:
[MYSQLD]
id=3
hostname=192.168.0.233
[MYSQLD]
id=4
hostname=192.168.0.234
[MYSQLD]
[MYSQLD]
[root@localhost ~]#
7)启动管理节点:[root@localhost mysql]# /usr/local/mysql/ndb_mgmd -f /etc/config.ini
[root@localhost mysql]# ps aux | grep ndb | grep -v grep
root 6230 0.0 0.1 17428 1780 ? Ssl 22:16 0:00 /usr/local/mysql/ndb_mgmd -f /etc/config.ini
启动成功了。
默认MGMD是后台启动的。
8)启动NDBD节点
[root@localhost mysql]# /usr/local/mysql/bin/ndbd --initial
(只是第一次启动还有添加节点而且恢复的时候要加)
[root@localhost mysql]# ps aux | grep ndb | grep -v grep
root 3191 0.0 0.2 17516 1992 ? Ss 22:24 0:00 /usr/local/mysql/bin/ndbd --initial
root 3192 4.2 15.3 911740 149120 ? Sl 22:24 0:00 /usr/local/mysql/bin/ndbd --initial
[root@localhost mysql]#
9)启动SQL 节点:
[root@localhost mysql]# service mysqld start
Starting MySQL. SUCCESS!
10)查看是否连接成功
[root@localhost ~]# /usr/local/mysql/ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=5 @192.168.0.235 (Version: 5.1.21, Nodegroup: 0, Master)
id=6 @192.168.0.236 (Version: 5.1.21, Nodegroup: 0)
[ndb_mgmd(MGM)] 2 node(s)
id=1 @192.168.0.231 (Version: 5.1.21)
id=2 @192.168.0.232 (Version: 5.1.21)
[mysqld(API)] 3 node(s)
id=3 @192.168.0.233 (Version: 5.1.21)
id=4 @192.168.0.234 (Version: 5.1.21)
id=7 (not connected, accepting connect from any host)
id=8 (not connected, accepting connect from any host)
ndb_mgm>
我这个是配置两台管理节点和两台SQL节点以及两台NDBD节点的。以此类推。
以下是我在使用中遇到的错误信息:
1、
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
2、[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -pEnter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.24-max
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
m
ysql> use testDatabase changed
mysql> show tables;
Empty set, 1 warning (0.00 sec)
mysql> create table t11 (id int) engine=ndb;ERROR 1050 (42S01): Table 't11' already exists
解决办法:
运行setup或者ntsysv命令进入系统启动设置。
去掉iptables.
关掉防火墙。不过保持sellinux是打开的。
早上还碰到一个错误:
[root@localhost data]# vi ndb_pid6423_error.log
Current byte-offset of file-pointer is: 568
Time: Friday 30 November 2007 - 23:15:28
Status: Permanent error, external action neededMessage: Invalid configuration received from Management Server (Configuration error)Error: 2350Error data: Could not connect to ndb_mgmdError object:Program: /usr/local/mysql/bin/ndbdPid: 6423
Trace:
Version: Version 5.1.21 (beta)
***EOM***
~
由于我没有把ndb-connectstring=db1,db2,..dbn
这样的规律写导致,已经解决。
PS:集群的数据节点是非常重要的,如果不能保证一个数据节点正常运行的话,集群也就失去了意义。管理节点在启动了集群后也就没有了意义。所以我在想多个管理节点是否有必要。