一、介绍
这篇文档旨在介绍如何安装配置基于3台服务器的MySQL集群。并且实现任意一台服务器出现问题或宕机时MySQL集群依然能够继续运行。
1. MySQL-Cluster简介
MySQL-Cluster主要有三种类型节点:
NDB node,数据节点将保存数据库,它会自动复制所有的数据节点;
SQL node,守护节点相当于是SQL数据库和客户端之间的接口,它提供从数据节点查询等操作,类似于"网关";
Management node,管理节点,用以监控和管理整个集群。
-------------------------------此处插图----------------------------
2.安装环境及软件包
3台华为RH2285服务器——其中两台(16颗CPU、96G内存、500G磁盘阵列)作为NDB节点和SQL节点服务器,另一台服务器16颗CPU、32G内存作为管理节点
软件包:MySQL-Cluster-client-gpl-7.2.13-1.rhel5.x86_64.rpm
MySQL-Cluster-server-gpl-7.2.13-1.rhel5.x86_64.rpm
MySQL-Cluster-devel-gpl-7.2.13-1.rhel5.x86_64.rpm
MySQL-Cluster-embedded-gpl-7.2.13-1.rhel5.x86_64.rpm
MySQL-Cluster-shared-compat-gpl-7.2.13-1.rhel5.x86_64.rpm
MySQL-Cluster-shared-gpl-7.2.13-1.rhel5.x86_64.rpm
操作系统:RedHat.Enterprise.Linux.v5.UPDATE.7.X86_64.DVD-HOTiSO.iso
服务器hostname和IP地址:
db1 172.16.1.74
db2 172.16.1.75
demo 172.16.1.78
数据库规划:
数据库管理节点(ndb_mgmd):172.16.1.78
数据库数据节点(NDB):172.16.1.74,172.16.1.75
数据库SQL节点(API节点):172.16.1.74,172.16.1.75
二、在db1和db2上安装MySQL-cluster
以下步骤需要在db1和db2上各做一次
1.首先检查linux操作系统中是否安装了自带的mysql数据库
一般linux自带mysql版本都比较低一些,因此要安装比较新的版本需要先将自带的低版本卸载。
检查操作系统中是否安装了mysql的命令:
rpm -qa |grep -i mysql
卸载mysql的命令:rpm -e mysqlXXXX
或者使用yum -remove mysqlXXX来删除,这样可以避免卸载过程中由于各个包之间的依赖造成卸载停止
2.创建mysql用户和组
groupadd mysql
useradd -g mysql mysql
usermod -d /home/mysql mysql
3.将MySQL-Cluster上传到/home/mysql/目录下,开始安装MySQL-Cluster
[root@db1 sdd]# rpm -ivh MySQL-Cluster-server-gpl-7.2.14-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-Cluster-server-gp########################################### [100%]
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h db1 password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
[root@db1 sbin]# rpm -ivh MySQL-Cluster-client-gpl-7.2.13-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-Cluster-client-gp ########################################### [100%]
依次完成MySQL-Cluster-devel-gpl-7.2.13-1.rhel5.x86_64.rpm
MySQL-Cluster-embedded-gpl-7.2.13-1.rhel5.x86_64.rpm
MySQL-Cluster-shared-compat-gpl-7.2.13-1.rhel5.x86_64.rpm
MySQL-Cluster-shared-gpl-7.2.13-1.rhel5.x86_64.rpm
的安装
4.安装完成之后创建连接
ln -s /usr/sbin/ndbd /usr/bin
ln -s /usr/sbin/ndb_mgmd /usr/bin
ln -s /usr/sbin/mysqld /usr/bin
#ln -s /usr/local/lib/mysqlmanager /usr/bin ---这个在7.2.13版本上不需要
管理节点服务器demo(172.16.1.78)上只安装MySQL-Cluster-server-gpl-7.2.13-1.rhel5.x86_64.rpm即可
三、安装并配置节点
1.配置管理节点(172.16.1.78)配置文件
# mkdir /var/lib/mysql-cluster
# cd /var/lib/mysql-cluster
# vi config.ini
在config.ini中添加如下内容:
[ndbd default]
NoOfReplicas= 2
MaxNoOfConcurrentOperations= 500000
MaxNoOfLocalOperations=500000
MaxNoOfConcurrentTransactions=500000
MaxNoOfConcurrentIndexOperations=50000
# Amount of memory required=(SizeofDatabase * NumberOfReplicas * 1.1 ) / NumberOfDataNodes
DataMemory= 49152M
IndexMemory= 6144M
TimeBetweenWatchDogCheck= 30000
DataDir=/var/lib/mysql/data
MaxNoOfAttributes=500000
MaxNoOfTables=1000
MaxNoOfOrderedIndexes= 512
#StartPartialTimeout=100
#StartPartitionedTimeout=100
#ArbitrationTimeout=5000
#MaxNoOfFiredTriggers=8000
#TransactionBufferMemory=5M
TransactionDeadlockDetectionTimeout=90000
HeartbeatIntervalDbDb=5000
#StopOnError=1