一、介绍
这篇文档旨在介绍如何安装配置基于2台服务器的MySQL集群。并且实现任意一台服务器出现问题或宕机时MySql集群依然能够继续运行。
1.MySQL-Cluster简介
MySQL-Cluster主要有三种类型节点:
Data node,数据节点将保存数据库,它会自动复制所有的数据节点;
Daemon node,守护节点相当于是SQL数据库和客户端之间的接口,它提供从数据节点查询等操作,类似于"网关";
Management node,管理节点,用以监控和管理整个集群。
2.安装环境及软件包
2台PC机,通过VMWare创建虚拟机,然后安装操作系统
软件包:MySQL-Cluster-client-gpl-7.2.13-1.rhel5.i386.rpm
MySQL-Cluster-server-gpl-7.2.13-1.rhel5.i386.rpm
操作系统:Redhat.Enterprise.Linux.v5.UPDATE.7.X86.DVD-HOTiSO.iso
serverA:192.168.0.180
serverB:192.168.0.181
数据库管理节点:192.168.0.180,192.168.0.181
数据库数据节点:192.168.0.180,192.168.0.181
数据库SQL节点(API节点):192.168.0.180,192.168.0.181
二、在serverA和serverB上安装MySQL-cluster
以下步骤需要在serverA和serverB上各做一次
1.首先检查linux操作系统中是否安装了自带的mysql数据库
一般linux自带mysql版本都比较低一些,因此要安装比较新的版本需要先将自带的低版本卸载。
检查操作系统中是否安装了mysql的命令:rpm -qa |grep -i mysql
卸载mysql的命令:rpm -e mysqlXXXX
或者使用yum -remove mysqlXXX来删除,这样可以避免卸载过程中由于各个包之间的依赖造成卸载停止
2.创建mysql用户和组
groupadd mysql
useradd -g mysqlmysql
usermod-d /home/mysql mysql
3.将MySQL-Cluster上传到/home/mysql/目录下,开始安装MySQL-Cluster
[root@serverAsbin]# rpm -ivh MySQL-Cluster-server-gpl-7.2.13-1.rhel5.i386.rpm
InstallingMySQL system tables...
13102811:00:50 [Warning] Forcing shutdown of 3 plugins
OK
Fillinghelp tables...
13102811:00:50 [Warning] Forcing shutdown of 3 plugins
OK
To startmysqld at boot time you have to copy
support-files/mysql.serverto the right place for your system
PLEASEREMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so,start the server, then issue the following commands:
./bin/mysqladmin-u root password 'new-password'
./bin/mysqladmin-u root -h serverB password 'new-password'
Alternativelyyou can run:
./bin/mysql_secure_installation
whichwill also give you the option of removing the test
databasesand anonymous user created by default. This is
stronglyrecommended for production servers.
See themanual for more instructions.
You canstart the MySQL daemon with:
cd . ;./bin/mysqld_safe &
You cantest the MySQL daemon with mysql-test-run.pl
cd./mysql-test ; perl mysql-test-run.pl
Pleasereport any problems with the ./bin/mysqlbug script!
Thelatest information about MySQL is available at http://www.mysql.com/
SupportMySQL by buying support/licenses from http://shop.mysql.com/
[root@serverAsbin]# rpm -ivh MySQL-Cluster-client-gpl-7.2.13-1.rhel5.i386.rpm
Preparing... ########################################### [100%]
1:MySQL-Cluster-client-gp ###########################################[100%]
4.安装完成之后创建连接
#ln -s /usr/sbin/ndbd /usr/bin
#ln -s /usr/sbin/ndb_mgmd /usr/bin
#ln -s /usr/sbin/mysqld /usr/bin
三、安装并配置节点
以下步骤需要在serverA和serverB上各做一次
1.配置管理节点配置文件
# mkdir /var/lib/mysql-cluster
# cd/var/lib/mysql-cluster
# vi config.ini
在config.ini中添加如下内容:
[ndbd default]
NoOfReplicas= 2
MaxNoOfConcurrentOperations=10000
# Amount of memoryrequired=(SizeofDatabase * NumberOfReplicas * 1.1 ) / NumberOfDataNodes
DataMemory= 128M
IndexMemory= 24M
TimeBetweenWatchDogCheck=30000
DataDir=/usr/local/mysql/data
MaxNoOfOrderedIndexes=512
StartPartialTimeout=100
StartPartitionedTimeout=100