(MySQL 集群) MySQL Cluster在Linux上的安装(RedHat 5.6)


一、环境介绍

IP_Address

Port_No

Node_name

Service_name

Desc

192.168.56.101

  3306

SQL node(API Node)

mysqld

SQL节点(API节点)

192.168.56.101

 2202

Data Node

ndbd

数据节点

192.168.56.102

 3306

SQL node(API Node)

mysqld

SQL节点(API节点)

192.168.56.102

 2202

Data Node

ndbd

数据节点

192.168.56.103

1186

Mgmt Node

ndb_mgmd

管理节点

二、准备工作

1)关闭防火墙(在三台服务器上操作)

[root@localhost ~]# service iptables stop

Flushing firewall rules:                                   [  OK  ]

Setting chains to policy ACCEPT: filter                    [  OK  ]

Unloading iptables modules:                                [  OK  ]

[root@localhost local]# chkconfig iptables off

2)默认不启动防火墙(在三台服务器上操作)

 [root@localhost ~]# chkconfig iptables off

3)添加mysql用户和组(在三台服务器上操作)

[root@localhost ~]# groupadd mysql

[root@localhost ~]# useradd -g mysql mysql

4)上传安装文件(只需要在192.168.56.101上操作即可)

可以使用FileZilla软件来上传安装文件,比如上传到Linux 上的/tmp目录。我使用的安装文件是:mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz

 三、安装Mysql Cluster

1.安装数据节点和SQL节点(只需要在192.168.56.101上操作即可)

1)安装tar包

[root@localhost ~]# cd /tmp

[root@localhost tmp]# tar -C /usr/local -zxvf mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz

[root@localhost tmp]# ln -s /usr/local/mysql-cluster-gpl-7.1.10-linux-i686-glibc23/ /usr/local/mysql

[root@localhost tmp]# cd /usr/local/mysql

[root@localhost mysql]# scripts/mysql_install_db --usr=mysql

 2)授权

[root@localhost mysql]# cd ..

[root@localhost local]# chown -R mysql mysql

[root@localhost local]# chgrp -R mysql mysql

 3)创建编辑my.cnf,键入下面内容

 [mysqld]

ndbcluster

ndb-connectstring=192.168.56.103

[mysql_cluster]

ndb-connectstring=192.168.56.103

 2.将/usr/local/mysql文件夹和/etc/my.cnf拷贝到192.168.56.102上

[root@localhost local]# scp -r ./mysql/* root@192.168.56.102:/usr/local/mysql

The authenticity of host '192.168.56.102 (192.168.56.102)' can't be established.

RSA key fingerprint is 1f:26:d9:20:d1:77:47:bf:3c:7b:64:6d:68:0f:bb:76.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.56.102' (RSA) to the list of known hosts.

root@192.168.56.102's password:

...........

[root@localhost local]# scp -r /etc/my.cnf root@192.168.56.102:/etc/

 3.将/usr/local/mysql文件夹Copy到192.168.56.103(使用scp命令)

[root@localhost local]# scp -r ./mysql/* root@192.168.56.103:/usr/local/mysql

The authenticity of host '192.168.56.103 (192.168.56.103)' can't be established.

RSA key fingerprint is 1f:26:d9:20:d1:77:47:bf:3c:7b:64:6d:68:0f:bb:76.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.56.103' (RSA) to the list of known hosts.

root@192.168.56.103's password:

 4.在102 & 103授权

[root@localhost ~]# cd /usr/local

[root@localhost local]# chown -R mysql mysql

[root@localhost local]# chgrp -R mysql mysql

 5.配置管理节点(在192.168.56.103上操作)

[root@localhost mysql]# mkdir /var/lib/mysql-cluster

[root@localhost mysql]# chown -R mysql /var/lib/mysql-cluster

[root@localhost mysql]# chgrp -R mysql /var/lib/mysql-cluster

[root@localhost mysql]# cd /usr/local/mysql/

[root@localhost mysql]# vim config.ini

 键入下面内容到config.ini中

[ndbd default]

NoOfReplicas=2 # Number of replicas

DataMemory=80M # How much memory to allocate for data storage

IndexMemory=18M # How much memory to allocate for index storage

[tcp default]

portnumber=2202 # This the default; however, you can use any

[ndb_mgmd]

hostname=192.168.56.103 # Hostname or IP address of MGM node

datadir=/var/lib/mysql-cluster # Directory for MGM node log files

[ndbd]

hostname=192.168.56.101 # Hostname or IP address

datadir=/usr/local/mysql/data # Directory for this data node's data files

[ndbd]

hostname=192.168.56.102 # Hostname or IP address

datadir=/usr/local/mysql/data # Directory for this data node's data files

[mysqld]

hostname=192.168.56.101 # Hostname or IP address

[mysqld]

hostname=192.168.56.102 # Hostname or IP address

 四、启动Mysql Cluster

1.启动管理节点后台服务(在192.168.56.103上操作)

[root@localhost mysql]# /usr/local/mysql/bin/ndb_mgmd -f /usr/local/mysql/config.ini

 2.启动管理节点管理服务(在192.168.56.103上操作)

[root@localhost mysql]# /usr/local/mysql/bin/ndb_mgm

 3.查看Mysql Cluster配置信息(在192.168.56.103上操作)

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.56.101)

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

[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.56.103  (mysql-5.1.51 ndb-7.1.10)

[mysqld(API)]   2 node(s)

id=4 (not connected, accepting connect from 192.168.56.101)

id=5 (not connected, accepting connect from 192.168.56.102)

 4.启动数据节点(101 & 102上操作)

[root@localhost local]# /usr/local/mysql/bin/ndbd --initial

 5.启动SQL节点(101 & 102上操作)

[root@localhost local]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &

 6.再次查看Mysql Cluster配置信息(在192.168.56.103上操作)

ndb_mgm> show

Cluster Configuration

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

[ndbd(NDB)]     2 node(s)

id=2    @192.168.56.101  (mysql-5.1.51 ndb-7.1.10, Nodegroup: 0, Master)

id=3    @192.168.56.102  (mysql-5.1.51 ndb-7.1.10, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.56.103  (mysql-5.1.51 ndb-7.1.10)

[mysqld(API)]   2 node(s)

id=4    @192.168.56.101  (mysql-5.1.51 ndb-7.1.10)

id=5    @192.168.56.102  (mysql-5.1.51 ndb-7.1.10)

 五、Mysql Cluster测试

1.在101(102)上创建数据库、表并插入数据

[root@localhost ~]# mysql

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| ndb_2_fs           |

| ndbinfo            |

| test               |

+--------------------+

5 rows in set (0.00 sec)

mysql> create database test1;

Query OK, 1 row affected (0.06 sec)

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| ndb_2_fs           |

| ndbinfo            |

| test               |

| test1              |

+--------------------+

6 rows in set (0.00 sec)

mysql> use test1;

Database changed

mysql> create table tb_test(id int) engine=ndb;

Query OK, 0 rows affected (0.36 sec)

mysql> insert into tb_test select 1;

Query OK, 1 row affected (0.06 sec)

Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from tb_test;

+------+

| id   |

+------+

|    1 |

+------+

1 row in set (0.00 sec)

2.在102(101)上查看已有的数据库、表和表数据

[root@localhost ~]# mysql

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| ndb_3_fs           |

| ndbinfo            |

| test               |

| test1              |

+--------------------+

6 rows in set (0.01 sec)

mysql> use test1;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select * from tb_test;

+------+

| id   |

+------+

|    1 |

+------+

1 row in set (0.00 sec)

通过测试,至此Mysql Cluster配置成功。

更多关于MySQL Cluster的详细信息,或者下载地址请点这里

相关内容