一、环境说明: CentOS6.3(32位) + MySQL Cluster 7.3.5,规划5台机器,资料如下:
节点分布情况:
MGM:192.168.137.101
NDBD1:192.168.137.102
NDBD2:192.168.137.103
SQL1:192.168.137.104
SQL2:192.168.137.105
二、下载安装包:
主要有三种类型的安装包:1:rpm安装包;2:预编译二进制安装包; 3:源码包。 这里选择第二种安装包“预编译二进制安装包”,它只需要解压即可。
先官网下载页面 http://dev.mysql.com/downloads/cluster/ ,选择 Linux - Generic 下面的 mysql-cluster-gpl-7.3.5-linux-glibc2.5-i686.tar.gz 这个安装包!
注意:我的CentOS是32位的,如果是64位系统则应该下载64位的安装包 mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64.tar.gz 。
三、环境清理(在各台服务器上都要执行)
清除MySQL旧版本:
首先使用如下命令来清理之前操作系统自带的MySQL安装:
yum -y remove mysql
然后使用如下命令:
[root@localhost src]# rpm -qa | grep mysql* mysql-libs-5.1.61-4.el6.i686 apr-util-mysql-1.3.9-3.el6_0.1.i686
对于找到的2个剩余MySQL包,按照如下的命令格式予以删除:
rpm -e --nodeps mysql-libs-5.1.61-4.el6.i686 rpm -e --nodeps apr-util-mysql-1.3.9-3.el6_0.1.i686
四、软件准备(在各台服务器上都要执行)
4.1 将 mysql-cluster-gpl-7.3.5-linux-glibc2.5-i686.tar.gz 上传到各服务器的某个目录下(如 /usr/local/src ) 下面,然后解压并移到 /usr/local/mysql 目录下
tar -xzvf /usr/local/src/mysql-cluster-gpl-7.3.5-linux-glibc2.5-i686.tar.gz mv /usr/local/src/mysql-cluster-gpl-7.3.5-linux-glibc2.5-i686/* /usr/local/mysql
4.2 新建mysql用户及用户组:
groupadd mysql
useradd -g mysql -s /usr/sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql
4.3 安装 My Cluster:
cd /usr/local/mysql ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
4.4 关闭防火墙(IPTABLES)与 selinux
# 关闭防火墙
chkconfig iptables off
# 关闭 selinux
vim /etc/selinux/config #(改为SELINUX=disabled)保存退出,
# 重启服务器
init 6
五、配置节点
5.1 配置管理节点(192.168.137.101)
# 删除自带的 /etc/my.cnf 【切记:一定要删除掉! 因为ndb_mgmd启动的时候,也会加上/etc/my.cnf的配置内容,干扰我们,所以要删除它】
rm -rf /etc/my.cnf
# 新建配置文件存放目录
mkdir /usr/local/mysql/etc chown mysql:mysql /usr/local/mysql/etc
# 创建配置文件 config.ini
vim /usr/local/mysql/etc/config.ini
# config.ini内容如下:
[ndb_mgmd default]
datadir = /usr/local/mysql/data[ndbd default]
NoOfReplicas = 2
DataMemory = 80M
IndexMemory = 18M
datadir = /usr/local/mysql/data[ndb_mgmd]
NodeId = 1
HostName = 192.168.137.101[ndbd]
NodeId = 11
HostName = 192.168.137.102[ndbd]
NodeId = 12
HostName = 192.168.137.103[mysqld]
NodeId = 81
HostName = 192.168.137.104[mysqld]
NodeId = 82
HostName = 192.168.137.105
5.2 配置数据节点(192.168.137.102、192.168.137.103)
# 修改配置文件
vim /etc/my.cnf
# my.cnf内容如下:
[mysqld]
ndbcluster
ndb-connectstring = 192.168.137.101[mysql_cluster]
ndb-connectstring = 192.168.137.101
5.3 配置SQL节点(192.168.137.104、192.168.137.105)
# 拷贝文件
\cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# 修改配置文件
vim /etc/my.cnf
# my.cnf内容如下:
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/datandbcluster
ndb-connectstring = 192.168.137.101[mysql_cluster]
ndb-connectstring = 192.168.137.101
六、启动节点
启动需要按照如下顺序进行:
Management Node > Data Node > SQL Node
6.1 启动管理节点(192.168.137.101)
# --initial 首次加载、/usr/local/mysql/etc/config.ini文件有改变,其它时候不要加,除非是在备份、恢复或配置变化后重启时,其他时候不要加,不然数据就清空。。。
/usr/local/mysql/bin/ndb_mgmd -f /usr/local/mysql/etc/config.ini --initial
# 正常启动方式
/usr/local/mysql/bin/ndb_mgmd -f /usr/local/mysql/etc/config.ini
其他常用操作:
#查看ndb_mgmd是否启动
[root@localhost mysql]# ps -ef | grep ndb_mgmd root 2948 1 1 23:47 ? 00:00:03 /usr/local/mysql/bin/ndb_mgmd -f /usr/local/mysql/etc/config.ini root 2984 2073 0 23:52 pts/0 00:00:00 grep ndb_mgmd [root@localhost mysql]#
#ndb_mgmd默认启动 1186 端口
[root@localhost mysql]# netstat -ntlp | grep ndb_mgmd tcp 0 0 0.0.0.0:1186 0.0.0.0:* LISTEN 2948/ndb_mgmd [root@localhost mysql]#
#查看集群状态
[root@localhost mysql]# /usr/local/mysql/bin/ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> show Connected to Management Server at: localhost:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=11 (not connected, accepting connect from 192.168.137.102) id=12 (not connected, accepting connect from 192.168.137.103) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.137.101 (mysql-5.6.17 ndb-7.3.5) [mysqld(API)] 3 node(s) id=81 (not connected, accepting connect from 192.168.137.104) id=82 (not connected, accepting connect from 192.168.137.105) id=83 (not connected, accepting connect from any host)
6.2 启动数据节点(192.168.137.102、192.168.137.103)
# 只是在第一次启动或在备份/恢复或配置变化后重启ndbd时,才加–initial参数!
/usr/local/mysql/bin/ndbd --initial
# 正常启动方式
/usr/local/mysql/bin/ndbd
# 查看 ndbd 启动状态
[root@localhost ~]# ps -ef | grep ndbd root 2373 1 0 18:11 ? 00:00:00 /usr/local/mysql/bin/ndbd root 2377 1985 0 18:11 pts/0 00:00:00 grep ndbd
6.3 启动SQL节点(192.168.137.104、192.168.137.105)
# 启动 SQL 节点
service mysqld start
# 关闭 SQL 节点
service mysqld stop
# 重启 SQL 节点
service mysqld restart
# 检验mysql是否运行
service mysqld status
# 为sql指定密码
/usr/local/mysql/bin/mysqladmin -u root password 'new-password' /usr/local/mysql/bin/mysqladmin -u root -h 'host' password 'new-password'
# 启动命令行窗口
/usr/local/mysql/bin/mysql -u root –p
参考:
【rpm安装】MySQL_Cluster_7.2.5_配置实例_v1.2
MySQL Cluster 7.2集群部署配置
MySQL Cluster集群配置与安装
【推荐】MySQL Cluster7.2.4初步安装部署新特性性能测试等
延伸阅读: