ndbd:数据库节点" />
本文我们主要介绍了MySQL数据库集群实现负载均衡的安装配置工作,接下来我们就让我们一起来了解一下这部分内容。
MySQL数据库集群关系如下图:
class='fit-image' onload='javascript:if(this.width>498)this.width=498;' onmousewheel = 'javascript:return big(this)' alt="MySQL数据库集群实现负载均衡的安装配置详解" src="http://images.51cto.com/files/uploadimg/20110805/1550080.jpg" />
ndbd:数据库节点,物理数据实际存放位置。
mysqld:MySQL服务器节点。
ndbd_mgmd:管理节点。管理/查看各库节点和服务器节点的状态。程序直接访问的是这台机器的IP。默认端口仍是3306。
1.在ndb_mgmd、mysqld、Node A、Node B上安装MySQL5.0
安装目录:/usr/local/mysql
2.配置 Node A、Node B、mysqld:
- # cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
- # vi /etc/my.cnf 在文件尾加入 # my.cnf
- # example additions to my.cnf for MySQL Cluster
- # (valid in MySQL 5.0) # enable ndbcluster storage engine, and provide connectstring for
- # management Server host (default port is 1186)
- [mysqld]
- ndbcluster
- ndb-connectstring=192.168.56.30 # provide connectstring for management Server host (default port: 1186)
- [ndbd]
- connect-string=192.168.56.30 # provide connectstring for management Server host (default port: 1186)
- [ndb_mgm]
- connect-string=192.168.56.30 # provide location of cluster configuration file
- [ndb_mgmd]
- config-file=/var/lib/mysql-cluster
在Node A、Node B上创建日志文件夹
- # mkdir /var/lib/mysql-cluster
3.配置ndb_mgmd:
- # mkdir /var/lib/mysql-cluster
- # cd /var/lib/mysql-cluster
- # vi config.ini # file "config.ini" - 2 data nodes and 2 SQL nodes
- # This file is placed in the startup directory of ndb_mgmd (the
- # management server)
- # The first MySQL Server can be started from any host. The second
- # can be started only on the host mysqld_5.mysql.com [NDBD DEFAULT]
- NoOfReplicas= 2
- DataDir= /var/lib/mysql-cluster [NDB_MGMD]
- Hostname= 192.168.56.30
- DataDir= /var/lib/mysql-cluster [NDBD]
- HostName= 192.168.56.11 [NDBD]
- HostName= 192.168.56.12[MYSQLD]
- [MYSQLD]
- [MYSQLD]
4. 启动服务
- ndb_mgmd /usr/local/mysql/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
- Node A /usr/local/mysql/bin/ndbd --initial #只在第一次启动ndbd时使用--initial参数
- Node B /usr/local/mysql/bin/ndbd --initial
- mysqld /usr/local/mysql/support-files/mysql.server start检查工作状态
回到管理节点服务器Ndb_mgmd上,并启动管理终端:# /usr/bin/ndb_mgm
- ndb_mgm> show
- Cluster Configuration [ndbd(NDB)] 2 node(s)
- id=2 (not connected, accepting connect from 192.168.56.11)
- id=3 @192.168.56.12 (Version: 5.0.22, Nodegroup: 0, Master) [ndb_mgmd(MGM)] 1 node(s)
- id=1 @192.168.56.30 (Version: 5.0.22) [mysqld(API)] 3 node(s)
- id=4 @192.168.56.20 (Version: 5.0.22)
- id=5 (not connected, accepting connect from any host)
- id=6 (not connected, accepting connect from any host) mysqld(API)即mysqld --ndb-cluster,MySQL服务器节点,应该程序访问的IP。创建数据库(mysqld):
- # /usr/local/mysql/bin/mysql
- > use test;
- > CREATE TABLE ctest (i INT) ENGINE=NDBCLUSTER;
- > INSERT INTO ctest () VALUES (1);
关于MySQL数据库集群负载均衡的配置就介绍到这里了,希望本次的介绍能够对您有所收获!