集群组成
管理节点(MGM):这类节点的作用是管理MySQLCluster内的其他节点,如提供配置数据,并停止节点,运行备份等。由于这类节点负责管理其他节点的配置,应该在启动其他节点之前启动这类节点。MGM节点是用命令“ndb_mgmd”启动的;
数据节点(NDB):这类节点用于保存Cluster的数据,数据节点的数目与副本的数目相关,是片段的倍数。例如,对于两个副本,每个副本有两个片段,那么就有4个数据节点,没有必要设定过多的副本,在NDB中数据会尽量的保存在内存中。数据节点使用命令“ndb”启动的;
SQL节点:这是用来访问Cluster数据的节点,对于MySQL Cluster,客户端节点是使用NDB Cluster存储引擎的传统MySQL服务器。通常,SQL节点使用命令“mysqld-ndbcluster”启动的;
节点共同操作
wget https://downloads.mysql.com/archives/get/p/14/file/mysql-cluster-gpl-7.5.25-linux-glibc2.12-x86_64.tar.gz
tar Czxvf /usr/local mysql-cluster-gpl-7.5.25-linux-glibc2.12-x86_64.tar.gz
mv /usr/local/mysql-cluster-gpl-7.5.25-linux-glibc2.12-x86_64 /usr/local/mysql
groupadd mysql
useradd -g mysql -s /bin/false mysql
cd /usr/local/mysql
chown -R root .
chgrp -R nginx .
./mysqld --initialize --explicit_defaults_for_timestamp=true --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
管理节点配置
[ndbd default]
NoOfReplicas=2
DataMemory=512M
IndexMemory=18M
ServerPort=2202
[ndb_mgmd]
HostName=192.168.10.132
NodeId=1
DataDir=/var/lib/mysql-cluster
[ndbd]
HostName=192.168.10.135
NodeId=2
DataDir=/usr/local/mysql/data
[ndbd]
HostName=192.168.10.136
NodeId=3
DataDir=/usr/local/mysql/data
[mysqld]
HostName=192.168.10.133
NodeId=4
[mysqld]
HostName=192.168.10.134
NodeId=5
管理节点启动 cd /usr/local/mysql/bin./ndb_mgmd --initial -f /var/lib/mysql-cluster/config.ini
SQL节点配置
[client]
socket=/usr/local/mysql/sock/mysql.sock
[mysqld]
ndbcluster
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/sock/mysql.sock
explicit_defaults_for_timestamp=true
user=mysql
ndb-connectstring=192.168.10.132
[mysql_cluster]
ndb-connectstring=192.168.10.132
SQL节点启动 cd /usr/local/mysql/bin./mysqld_safe --user=mysql
数据节点配置
[mysqld]
basedir=/usr/locla/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/sock/mysql.sock
explicit_defaults_for_timestamp=true
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=192.168.10.132
数据节点启动 cd /usr/lcoal/mysql/bin ./ndbd --initial
参数只需要第一次初始化的时候加
集群查看
在管理节点上 cd /usr/local/mysql/bin
[user@host ~]# 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 (not connected, accepting connect from 192.168.10.135)
id=3 (not connected, accepting connect from 192.168.10.136)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.10.132 (mysql-5.7.37 ndb-7.5.25)
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from 192.168.10.133)
id=5 (not connected, accepting connect from 192.168.10.134)
ndb_mgm> Node 2: Started (version 7.5.25)
Node 3: Started (version 7.5.25)
#连接状态
ndb_mgm> SHOW
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.10.135 (mysql-5.7.37 ndb-7.5.25, Nodegroup: 0, *)
id=3 @192.168.10.136 (mysql-5.7.37 ndb-7.5.25, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.10.132 (mysql-5.7.37 ndb-7.5.25)
[mysqld(API)] 2 node(s)
id=4 @192.168.10.133 (mysql-5.7.37 ndb-7.5.25)
id=5 @192.168.10.134 (mysql-5.7.37 ndb-7.5.25)
连接集群
关闭集群
1 首先关闭管理节点和数据节点,需要在管理节点上执行命令,如下:./ndb_mgm -e shutdown
2 然后关闭SQL节点,在SQL节点上执行命令/usr/local/mysql/support-fies/mysql.server stop
(其中/usr/local/mysql/是mysql的安装目录).从而关闭SQL节点