IP Description 主机名
192.168.0.199 Management Node 管理节点 Management
192.168.0.191 SQL Node 执行sql语句的节点 sqlnodeA
192.168.0.133 SQL Node 执行sql语句的节点 sqlnodeB
192.168.0.196 Data Node 存储数据的节点 datanodeA
192.168.0.17 Data Node 存储数据的节点 datanodeB
[root@Management cluster-conf]# pwd
/usr/local/mysql/cluster-conf
[root@Management cluster-conf]# cat config.ini
#此选项是对数据节点的配置
[ndbd default]
NoOfReplicas=2 # 数据复制的分数
DataMemory=80M # 分配数据内存
IndexMemory=18M # 分配索引使用内存
# 管理节点选项:
[ndb_mgmd]
id=1
hostname=192.168.0.199 # 这个是管理节点的IP地址
datadir=/var/lib/mysql-cluster # 管理所有点点日志的文件目录
#数据节点A配置
[ndbd]
id=2
hostname=192.168.0.196 #datanodeA的IP地址
datadir=/usr/local/mysql/ndbdata #目录如果不存在需要手动创建,在datanodeA从创建
#数据节点B配置
[ndbd]
id=3
hostname=192.168.0.17 #datanodeB的IP地址
datadir=/usr/local/mysql/ndbdata #目录如果不存在需要手动创建,在datanodeB从创建
#SQL节点A配置
[mysqld]
id=4
hostname=192.168.0.191 #sql节点A的IP地址
#SQL节点B配置
[mysqld]
id=5
hostname=192.168.0.133 #sql节点B的IP地址
#其中id=项不是必须配置的,如果不配置mysql也会自动分配一个。·
[root@Management cluster-conf]#
[root@sqlnodeA ~]# useradd mysql
[root@sqlnodeA ~]# chown mysql:mysql -R /usr/local/mysql/
[root@sqlnodeA ~]# vi /etc/my.cnf
#SQL½节点A的配置文件
[mysqld]
ndbcluster #配置数据的存储引擎
ndb-connectstring=192.168.0.199 #管理服务器
[mysql_cluster]
ndb_connectstring=192.168.0.199 #管理服务器
[root@sqlnodeA ~]# chown mysql:mysql /etc/my.cnf
[root@sqlnodeA ~]# scp /etc/my.cnf 192.168.0.133:/etc/
[root@sqlnodeB ~]# useradd mysql
[root@sqlnodeB ~]# chown mysql:mysql /etc/my.cnf
[root@sqlnodeB ~]# chown mysql:mysql /usr/local/mysql/ -R
[root@datanodeA ~]# useradd mysql
[root@datanodeA ~]# vi /etc/my.cnf
#这是数据节点A的配置文件
[mysqld]
datadir=/usr/local/mysql/ndbdata #数据存放目录,一定要和管理节点写的一样
ndbcluster #运行的数据库引擎
ndb-connectstring=192.168.0.199 #管理节点
[mysql_cluster]
ndb-connectstring=192.168.0.199
"/etc/my.cnf" [New] 8L, 299C written
[root@datanodeA ~]# mkdir /usr/local/mysql/ndbdata
[root@datanodeA ~]# chown mysql:mysql /usr/local/mysql/ -R
[root@datanodeA ~]# chown mysql:mysql /etc/my.cnf
[root@datanodeA ~]# scp /etc/my.cnf 192.168.0.17:/etc/
password:
my.cnf 100% 299 0.3KB/s 00:00
[root@datanodeB ~]# useradd mysql
[root@datanodeB ~]# mkdir /usr/local/mysql/ndbdata
[root@datanodeB ~]# chown mysql:mysql -R /usr/local/mysql/ndbdata/
[root@datanodeB ~]# chown mysql:mysql /etc/my.cnf
[root@sqlnodeA mysql]# ./bin/mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> show databases ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.01 sec)
mysql> create database cluster ;
Query OK, 1 row affected (0.18 sec)
mysql> use cluster ;
Database changed
mysql> create table test1(id int,name varchar(10)) engine=ndb ;
Query OK, 0 rows affected (0.03 sec)
mysql> insert into test1 values(1,'zhaoyun');
Query OK, 1 row affected (0.00 sec)
mysql> select * from test1 ;
+------+---------+
| id | name |
+------+---------+
| 1 | zhaoyun |
+------+---------+
1 row in set (0.00 sec)
现在是在SQL节点A上创建的数据库,下面从SQL节点B登录,查看效果。
[root@sqlnodeB mysql]# ./bin/mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.30-ndb-6.3.20-cluster-gpl MySQL Cluster Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cluster |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use cluster
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> show tables ;
+-------------------+
| Tables_in_cluster |
+-------------------+
| test1 |
+-------------------+
1 row in set (0.00 sec)
mysql> select * from test1 ;
+------+---------+
| id | name |
+------+---------+
| 1 | zhaoyun |
+------+---------+
1 row in set (0.00 sec)
mysql> show create table test1 ;
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| test1 | CREATE TABLE `test1` (
`id` int(11) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> insert into test1 values(2,'zhao');
Query OK, 1 row affected (0.00 sec)
mysql> select * from test1 ;
+------+---------+
| id | name |
+------+---------+
| 1 | zhaoyun |
| 2 | zhao |
+------+---------+
2 rows in set (0.00 sec)
现在看来,在SQL节点B登录,可以看到sql节点A创建的内容。那么,再从B创建内容看A是否能看到。
mysql> select * from test1 ;
+------+---------+
| id | name |
+------+---------+
| 1 | zhaoyun |
| 2 | zhao |
+------+---------+
2 rows in set (0.00 sec) 在A节点也可以看到从B节点插入的数据了。
说明现在sql节点已经工作正常,因为数据存放在数据节点,任何一个坏掉,都不影响使用。
本文转自zhaoyun00 51CTO博客,原文链接: http://blog.51cto.com/zhaoyun/738435