一、MYSQL集群节点的分布情况
Management Node
MGM1:192.168.0.51
MGM2:192.168.0.52
SQL Node
SQL1:192.168.0.53
SQL2:192.168.0.54
Data Node
NDBD1:192.168.0.55
NDBD2:192.168.0.56
===================================================================
二、安装并配置Data Node
1)安装Data Node1
[root@NDBD1 ~]#tar zxvf mysql-cluster-gpl-7.0.13-linux-i686-glibc23.tar.gz -C /usr/local/;
[root@NDBD1 ~]#cd /usr/local
[root@NDBD1 local]#mv mysql-cluster-gpl-7.0.13-linux-i686-glibc23 mysql
[root@NDBD1 local]#useradd mysql
[root@NDBD1 local]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@NDBD1 local]#chown -R mysql:mysql /usr/local/mysql
[root@NDBD1 local]#cd /usr/local/mysql
[root@NDBD1 mysql]#scripts/mysql_install_db --user=mysql
[root@NDBD1 mysql]#chown -R root:mysql .
[root@NDBD1 mysql]#chown -R mysql:mysql ./data
2)配置Data Node1
[root@NDBD1 mysql]# cat > /etc/hosts
192.168.0.51 MGM1
192.168.0.52 MGM2
192.168.0.53 SQL1
192.168.0.54 SQL2
192.168.0.55 NDBD1
192.168.0.56 NDBD2
[root@NDBD1 mysql]# vi ~/.bashrc
alias PS='ps aux | grep ndbd | grep -v grep'
[root@NDBD1 mysql]# vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
[root@NDBD1 mysql]# source ~/.bashrc; source ~/.bash_profile
[root@NDBD1 mysql]# mkdir /usr/local/mysql/etc
[root@NDBD1 mysql]# touch etc/my.cnf
[root@NDBD1 mysql]# chown -R root:mysql etc
[root@NDBD1 mysql]# vi etc/my.cnf
#Options for mysqld process
[mysqld]
ndbcluster #run NDB engine
#ndb-connectstring = MGM1 #location of MGM node(MGM1 is master management node)
#ndb-connectstring = MGM2 #location of MGM node(MGM2 is slave management node)
ndb-connectstring = 192.168.0.51
ndb-connectstring = 192.168.0.52
#Options for ndbd process
[mysql_cluster]
#ndb-connectstring = MGM1 #location of MGM node
#ndb-connectstring = MGM2 #location of MGM node
ndb-connectstring = 192.168.0.51
ndb-connectstring = 192.168.0.52
3)安装并配置Data Node2(安装与配置跟Data Node1一样)
===================================================================
三、安装并配置SQL Node
1)安装SQL Node1
[root@SQL1 ~]#tar zxvf mysql-cluster-gpl-7.0.13-linux-i686-glibc23.tar.gz -C /usr/local/;
[root@SQL1 ~]#cd /usr/local
[root@SQL1 local]#mv mysql-cluster-gpl-7.0.13-linux-i686-glibc23 mysql
[root@SQL1 local]#useradd mysql
[root@SQL1 local]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@SQL1 local]#chown -R mysql:mysql /usr/local/mysql
[root@SQL1 local]#cd /usr/local/mysql
[root@SQL1 mysql]#scripts/mysql_install_db --user=mysql
[root@SQL1 mysql]#chown -R root:mysql .
[root@SQL1 mysql]#chown -R mysql:mysql ./data
2)配置SQL Node1
[root@SQL1 mysql]# cat > /etc/hosts
192.168.0.51 MGM1
192.168.0.52 MGM2
192.168.0.53 SQL1
192.168.0.54 SQL2
192.168.0.55 NDBD1
192.168.0.56 NDBD2
[root@SQL1 mysql]# vi ~/.bashrc
alias mysql_shutdown='/usr/local/mysql/bin/mysqladmin -u root shutdown &> /dev/null &'
alias mysql_startup='/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf &> /dev/null &'
alias PS='ps aux | grep mysql | grep -v grep'
[root@SQL1 mysql]# vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
[root@SQL1 mysql]# source ~/.bashrc; source ~/.bash_profile
[root@SQL1 mysql]# mkdir /usr/local/mysql/etc
[root@SQL1 mysql]# touch etc/my.cnf
[root@SQL1 mysql]# chown -R root:mysql etc
[root@SQL1 mysql]# vi etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
user = mysql
port = 3306
socket = /tmp/mysql.sock
ndbcluster
#ndb-connectstring = MGM1
#ndb-connectstring = MGM2
ndb-connectstring = 192.168.0.51
ndb-connectstring = 192.168.0.52
[mysql_cluster]
#provide connectstring for management server host (default port: 1186)
#ndb-connectstring = [ hostname | ip ] [: 1186 ]
#ndb-connectstring = MGM1
#ndb-connectstring = MGM2
ndb-connectstring = 192.168.0.51
ndb-connectstring = 192.168.0.52
3)安装SQL Node2(安装与配置跟SQL Node1 一样)
===================================================================
四、安装并配置Management Node
1)安装Management Node1
[root@MGM1 ~]# tar zxvf mysql-cluster-gpl-7.0.13-linux-i686-glibc23.tar.gz
[root@MGM1 ~]# mv mysql-cluster-gpl-7.0.13-linux-i686-glibc23 mysql
[root@MGM1 ~]# mkdir /usr/local/mysql
[root@MGM1 ~]# mkdir /usr/local/mysql/etc #用于存放ndb_mgmd启动时所使用配置文件
[root@MGM1 ~]# mkdir /usr/local/mysql/config
[root@MGM1 ~]# mkdir /usr/local/mysql/bin
[root@MGM1 ~]# mkdir /usr/local/mysql/log
[root@MGM1 ~]# cp mysql/bin/ndb_mgm* /usr/local/mysql/bin/
[root@MGM1 ~]# chmod 755 /usr/local/mysql/bin/*
[root@MGM1 ~]# useradd mysql
[root@MGM1 ~]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@MGM1 ~]# chown -R root:mysql /usr/local/mysql
2)配置Management Node1
[root@MGM1 ~]# cat > /etc/hosts
192.168.0.51 MGM1
192.168.0.52 MGM2
192.168.0.53 SQL1
192.168.0.54 SQL2
192.168.0.55 NDBD1
192.168.0.56 NDBD2
[root@MGM1 ~]# vi .bashrc
alias PS='ps aux | grep ndb_mgmd | grep -v grep'
alias ndb_mgmd='ndb_mgmd --config-file=/usr/local/mysql/etc/config.ini --config-dir=/usr/local/mysql/config --initial'
[root@MGM1 ~]# vi .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
[root@MGM1 ~]# vi /usr/local/mysql/etc/config.ini
#Options affecting ndbd processes on all Data Nodes
[NDBD DEFAULT]
#Number of replicas
NoOfReplicas=2
########################What is NoOfReplicas?########################
# 1)数据节点:A与B
# 2)某个数据:由于两个数据节点,所以将数据分成2块进行存储:1与2
# 3)如果把NoOfReplicas的值设置成"1",那么将把数据块1存储到A,数据块2存储到B
# ,所以只要A或B宕机,数据就不是完整的了,就会少掉其中的一部分(数据块1或数据块2)
# 4)如果把NoOfReplicas的值设置成"2",那么将把数据块1存储到A,并把数据块1备份
# 到B上,把数据块2存储到B,并把数据块2备份到A上,所以A或者B中其中一个宕机,
# 数据还是完整的
# 5)所以NoOfReplicas的最大值可能只能是4
#####################################################################
#How much memory to allocate for data storage
DataMemory=80M
#How much memory to allocate for index storage
IndexMemory=18M
######About DataMemory and IndexMemory######
# Use the tool named ndb_size.pl,80M and 18M
# is default values for them.
############################################
#TCP/IP Options
[TCP DEFAULT]
#The Default value is 2202
#portnumber=2202
#Management Process Options
[NDB_MGMD]
id=1
#Hostname or IP address of MGM Node
#hostname=MGM1
hostname=192.168.0.51
#Directory for MGM Node logfiles
datadir=/usr/local/mysql/log
[NDB_MGMD]
id=2
#hostname=MGM2
hostname=192.168.0.52
datadir=/usr/local/mysql/log
#Options for Data Node
[NDBD]
id=11
#Hostname or IP address of Data Node
#hostname=NDBD1
hostname=192.168.0.55
#Directory for this data node's datafiles
datadir=/usr/local/mysql/data
#指定存放为元数据创建的所有文件、REDO日志、UNDO日志和数据文件的目录
#FileSystemPath=PATH
#存放备份的目录
#BackupDataDir=PATH
[NDBD]
id=12
#hostname=NDBD2
hostname=192.168.0.56
datadir=/usr/local/mysql/data
#Options for SQL Node
[MYSQLD]
id=21
#Hostname or IP address of SQL Node
#hostname=SQL1
hostname=192.168.0.53
[MYSQLD]
id=22
#hostname=SQL2
hostname=192.168.0.54
[MYSQLD]
[MYSQLD]
[MYSQLD]
===================================================================
五、启动mysql集群的各个节点
注意:启动的顺序为:管理节点->数据节点->SQL节点
注意:仅在首次启动数据节点(ndbd)时,或在备份/恢复或配置变化后重启ndbd时使用“--initial”参数,原因在于,该参数会使节点删除由早期ndbd实例创建的、用于恢复的任何文件,包括恢复用日志文件
[root@MGM1 ~]# ndb_mgmd; PS
[root@MGM2 ~]# ndb_mgmd; PS
[root@NDBD1 ~]# ndbd --initial; PS
[root@NDBD2 ~]# ndbd --initial; PS
[root@SQL1 ~]# mysql_startup; PS
[root@SQL2 ~]# mysql_startup; PS
===================================================================
六、查看各节点情况
注意:可通过管理节点来查看各节点的启动情况
[root@MGM1 ~]# ndb_mgm
[root@MGM1 ~]# ndb_mgm