MySQL Cluster 7.3.5 集群配置实例(入门篇)

一、环境说明: 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安装:

1 yum -y remove mysql

然后使用如下命令:

1 [root@localhost src]# rpm -qa | grep mysql*
2 mysql-libs-5.1.61-4.el6.i686
3 apr-util-mysql-1.3.9-3.el6_0.1.i686

对于找到的2个剩余MySQL包,按照如下的命令格式予以删除:

1 rpm  -e  --nodeps  mysql-libs-5.1.61-4.el6.i686
2 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 目录下

1 tar  -xzvf   /usr/local/src/mysql-cluster-gpl-7.3.5-linux-glibc2.5-i686.tar.gz
2 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:

1 cd /usr/local/mysql
2 ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

4.4 关闭防火墙(IPTABLES)与 selinux

# 关闭防火墙

1 chkconfig iptables off

# 关闭 selinux

1 vim /etc/selinux/config  #(改为SELINUX=disabled)保存退出,

# 重启服务器

1 init 6

 

五、配置节点

5.1 配置管理节点(192.168.137.101)

# 删除自带的 /etc/my.cnf  【切记:一定要删除掉! 因为ndb_mgmd启动的时候,也会加上/etc/my.cnf的配置内容,干扰我们,所以要删除它】

1 rm -rf /etc/my.cnf

# 新建配置文件存放目录

1 mkdir /usr/local/mysql/etc
2 chown mysql:mysql /usr/local/mysql/etc

# 创建配置文件 config.ini

1 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)

# 修改配置文件

1 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)

# 拷贝文件

1 \cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

# 修改配置文件

1 vim /etc/my.cnf

# my.cnf内容如下:

[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data

ndbcluster
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文件有改变,其它时候不要加,除非是在备份、恢复或配置变化后重启时,其他时候不要加,不然数据就清空。。。

1 /usr/local/mysql/bin/ndb_mgmd  -f  /usr/local/mysql/etc/config.ini --initial

# 正常启动方式

1 /usr/local/mysql/bin/ndb_mgmd  -f  /usr/local/mysql/etc/config.ini

 

其他常用操作:

#查看ndb_mgmd是否启动

1 [root@localhost mysql]# ps -ef | grep ndb_mgmd
2 root      2948     1  1 23:47 ?        00:00:03 /usr/local/mysql/bin/ndb_mgmd -f /usr/local/mysql/etc/config.ini
3 root      2984  2073  0 23:52 pts/0    00:00:00 grep ndb_mgmd
4 [root@localhost mysql]#

#ndb_mgmd默认启动 1186 端口

1 [root@localhost mysql]# netstat -ntlp | grep ndb_mgmd
2 tcp        0      0 0.0.0.0:1186                0.0.0.0:*                   LISTEN      2948/ndb_mgmd      
3 [root@localhost mysql]#

#查看集群状态

01 [root@localhost mysql]# /usr/local/mysql/bin/ndb_mgm
02 -- NDB Cluster -- Management Client --
03 ndb_mgm> show
04 Connected to Management Server at: localhost:1186
05 Cluster Configuration
06 ---------------------
07 [ndbd(NDB)]    2 node(s)
08 id=11 (not connected, accepting connect from 192.168.137.102)
09 id=12 (not connected, accepting connect from 192.168.137.103)
10  
11 [ndb_mgmd(MGM)]    1 node(s)
12 id=1    @192.168.137.101  (mysql-5.6.17 ndb-7.3.5)
13  
14 [mysqld(API)]    3 node(s)
15 id=81 (not connected, accepting connect from 192.168.137.104)
16 id=82 (not connected, accepting connect from 192.168.137.105)
17 id=83 (not connected, accepting connect from any host)

 

6.2 启动数据节点(192.168.137.102、192.168.137.103)

# 只是在第一次启动或在备份/恢复或配置变化后重启ndbd时,才加–initial参数!

1 /usr/local/mysql/bin/ndbd --initial

# 正常启动方式

1 /usr/local/mysql/bin/ndbd

# 查看 ndbd 启动状态

1 [root@localhost ~]# ps -ef | grep ndbd
2 root      2373     1  0 18:11 ?        00:00:00 /usr/local/mysql/bin/ndbd
3 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 节点

1 service mysqld start

# 关闭 SQL 节点

1 service mysqld stop

# 重启 SQL 节点

1 service mysqld restart

# 检验mysql是否运行

1 service mysqld status

# 为sql指定密码

1 /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
2  
3 /usr/local/mysql/bin/mysqladmin -u root -h 'host' password 'new-password'

# 启动命令行窗口

1 /usr/local/mysql/bin/mysql -u root –p

 

 

原文地址:http://blog.snsgou.com/post-366.html

你可能感兴趣的:(mysql)