中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 操作系统 > Linux > Linux综合
mysql集群技术
作者:未知 时间:2005-09-13 22:41 出处:Blog.ChinaUnix.net 责编:chinaitpower
              摘要:mysql集群技术
  

1         环境描述

Mysql manager 节点:192.168.0.1

MysqlServer节点:192.168.0.100

Mysql 节点:192.168.0.160

Mysql 节点:192.168.0.161

说明:至少需要四台服务器才可以做mysql的集群。建议5台,再增加一台MysqlServer。

2         安装mysql二进制包

2.1   安装之前的准备工作

下载mysql-max-4.1.13-pc-linux-gnu-i686.tar.gz

(注意:可以做集群的mysql都是mysql-max,下载地点www.mysql.org

#groupadd mysql

#useradd -g mysql mysql

 

#cd /usr/local

#tar xfz mysql-max-4.1.13-pc-linux-gnu-i686.tar.gz

#ln -s /usr/local/mysql-max-4.1.13-pc-linux-gnu-i686  /opt/mysql4.1.13

2.2   分别在managerservernode节点上安装二进制的mysql

#cd mysql4.1.13

#scripts/mysql_install_db --user=mysql (必须带目录执行,否则出错)

#chown -R root /opt/mysql4.1.13

#chgrp -R mysql /opt/mysql4.1.13

#chown -R mysql.mysql  /opt/mysql4.1.13/data

#cp support-files/mysql.server  /etc/rc.d/init.d/   配置mysql启动设置
#chmod +x  /etc/rc.d/init.d/mysql.server
#chkconfig --add mysql.server

3         配置servernote节点

192.168.0.160192.168.0.161机器上

# ./mysql –help    该命令可以查看mysql启动时是怎么寻找my.cnf文件的顺序。

Default options are read from the following files in the given order:

/etc/my.cnf    /usr/local/mysql-max-4.1.13/data/my.cnf    ~/.my.cnf

# cp support-files/my-medium.cnf data/my.cnf     mysql的配置文件考到data

Vi /usr/local/mysql-max-4.1.13-pc-linux-gnu-i686/data/my.cnf

[MYSQLD]

ndbcluster

ndb-connectstring=192.168.0.1

[MYSQL_CLUSTER]

ndb-connectstring=192.168.0.1

4         配置Management管理节点

192.168.0.1机器上

#mkdir /var/lib/mysql-cluster

#cd /var/lib/mysql-cluster

#vi config.ini

[NDBD DEFAULT]      # Options affecting ndbd processes on all data nodes:

NoOfReplicas=2      # Number of replicas

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

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

                    # For DataMemory and IndexMemory, we have used the

                    # default values. Since the "world" database takes up

                    # only about 500KB, this should be more than enough for

                    # this example Cluster setup.

 

[TCP DEFAULT]       # TCP/IP options:

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

                    # port that is free for all the hosts in cluster

                    # Note: It is recommended beginning with MySQL 5.0 that

                    # you do not specify the portnumber at all and simply allow

                    # the default value to be used instead

# Management process options(定义管理节点.

[NDB_MGMD]

hostname=192.168.0.1        # 管理节点Hostname or IP address of MGM node

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

# Options for data node "A"定义群集数据节点.

# (one [NDBD] section per data node)

[NDBD]

hostname=192.168.0.160      # 节点Hostname or IP address

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

# Options for data node "B"定义群集数据节点.

[NDBD]

hostname=192.168.0.161      # 节点Hostname or IP address

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

# SQL node options定义Sql server节点.

[MYSQLD]

hostname=192.168.0.100      # SQL节点Hostname or IP address

#datadir=/usr/local/mysql/data  # Directory for SQL node's datafiles

                    # (additional mysqld connections can be

                    # specified for this node for various

                    # purposes such as running ndb_restore)

[NDB_MGMD]:后面不能有任何注释信息,否则提示:

Error line 17: [TCP] Unknown parameter: [NDB_MGMD]   # Management process options

Error line 17: Could not parse name-value pair in config file.

[SHM]: Defines shared-memory connections between nodes. MySQL 4.1.9之前,这个功能必须使用--with-ndb-shm option编译进去, MySQL 4.1.9-max版本开始, it is enabled by default

5         启动mysql集群

5.1      初始化启动mysql集群服务

1)启动MysqlManagement管理节点(192.168.0.1

#ndb_mgmd -f /var/lib/mysql-cluster/config.ini

2)启动Data  Node节点(192.168.0.160,192.168.0.161)

#ndbd --initial

(注意:这个参数只能在第一次启动DataNode节点时使用,因为—initial参数会删除一些ndbd 实例先前创建的所有文件)

3)启动MysqlServer节点(192.168.0.100)

# ./mysql.server start

5.2      重启mysql集群服务

1)启动MysqlManagement管理节点(192.168.0.1

#ndb_mgmd -f /var/lib/mysql-cluster/config.ini

2)启动Data  Node节点(192.168.0.160,192.168.0.161)

#ndbd

3)启动MysqlServer节点(192.168.0.100)

# ./mysql.server start

(注意:Management管理节点和DataNote节点都不开启mysql服务,只有MysqlServer节点开启。The default port for Cluster management nodes is 1186; the default port for data nodes is 2202.)

6         测试集群的效果

6.1      在管理机上查看各节点运行状况

[root@Proxy bin]# ./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.0.160  (Version: 4.1.13, Nodegroup: 0, Master)

id=3    @192.168.0.161  (Version: 4.1.12, Nodegroup: 0)

 

[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.0.1  (Version: 4.1.13)

 

[mysqld(API)]   1 node(s)

id=4    @192.168.0.100  (Version: 4.1.12)

6.2      模拟写入一个数据库表,各MysqlServer节点是否能够同步

1)  在一个MysqlServer节点上创建数据库world和表,然后看看另一个MysqlServer节点是否也同样可以看到。

答:数据都相同

2)  拔掉一个DataNote节点网线,看看两台MysqlServer节点是否还能正常工作。

答:可以

3)  拔掉两台DataNote节点网线,查看一下MysqlServer节点是否还能正常工作。

答:所有MysqlServer都不能正常工作

7         附件:

以上文档参考mysql官方资料:http://dev.mysql.com/doc/mysql/en/ndbcluster.html

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有