集群组成

  1. 管理节点(MGM):这类节点的作用是管理MySQLCluster内的其他节点,如提供配置数据,并停止节点,运行备份等。由于这类节点负责管理其他节点的配置,应该在启动其他节点之前启动这类节点。MGM节点是用命令“ndb_mgmd”启动的;

数据节点(NDB):这类节点用于保存Cluster的数据,数据节点的数目与副本的数目相关,是片段的倍数。例如,对于两个副本,每个副本有两个片段,那么就有4个数据节点,没有必要设定过多的副本,在NDB中数据会尽量的保存在内存中。数据节点使用命令“ndb”启动的;

SQL节点:这是用来访问Cluster数据的节点,对于MySQL Cluster,客户端节点是使用NDB Cluster存储引擎的传统MySQL服务器。通常,SQL节点使用命令“mysqld-ndbcluster”启动的;

节点共同操作

下载连接
https://downloads.mysql.com/archives/get/p/14/file/mysql-cluster-gpl-7.5.25-linux-glibc2.12-x86_64.tar.gz

  1. wget https://downloads.mysql.com/archives/get/p/14/file/mysql-cluster-gpl-7.5.25-linux-glibc2.12-x86_64.tar.gz
  2. tar Czxvf /usr/local mysql-cluster-gpl-7.5.25-linux-glibc2.12-x86_64.tar.gz
  3. mv /usr/local/mysql-cluster-gpl-7.5.25-linux-glibc2.12-x86_64 /usr/local/mysql
  4. groupadd mysql
  5. useradd -g mysql -s /bin/false mysql
  6. cd /usr/local/mysql
  7. chown -R root .
  8. chgrp -R nginx .
  9. ./mysqld --initialize --explicit_defaults_for_timestamp=true --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

管理节点配置

  1. [ndbd default]
  2. NoOfReplicas=2
  3. DataMemory=512M
  4. IndexMemory=18M
  5. ServerPort=2202
  6. [ndb_mgmd]
  7. HostName=192.168.10.132
  8. NodeId=1
  9. DataDir=/var/lib/mysql-cluster
  10. [ndbd]
  11. HostName=192.168.10.135
  12. NodeId=2
  13. DataDir=/usr/local/mysql/data
  14. [ndbd]
  15. HostName=192.168.10.136
  16. NodeId=3
  17. DataDir=/usr/local/mysql/data
  18. [mysqld]
  19. HostName=192.168.10.133
  20. NodeId=4
  21. [mysqld]
  22. HostName=192.168.10.134
  23. NodeId=5

管理节点启动 cd /usr/local/mysql/bin
./ndb_mgmd --initial -f /var/lib/mysql-cluster/config.ini

SQL节点配置

  1. [client]
  2. socket=/usr/local/mysql/sock/mysql.sock
  3. [mysqld]
  4. ndbcluster
  5. datadir=/usr/local/mysql/data
  6. socket=/usr/local/mysql/sock/mysql.sock
  7. explicit_defaults_for_timestamp=true
  8. user=mysql
  9. ndb-connectstring=192.168.10.132
  10. [mysql_cluster]
  11. ndb-connectstring=192.168.10.132

SQL节点启动 cd /usr/local/mysql/bin
./mysqld_safe --user=mysql

数据节点配置

  1. [mysqld]
  2. basedir=/usr/locla/mysql
  3. datadir=/usr/local/mysql/data
  4. socket=/usr/local/mysql/sock/mysql.sock
  5. explicit_defaults_for_timestamp=true
  6. user=mysql
  7. symbolic-links=0
  8. [mysqld_safe]
  9. log-error=/var/log/mysqld.log
  10. pid-file=/var/run/mysqld/mysqld.pid
  11. [mysql_cluster]
  12. ndb-connectstring=192.168.10.132

数据节点启动 cd /usr/lcoal/mysql/bin
./ndbd --initial 参数只需要第一次初始化的时候加

集群查看

在管理节点上 cd /usr/local/mysql/bin

  1. [user@host ~]# ndb_mgm
  2. -- NDB Cluster -- Management Client --
  3. #未连接状态
  4. ndb_mgm> SHOW
  5. Connected to Management Server at: localhost:1186
  6. Cluster Configuration
  7. ---------------------
  8. [ndbd(NDB)] 2 node(s)
  9. id=2 (not connected, accepting connect from 192.168.10.135)
  10. id=3 (not connected, accepting connect from 192.168.10.136)
  11. [ndb_mgmd(MGM)] 1 node(s)
  12. id=1 @192.168.10.132 (mysql-5.7.37 ndb-7.5.25)
  13. [mysqld(API)] 2 node(s)
  14. id=4 (not connected, accepting connect from 192.168.10.133)
  15. id=5 (not connected, accepting connect from 192.168.10.134)
  16. ndb_mgm> Node 2: Started (version 7.5.25)
  17. Node 3: Started (version 7.5.25)
  18. #连接状态
  19. ndb_mgm> SHOW
  20. Cluster Configuration
  21. ---------------------
  22. [ndbd(NDB)] 2 node(s)
  23. id=2 @192.168.10.135 (mysql-5.7.37 ndb-7.5.25, Nodegroup: 0, *)
  24. id=3 @192.168.10.136 (mysql-5.7.37 ndb-7.5.25, Nodegroup: 0)
  25. [ndb_mgmd(MGM)] 1 node(s)
  26. id=1 @192.168.10.132 (mysql-5.7.37 ndb-7.5.25)
  27. [mysqld(API)] 2 node(s)
  28. id=4 @192.168.10.133 (mysql-5.7.37 ndb-7.5.25)
  29. id=5 @192.168.10.134 (mysql-5.7.37 ndb-7.5.25)

连接集群

连接上任一SQL节点即可

关闭集群

1 首先关闭管理节点和数据节点,需要在管理节点上执行命令,如下:
./ndb_mgm -e shutdown
2 然后关闭SQL节点,在SQL节点上执行命令
/usr/local/mysql/support-fies/mysql.server stop
(其中/usr/local/mysql/是mysql的安装目录).从而关闭SQL节点