Mysql中双NDBD节点Cluster快速配置

1.配置环境;
MGM:192.168.0.31
NDBD1:192.168.0.32
NDBD2:192168.0.33
SQL1:192.168.0.34
SQL2:192.168.0.30


2.软件安装
(一)管理节点MGM
首先在合适的位置建立管理节点的配置文件;
config.ini
[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[tcp default]
portnumber=2202


[ndb_mgmd]
hostname=192.168.0.31
datadir=/var/lib/mysql-cluster
[ndbd]
hostname=192.168.0.32
datadir=/usr/local/mysql/data
[ndbd]
hostname=192.168.0.33
datadir=/usr/local/mysql/data
[mysqld]
hostname=192.168.0.30
[mysqld]
hostname=192.168.0.34
a.改变地址到/var/tmp目录下,解压mysql-cluster压缩文件,取出ndb_mdmd和ndb_mdm;
b.改变路径为拷贝到的目录下,并确保这两个文件可执行;
chmod +x ndb_mgm*
c.在/usr/local下创建mysql文件夹;
(二)数据节点NDBD和SQL节点;
配置数据节点NDBD和SQL节点;
在每个SQL节点都做如下的配置,在/etc/my.cnf文件内;
[client]
socket=/usr/local/mysql/sock/mysql.sock


[mysqld]
ndbcluster
datadir=/usr/local/mysql
socket=/usr/local/mysql/sock/mysql.sock
ndb-connectstring=192.168.0.31
#user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1


# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
[mysql_cluster]
ndb-connectstring=192.168.0.31
1.在每个数据节点和SQL节点上,创建mysql用户,和mysql用户组;
groupadd  mysql
useradd -g mysql mysql
2.改变位置到LOCAL位置,解压mysql-cluster-gpl-7.2.7-linux2.6-i686.tar.gz并改名mysql,然后执行相关的脚本,创建系统数据库;
mkdir sock
scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql  --datadir=/usr/local/mysql --socket=/usr/local/mysql/sock/mysql.sock
3.为mysql服务及数据目录设置必要的服务;
    chown -R root .
    chown -R mysql.mysql  /usr/local/mysql/data
    chown -R mysql.mysql  /usr/local/mysql/sock
    chgrp  -R mysql  .
     ls  -l
 4.复制mysql的启动脚本到如下的文件夹,确保可以执行。并设置为当系统启动时,同时启动mysql;
   cp support-files/mysql.server  /etc/rc.d/init.d/
   chmod +x  /etc/rc.d/init.d/mysql.server
   chkconfig  --add mysql.server
3.Cluster 环境启动
  注意启动顺序;首先是管理节点,然后是NDBD节点,最后是SQL节点;
 (1)[MGM]
使用ndb_mgm来监听客户端
[root@LVS ~]# ndb_mgmd  -f /var/lib/mysql-cluster/config.ini 
MySQL Cluster Management Server mysql-5.5.25 ndb-7.2.7
[root@LVS ~]# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show 
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2 (not connected, accepting connect from 192.168.0.32)
id=3 (not connected, accepting connect from 192.168.0.33)


[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.31  (mysql-5.5.25 ndb-7.2.7)


[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.0.30)
id=5 (not connected, accepting connect from 192.168.0.34)


ndb_mgm>
(2)[NDBD]
  首次启动,需要添加--initial参数,一边进行NDB节点的初始化工作,在以后的启动过程中,则是不能添加该参数,否则NDBD程序会清除之前建立的所有用于恢复的数据文件和日志文件;
[root@db1 ~]# /usr/local/mysql/bin/ndbd
2012-12-26 16:24:32 [ndbd] INFO     -- Angel connected to '192.168.0.31:1186'
2012-12-26 16:24:32 [ndbd] INFO     -- Angel allocated nodeid: 2
[root@db1 ~]# 
ndb_mgm> show 
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.0.32  (mysql-5.5.25 ndb-7.2.7, starting, Nodegroup: 0)
id=3 (not connected, accepting connect from 192.168.0.33)


[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.31  (mysql-5.5.25 ndb-7.2.7)


[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.0.30)
id=5 (not connected, accepting connect from 192.168.0.34)


ndb_mgm> Node 2: Started (version 7.2.7)


ndb_mgm> 
[root@db2 ~]# /usr/local/mysql/bin/ndbd
2012-12-26 16:30:13 [ndbd] INFO     -- Angel connected to '192.168.0.31:1186'
2012-12-26 16:30:13 [ndbd] INFO     -- Angel allocated nodeid: 3
[root@db2 ~]# 
ndb_mgm> show 
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.0.32  (mysql-5.5.25 ndb-7.2.7, Nodegroup: 0, Master)
id=3    @192.168.0.33  (mysql-5.5.25 ndb-7.2.7, starting, Nodegroup: 0)


[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.31  (mysql-5.5.25 ndb-7.2.7)


[mysqld(API)]   2 node(s)
id=4    @192.168.0.30  (mysql-5.5.25 ndb-7.2.7)
id=5    @192.168.0.34  (mysql-5.5.25 ndb-7.2.7)


ndb_mgm> Node 3: Started (version 7.2.7)
(3)[SQLD]
/usr/local/mysql/bin/mysqld_safe  --user=mysql &
如果出现ERROR 2002(HY000):Can't connect to local mysql server through socket............
可以再次创建系统数据库;
方法如下:
scripts/mysql_install_db  --user=mysql  --basedir=/usr/local/mysql  --datadir=/usr/local/mysql
然后再次启动;
/usr/local/mysql/bin/mysqld_safe  --user=mysql &
即可;
[root@sql1 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.25a-ndb-7.2.7-gpl MySQL Cluster Community Server (GPL)


Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


mysql> 
管理节点查看:
ndb_mgm> show 
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.0.32  (mysql-5.5.25 ndb-7.2.7, Nodegroup: 0, Master)
id=3    @192.168.0.33  (mysql-5.5.25 ndb-7.2.7, Nodegroup: 0)


[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.31  (mysql-5.5.25 ndb-7.2.7)


[mysqld(API)]   2 node(s)
id=4    @192.168.0.30  (mysql-5.5.25 ndb-7.2.7)
id=5    @192.168.0.34  (mysql-5.5.25 ndb-7.2.7)


ndb_mgm> 
4.测试
1.常规测试;
在节点4上,为了让在cluster中正常复制,创建一个表必须是ndbcluster引擎或者NDB引擎方法如下:
2.模拟NDB节点crash;
3.模拟SQL节点crash;


你可能感兴趣的:(Mysql中双NDBD节点Cluster快速配置)