快捷搜索:   nginx

Linux mysql 5.0 集群负载均衡架构

mysql 5.0 集群负载均衡   


ndbd:             数据库节点,物理数据实际存放位置。
:         MySQL服务器节点。
ndbd_mgmd:管理节点。管理/查看各库节点和服务器节点的状态。程序直接访问的是这台机器的IP。默认端口仍是3306。

1.ndb_mgmdmysqldNode ANode B上安装MySQL5.0

安装目录:/usr/local/mysql

2.配置 Node ANode Bmysqld
# 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 ANode 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);

顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论