ubuntu mysql集群搭建_ubuntu server部署mysql集群

简介

[说明本次部署的内容,目的等等]

本部署文档的目的是如何在ubuntu server上进行mysql的群集部署。

前期准备

在进行本文档操作前,需要完成如下前期步骤:

1.安装3台ubuntu server服务器;

Server1: ndbd 192.168.68.5

Server2: ndbd 192.168.68.6

Server3: mysqld –ndb-cluster 192.168.68.8

ndbd(192.168.68.5\192.168.68.6): 数据库节点,存放数据。

mysqld –ndb-cluster(192.168.68.8): MySQL服务器节点,管理节点,管理群集。

注:

本实验在ubuntu server(8.04)实现

管理节点:server3(192.168.68.8)存储节点:server1(192.168.68.5),server2(192.168.68.6)

2.3台server均安装mysql - server数据库。

部署概要

1.安装ubuntu服务器(本实验使用为8.04);

2.安装mysql – server数据库;

3.这三台服务器上配置my.cnf;

4.管理节点(192.168.68.8)上配置ndb_mgmd.cnf;

5.管理节点服务器上启动mysql-ndb-mgm;

6.存储节点上(192.168.68.5\6)启动mysql-ndb;

7.3台服务器分别启动mysql-ndb服务;

8.测试管理节点。

部署步骤

安装Ubuntu服务器

1.安装ubuntu服务器,安装过程中安装msyql(也可单独安装)、openssh服务。

群集配置

ndbcluster

ndb-connectstring=192.168.68.8

[mysqldump]

quick

quote-names

max_allowed_packet = 16M

[mysql]

#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]

key_buffer = 16M

#

# * NDB Cluster

#

# See /usr/share/doc/mysql-server-*/README.Debian for more information.

#

# The following configuration is read by the NDB Data Nodes (ndbd processes)

# not from the NDB Management Nodes (ndb_mgmd processes).

#

[MYSQL_CLUSTER]

ndb-connectstring=192.168.68.8

#

# * IMPORTANT: Additional settings that can override those from this file!

# The files must end with ‘.cnf’, otherwise they’ll be ignored.

#

!includedir /etc/mysql/conf.d/

ubuntu@ubuntu:~$

提示

/etc/mysql/my.cnf主要配置如下内容:

ndbcluster

ndb-connectstring=192.168.68.13

和添加

[MYSQL_CLUSTER]

ndb-connectstring=192.168.68.13

三台服务器都需要配置

2.管理节点服务器中配置(192.168.68.8)中配置ndb_mgmd.cnf。

复制:

/usr/share/doc/mysql-server-5.0/examples/ndb_mgmd.cnf 至/etc/mysql/ndb_mgmd.cnf

3.管理节点服务器中配置(192.168.68.8)中编辑ndb_mgmd.cnf。

ubuntu@ubuntu:~$ sudo vim /etc/mysql/ndb_mgmd.cnf

[NDBD DEFAULT]

NoOfReplicas=2

DataMemory=10MB

IndexMemory=25MB

MaxNoOfTables=256

MaxNoOfOrderedIndexes=256

MaxNoOfUniqueHashIndexes=128

[MYSQLD DEFAULT]

[NDB_MGMD DEFAULT]

[TCP DEFAULT]

[NDB_MGMD]

Id=1 # the NDB Management Node (this one)HostName=192.168.68.8

DataDir= /var/lib/mysql-cluster

[NDBD]

Id=2 # the first NDB Data Node

HostName=192.168.68.5

DataDir= /var/lib/mysql-cluster

[NDBD]

Id=3 # the second NDB Data Node

HostName=192.168.68.6DataDir=/var/lib/mysql-cluster

[MYSQLD]

Id=4 # the first SQL node

HostName=192.168.68.5

[MYSQLD]

Id=5 # the first SQL node

HostName=192.168.68.6

4.服务器管理节点服务器(192.168.68.8)中的mysql-ndb-mgm服务。

sudo /etc/init.d/mysql-ndb-mgm start

5.启动数据存储服务器(192.168.68.5\6)中服务mysql-ndb。

sudo /etc/init.d/mysql-ndb start

6.最后启动,3台服务器中(192.168.68.5\6\8)启动mysql服务。

sudo /etc/init.d/mysql start

群集测试

1.节点管理服务器运行ndb_mgm(192.168.68.8)。

ubuntu@ubuntu:~$ 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 @192.168.68.5(Version: 5.0.51, Nodegroup: 0)

id=3 @192.168. 68.6 (Version: 5.0.51, Nodegroup: 0, Master)

[ndb_mgmd(MGM)] 1 node(s)

id=1 @192.168. 68.8 (Version: 5.0.51)

[mysqld(API)] 2 node(s)

id=4 @192.168. 68.5 (Version: 5.0.51)

id=5 @192.168. 68.6 (Version: 5.0.51)

ndb_mgm>

提示

1.表必须用ENGINE=NDB或ENGINE=NDBCLUSTER选项创建,或用ALTER TABLE选项更改,以使用NDB Cluster存储引擎在 Cluster内复制它们。如果使用mysqldump的输出从已有数据库导入表,可在文本编辑器中打开SQL脚本,并将该选项添加到任何表创建语句,或用这类选项之一替换任何已有的ENGINE(或TYPE)选项。

2.另外还请记住,每个NDB表必须有一个主键。如果在创建表时用户未定义主键,NDB Cluster存储引擎将自动生成隐含的主键。(注释:该隐含 键也将占用空间,就像任何其他的表。

3.索引一样。由于没有足够的内存来容纳这些自动创建的键,出现问题并不罕见)。

4.当你在一个节点上运行create database mydb;你去其他sql node上执行show databases;将不能看到mydb,你需要创建它,然后use mydb; show tables;你将看到同步的表。

2.存储节点1 (192.168.68.5)中创建数据库(test)与表(table1)。

ubuntu@ubuntu:~$ mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 7

Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql> create database test;

Query OK, 1 row affected (0.00 sec)

mysql> use cluster

Database changed

mysql> create table table1(nub int(10),primary key(nub),) engine = ndbcluster;

charset utf8;

Query OK, 0 rows affected (1.07 sec)

mysql>insert into table1 values(1);

Query OK, 1 row affected (0.12 sec)

3.存储节点2(192.168.68.6)中创建数据库(test)。

注:节点2中不需要创建table1表,

ubuntu@ubuntu:~$ mysql –u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 7

Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql> show databases;

+——————–+

| Database |

+——————–+

| information_schema |

| mysql |

+——————–+

2 rows in set (0.13 sec)

mysql>create database test;

Query OK, 1 row affected (0.00 sec)

mysql> show databases;

+——————–+

| Database |

+——————–+

| information_schema |

| test|

| mysql |

+——————–+

3 rows in set (0.13 sec)

mysql> use test;

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 |

+——————-+

| table1 |

+——————-+

1 row in set (0.01 sec)

mysql> select * from table1;

+—-+———–+

| nub |

+—-+———–+

| 1 |

+—-+———–+

1 rows in set (0.03 sec)

提示

在节点2(192.168.68.6)中,可观察到,虽未创建table1表,但是能够查看到该表,并能够看到表中的数据,验证结果mysql群集实现。

4.将管理节点(192.168.68.8)停掉,在存储节点1服务器(192.168.68.5)中创建table2(使用ENGINE=NDBCLUSTER),在存储节点2服务器(192.168.68.6)上“show tables”也可以看到新创建的表table2。

提示

群集实现后,管理节点服务器可以停掉,群集仍然可以实现。

总结:如创建表时,未在创建表语句后添加ENGINE=NDB或ENGINE=NDBCLUSTER,则该表不会在群集server中同步。

管理节点、存储节点,也可以同在一台机器上,或两台msyql数据库server服务器,其中一台同时为管理节点与存储节点,而另一台仅为存储节点,这样的设计均是可以的。

在实际过程中可以根据实际需要而部署。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值