MySQL Cluster 安装与配置

MySQL Cluster 安装与配置

1.  安装前准备

1.1本文MySQL集群结构

服务器

开启的服务

角色

192.168.100.5

server5.domain

ndb_mgmd

ndb_mgm

管理节点

(master)

192.168.100.7

server7.domain

ndb_mgmd

ndb_mgm

管理节点

(master)

192.168.100.8

server8.domain

mysqld

ndbd

MySQL API

数据节点

192.168.100.9

server9.domain

mysqld

ndbd

MySQL API

数据节点

192.168.100.10

server10.domain

mysqld

ndbd

MySQL API

数据节点

192.168.100.11

server11.domain

mysqld

ndbd

MySQL API

数据节点

192.168.100.12

server12.domain

mysqld

ndbd

MySQL API

数据节点

192.168.100.13

server13.domain

mysqld

ndbd

MySQL API

数据节点

192.168.100.14

server14.domain

mysqld

ndbd

MySQL API

数据节点

192.168.100.15

server15.domain

mysqld

ndbd

MySQL API

数据节点

 

1.2软件下载

官网 http://dev.mysql.com/downloads/mysql/5.0.html下载MySQL5.0版本,注意下载与系统CPU和操作系统相符合的版本。本文所用的机器的CPUIntel EM64T,操作系统为CentOS5.2。我MySQL Cluster下载的是5.0.83社区版本:

MySQL-client-community-5.0.83-0.rhel5.x86_64.rpm(mysql客户端)

  • The standard MySQL client programs. You probably always want to install this package.

MySQL-clusterextra-community-5.0.83-0.rhel5.x86_64.rpm

/usr/share/man/man1/ndb_cpcd.1.gz

/usr/share/man/man1/ndb_delete_all.1.gz

/usr/share/man/man1/ndb_drop_index.1.gz

/usr/share/man/man1/ndb_drop_table.1.gz

MySQL-clustermanagement-community-5.0.83-0.rhel5.x86_64.rpm(ndb_mgmd)

  • Packages that contain additional files for MySQL Cluster installations. These are platform-specific RPMs, in contrast to the platform-independent ndb-xxx RPMs

MySQL-clusterstorage-community-5.0.83-0.rhel5.x86_64.rpm(ndbd)

MySQL-clustertools-community-5.0.83-0.rhel5.x86_64.rpm(ndb_mgm)

  • The MySQL-clustertools RPM requires a working installation of perl and the DBI and HTML::Template packages.

 

MySQL-community-debuginfo-5.0.83-0.rhel5.x86_64.rpm

  • This package contains debugging information. debuginfo RPMs are never needed to use MySQL software; this is true both for the server and for client programs. However, they contain additional information that might be needed by a debugger to analyze a crash.

MySQL-devel-community-5.0.83-0.rhel5.x86_64.rpm

  • The libraries and include files that are needed if you want to compile other MySQL clients, such as the Perl modules.

MySQL-server-community-5.0.83-0.rhel5.x86_64.rpm(MYSQL API)

  • The MySQL server. You need this unless you only want to connect to a MySQL server running on another machine.

 

MySQL-shared-community-5.0.83-0.rhel5.x86_64.rpm

  • This package contains the shared libraries (libmysqlclient.so*) that certain languages and applications need to dynamically load and use MySQL. It contains single-threaded and thread-safe libraries. If you install this package, do not install the MySQL-shared-compat package.

MySQL-shared-compat-5.0.83-0.rhel5.x86_64.rpm

  • This package includes the shared libraries for MySQL 3.23, 4.0, and so on, up to the current release. It contains single-threaded and thread-safe libraries. Install this package instead of MySQL-shared if you have applications installed that are dynamically linked against older versions of MySQL but you want to upgrade to the current version without breaking the library dependencies.

MySQL-test-community-5.0.83-0.rhel5.x86_64.rpm

  • This package includes the MySQL test suite

 

下面两个perl包需要下载(www.rpmfind.com

perl-DBD-mysql-4.012-1.el5.rf

perl-Class-DBI-mysql-1.00-1.el5.rf

perl-HTML-Template - 2.9-1.el5.rf.noarch

 

1.3关掉防火墙或类似功能软件(SELinux

1.4检查主机名

(1)设定主机名:

#vi /etc/sysconfig/network(永久改变主机名)

Hostname=xxx

:wq

#hostname XXX(即时改变主机名)

(2)保证集群内主机可通过hostnameping

#vi /etc/hosts

#格式:[ip] [hostname]

192.168.100.5 server5.domain

192.168.100.7 server7.domain

2.  MySQL Cluster安装

common安装:(不管哪种节点都必须安装)

MySQL-shared-community-5.0.83-0.rhel5.x86_64.rpm

perl-DBD-mysql-4.012-1.el5.rf

perl-Class-DBI-mysql-1.00-1.el5.rf

perl-HTML-Template - 2.9-1.el5.rf.noarch

 

管理节点最小安装:

MySQL-clustermanagement-community-5.0.83-0.rhel5.x86_64.rpm(ndb_mgmd)

MySQL-clustertools-community-5.0.83-0.rhel5.x86_64.rpm(ndb_mgm)

 

数据节点最小安装:

MySQL-clusterstorage-community-5.0.83-0.rhel5.x86_64.rpm(ndbd)

 

SQL节点最小安装

MySQL-client-community-5.0.83-0.rhel5.x86_64.rpm(mysql客户端)

MySQL-server-community-5.0.83-0.rhel5.x86_64.rpm(MYSQL API)

 

注:安装过程如果存在依赖关系,使用yum install 包名 –nogpgcheck

    MySQL-server安装后关闭mysqld#service mysql stop

 

3.  MySQL Cluster配置

3.1 每台机器上#mkdir /usr/share/mysql-cluster –p

3.2管理节点配置文件#vi /usr/share/mysql-cluster/config.ini

[NDBD DEFAULT]

NoOfReplicas=2

DataMemory=800M

IndexMemory=180M

 

[NDB_MGMD DEFAULT]

DataDir=/usr/share/mysql-cluster

[TCP DEFAULT]

[NDB_MGMD]

ID=1

HostName=192.168.100.5

[NDB_MGMD]

ID=2

HostName=192.168.100.6

[NDBD]

HostName=192.168.100.7

DataDir=/usr/share/mysql-cluster/

[NDBD]

HostName=192.168.100.8

DataDir=/usr/share/mysql-cluster/

[NDBD]

HostName=192.168.100.9

DataDir=/usr/share/mysql-cluster/

[NDBD]

HostName=192.168.100.10

DataDir=/usr/share/mysql-cluster/

[NDBD]

HostName=192.168.100.11

DataDir=/usr/share/mysql-cluster/

[NDBD]

HostName=192.168.100.12

DataDir=/usr/share/mysql-cluster/

[NDBD]

HostName=192.168.100.13

DataDir=/usr/share/mysql-cluster/

[NDBD]

HostName=192.168.100.14

DataDir=/usr/share/mysql-cluster/

# one [MYSQLD] per storage node

[MYSQLD]

HostName=192.168.100.7

[MYSQLD]

HostName=192.168.100.8

[MYSQLD]

HostName=192.168.100.9

[MYSQLD]

HostName=192.168.100.10

[MYSQLD]

HostName=192.168.100.11

[MYSQLD]

HostName=192.168.100.12

[MYSQLD]

HostName=192.168.100.13

[MYSQLD]

HostName=192.168.100.14

 

3.3 mysqldndbdndb_mgm连接管理节点配置#vi /etc/my.cnf

# Options for mysqld process:

 

[mysqld]

 

Datadir=/var/lib/mysql-cluster

 

ndbcluster                      # run NDB storage engine

 

ndb-connectstring=192.168.100.5,192.168.100.6  # location of management server

 

 

 

# Options for ndbd and ndb_mgm process:

 

[mysql_cluster]

 

ndb-connectstring=192.168.100.5,192.168.100.6  # location of management server

 

4.  MySQL Cluster启动与测试

4.1 启动顺序

管理节点-->数据节点-->SQL节点

管理节点启动:#ndb_mgmd -f /u       sr/share/mysql-cluster/config.ini

数据节点启动: #ndbd --initial(通过/etc/my.cnf连接管理节点)

SQL节点启动: #/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf#service mysql start

4.2     测试

#ndb_mgm(注意该命令也是默认通过/etc/my.cnf连接管理节点)

Connected to Management Server at: 192.168.100.5:1186

Cluster Configuration

---------------------

[ndbd(NDB)]     8 node(s)

id=3    @192.168.100.15  (Version: 5.0.83, Nodegroup: 0, Master)

id=4    @192.168.100.8  (Version: 5.0.83, Nodegroup: 0)

id=5    @192.168.100.9  (Version: 5.0.83, Nodegroup: 1)

id=6    @192.168.100.10  (Version: 5.0.83, Nodegroup: 1)

id=7    @192.168.100.11  (Version: 5.0.83, Nodegroup: 2)

id=8    @192.168.100.12  (Version: 5.0.83, Nodegroup: 2)

id=9    @192.168.100.13  (Version: 5.0.83, Nodegroup: 3)

id=10   @192.168.100.14  (Version: 5.0.83, Nodegroup: 3)

 

[ndb_mgmd(MGM)] 2 node(s)

id=1    @192.168.100.5  (Version: 5.0.83)

id=2    @192.168.100.7  (Version: 5.0.83)

 

[mysqld(API)]   8 node(s)

id=11   @192.168.100.15  (Version: 5.0.83)

id=12   @192.168.100.8  (Version: 5.0.83)

id=13   @192.168.100.9  (Version: 5.0.83)

id=14   @192.168.100.10  (Version: 5.0.83)

id=15   @192.168.100.11  (Version: 5.0.83)

id=16   @192.168.100.12  (Version: 5.0.83)

id=17   @192.168.100.13  (Version: 5.0.83)

id=18   @192.168.100.14  (Version: 5.0.83)

以上说明一切正常。

将服务增加到开机启动服务项中:

server5.domain/server7.domain:

echo 'ndb_mgmd -f /usr/share/mysql-cluster/config.ini' > /etc/rc.d/init.d/ndb_mgmd
chmod 755 /etc/rc.d/init.d/ndb_mgmd

server8.domain-server15.domain:

echo 'ndbd' > /etc/rc.d/init.d/ndbd

chmod 755 /etc/rc.d/init.d/ndbd

chkconfig --level 2345 ndbd on(ndbd 服务不支持 chkconfig)

OK,到此mysql cluster 配置完成。

强调:

1)由于数据放在内存中,需要在ndb节点上加大内存的数量。按照11.1的比例,如果数据量达到3.6GB,需要4GB的内存。

查看server8上的数据大小:

[root@sql2 ~]# cd /var/lib/mysql-cluster/ndb_4_fs/

[root@sql2 ndb_4_fs]# du -lh

1.3GB

连接API创建数据库:

以下操作在8API上都需要操作:

# mysql 

mysql> create database testdatabase;

mysql> grant all on *.* to t8@”192.168.100.%” identified by “t8”;

mysql> flush privileges;

mysql> create table test(int (1));

mysql> insert into test(1);

mysql> quit;

以上做完以后,可以通过任意一台API上创建表,并写数据到表中,其他数据库都会同步写入。

分别连接每台服务器进行检查:

# mysql

mysql> use testdatabase;

mysql> select * from test;

如果输出结果完全相同,表明mysql cluster已经可以正常工作了。

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值