一、环境
虚拟机:vmware work station 8.0.4
安装3台linux服务器:Red Hat rhel-5.1-server-i386-dvd.iso(虚拟机安装一台后,其他用vmware拷贝2份)
本机环境:windows 7,安装客户端SSH Secure Shell Client 3.2.9
mysql软件直接从官网下载的mysql-cluster-gpl-7.2.10-linux2.6-i686.tar.gz,通过ssh传输到3台linux虚拟机上面
二、安装linux服务器
具体安装步骤不介绍了,安装完成后关闭不用的服务,自由选择,备注,一定要关闭xend服务,否则虚拟机不能同时启动,报错
chkconfig sendmail off
chkconfig bluetooth off
chkconfig ip6tables off
chkconfig iptables off
chkconfig xend off
chkconfig cups off
chkconfig
vi /etc/selinux/config 设置SELINUX=disabled
三、集群安装工艺
由于个人模拟集群,如果跑太多虚拟机时间长点实在太卡,所以只能选择双机集群,共需3台机器
管理节点:192.168.142.2
数据节点and SLQ节点:192.168.142.3
数据节点and SLQ节点:192.168.142.129
确保互通,另关闭iptalbes,否则需要单独设置,默认影响集群1186端口服务
网上流传版本多介于mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz
此版本是mysql很早的版本了,很多新特性不支持,但是是标准版,server版,max版做集群,现在都是用cluster作为集群版本了,对应mysql-5.5.29,下面介绍具体安装方法:
1)在3台机器上均执行如下操作,创建Mysql用户,权限处理,上面的安装包均放至/usr/local目录下通过tar zxvf命令解压
# cd /usr/local/
# groupadd mysql
# useradd -g mysql mysql
# mv mysql-cluster-gpl-7.2.10-linux2.6-i686 mysql
# chown -R mysql:mysql /usr/local/mysql
2)配置管理节点
[root@song-PC bin]# cp /usr/local/mysql/bin/ndb_mgmd /usr/bin
[root@song-PC bin]# cp /usr/local/mysql/bin/ndb_mgm /usr/bin
chmod +x ndb_mg*
建立配置文件
# mkdir /var/lib/mysql-cluster
# cd /var/lib/mysql-cluster
# vi config.ini
编写如下内容
[NDBD DEFAULT]
NoOfReplicas=2
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
DataDir= /var/lib/mysql-cluster
# Managment Server
[NDB_MGMD]
HostName=192.168.142.2# manage_server_ip
# Storage Engines
[NDBD]
HostName=192.168.142.3
DataDir= /var/lib/mysql-cluster
[NDBD]
HostName=192.168.142.129
DataDir=/var/lib/mysql-cluster
[MYSQLD]
HostName=192.168.142.3
[MYSQLD]
HostName=192.168.142.129
[MYSQLD]
[MYSQLD]
[tcp default]
启动管理节点/usr/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
#/usr/bin/ndb_mgm
输入show可以查看集群各节点状态
3)配置数据节点
[root@song-VPC2 ~]# cd /usr/local/mysql/
[root@song-VPC2 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@song-VPC2 mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@song-VPC2 mysql]# chkconfig --add mysqld
[root@song-VPC2 mysql]# scripts/mysql_install_db --user=mysql
此时提示Installing MySQL system tables...
编辑vi /etc/my.cnf
[mysqld]
ndbcluster
ndb-connectstring=192.168.142.2
[mysql_cluster]
ndb-connectstring=192.168.142.2
保存退出
[root@song-VPC2 mysql]# mkdir /var/lib/mysql-cluster
4)启动数据节点
cd /var/lib/mysql-cluster/
[root@song-VPC2 mysql-cluster]# /usr/local/mysql/bin/ndbd --initial #第一次启动加initial参数
5)启动sql节点
[root@song-VPC2 mysql-cluster]# /etc/rc.d/init.d/mysqld start
提示Starting MySQL.........
时间稍微长点2分钟左右,ok正常
6)管理节点维护
[root@song-PC ~]# /usr/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=2 @192.168.142.3 (mysql-5.5.29 ndb-7.2.10, starting, Nodegroup: 0)
id=3 (not connected, accepting connect from 192.168.142.129)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.142.2 (mysql-5.5.29 ndb-7.2.10)
[mysqld(API)] 4 node(s)
id=4 (not connected, accepting connect from 192.168.142.3)
id=5 (not connected, accepting connect from 192.168.142.129)
id=6 (not connected, accepting connect from any host)
id=7 (not connected, accepting connect from any host)
更新config.ini(更换节点ip)后需要重启管理节点
step 1:停止
ndb_mgm> 1 stop
Node 1 has shutdown.
Disconnecting to allow Management Server to shutdown
step 2:重新加载
shell> /usr/local/mysql/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini --reload
MySQL Cluster Management Server mysql-5.5.22 ndb-7.2.6
step 3:重启数据节点
ndb_mgm> 2 restart
Node 2: Node shutdown initiated
Node 2: Node shutdown completed, restarting, no start.
Node 2 is being restarted
ndb_mgm> 3 restart
Node 3: Node shutdown initiated
Node 3: Node shutdown completed, restarting, no start.
Node 3 is being restarted
如果数据节点处于starting状态,是不能1 stop的,需要在数据节点执行ps -ef|grep ndbd,找到进程kill掉
7)问题备注:
已解决:mysql运行期间如果修改hostname可能导致mysql服务不能启动也不能停止
[root@song-VPC1 mysql-cluster]# service mysqld status
/etc/init.d/mysqld: line 363: test: 4362: binary operator expected
MySQL is running but PID file could not be found [FAILED]
待解决:管理节点重启后如果从新启动管理服务,需要过几分钟数据节点才能链接
在此过程中,数据节点同时连接总会掉线,报错如下:
ndb_mgm> Node 3: Forced node shutdown completed. Occured during startphase 0. Initiated by signal 11.
如果是kill掉的,会提示Initiated by signal 9.
为什么会自动掉?负载过大还是bug?这个不太清楚
8)测试在数据节点1 create database可以和节点2同步,至此安装完成