MySQL NDB集群初始配置

NDB集群初始配置
在本节中,我们将通过创建和编辑配置文件来讨论已安装的NDB集群的手动配置。
群集节点和主机。
节点 IP地址

管理节点(mgmd)                        10.10.10.102
SQL节点(mysqld)                       10.10.10.103
数据节点A(ndbd)                       10.10.10.104
数据节点B(ndbd)                       10.10.10.105

NDB Cluster还提供了一个GUI安装程序,可用于执行配置,而无需在单独的应用程序中编辑文本文件。要了解更多信息,请参见第21.2.1 节“NDB集群”Auto-Installer”。

对于我们的四节点、四主机的NDB集群(请参阅集群节点和主机),有必要编写四个配置文件,每个节点主机一个。
.每个数据节点或SQL节点都需要一个my.cnf文件,该文件提供两条信息:一个连接字符串,告诉节点在哪里找到管理节点,另一行告诉该主机( 承载数据节点的机器)上的MySQL服务器启用NDBCLUSTER存储引擎。

.管理节点需要一个config.ini文件,告诉它要维护多少个副本、为每个数据节点上的数据和索引分配多少内存、在哪里找到数据节点、在哪里 将数据保存到每个数据节点的磁盘上,以及在哪里找到SQL节点。

配置数据节点和SQL节点。
数据节点所需的my.cnf文件相当简单。配置文件应该位于/etc目录下,可以使用任何文本编辑器进行编辑。(如果该文件不存在,则创建该文件 。)例如:

shell> vi /etc/my.cnf

对于我们的示例设置中的每个数据节点和SQL节点,my.cnf应该是这样的:

[mysqld]
# Options for mysqld process:
ndbcluster # run NDB storage engine

[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=10.10.10.102 # location of management server

输入上述信息后,保存该文件并退出文本编辑器。对承载数据节点“A”、数据节点“B”和SQL节点的机器执行此操作。
SQL节点:

[root@mysqld /]# vi /etc/my.cnf
[mysqld]
# Options for mysqld process:
ndbcluster # run NDB storage engine

[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=10.10.10.102 # location of management server

数据节点A:

[root@ndbda /]# vi /etc/my.cnf
[mysqld]
# Options for mysqld process:
ndbcluster # run NDB storage engine

[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=10.10.10.102 # location of management server

数据节点B:

[root@ndbdb /]# vi /etc/my.cnf
[mysqld]
# Options for mysqld process:
ndbcluster # run NDB storage engine

[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=10.10.10.102 # location of management server

如前所示,一旦你用my.cnf文件的[mysqld]和[mysql_cluster]部分中的ndbcluster和ndbconnectstring参数启动了mysqld进程,你就不能在没 有实际启动集群之前执行任何CREATE TABLE或ALTER TABLE语句。否则,这些语句将失败并报错。这是设计的结果。

配置管理节点。
配置管理节点的第一步是创建可以找到配置文件的目录,然后创建文件本身。例如(以root身份运行):

[root@mgmd /]# mkdir /var/lib/mysql-cluster
[root@mgmd /]# cd /var/lib/mysql-cluster

对于我们的典型设置,config.ini文件应该如下所示:

[root@mgmd mysql-cluster]# vi config.ini
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2      # Number of replicas
DataMemory=1024M    # How much memory to allocate for data storage
IndexMemory=256M    # How much memory to allocate for index storage
                    # For DataMemory and IndexMemory, we have used the
                    # default values. Since the "world" database takes up
                    # only about 500KB, this should be more than enough for
                    # this example NDB Cluster setup.
ServerPort=2202     # This the default value; however, you can use any
                    # port that is free for all the hosts in the cluster
                    # Note1: It is recommended that you do not specify the port
                    # number at all and simply allow the default value to be used
                    # instead
                    # Note2: The port was formerly specified using the PortNumber
                    # TCP parameter; this parameter is no longer available in NDB
                    # Cluster 7.5.
[ndb_mgmd]
# Management process options:
HostName=10.10.10.102            # Hostname or IP address of MGM node
DataDir=/var/lib/mysql-cluster     # Directory for MGM node log files
[ndbd]
# Options for data node "A":
HostName=10.10.10.104            # Hostname or IP address
NodeId=2                           # Node ID for this data node
DataDir=/usr/local/mysql/data      # Directory for this data node's data files
[ndbd]
# Options for data node "B":
HostName=10.10.10.105            # Hostname or IP address
NodeId=3                           # Node ID for this data node
DataDir=/usr/local/mysql/data      # Directory for this data node's data files
[mysqld]
# SQL node options:
HostName=10.10.10.103            # Hostname or IP address
                                   # (additional mysqld connections can be
                                   # specified for this node for various
                                   # purposes such as running ndb_restore)
~

在创建了所有配置文件并指定了这些最小选项之后,就可以继续启动集群并验证所有进程都在运行。

集群管理节点的默认端口为1186;数据节点默认端口为“2202”。但是,集群可以从已经空闲的端口中自动为数据节点分配端口。

NDB集群初始启动
在配置完集群之后,启动集群并不是很困难。每个集群节点进程必须在其所在的主机上单独启动。首先应该启动管理节点,然后是数据节点,最 后是任何SQL节点:
1.在管理主机上,在系统shell中执行如下命令启动管理节点进程:

[root@mgmd /]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini
MySQL Cluster Management Server mysql-5.7.48 ndb-7.5.36
2025-05-22 18:26:23 [MgmtSrvr] INFO     -- The default config directory '/usr/local/mysql/mysql-cluster' does not exist.  Trying to create it...
Failed to create directory '/usr/local/mysql/mysql-cluster', error: 2
2025-05-22 18:26:23 [MgmtSrvr] ERROR    -- Could not create directory '/usr/local/mysql/mysql-cluster'. Either create it  manually or specify a different directory with --configdir=
[root@mgmd /]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini --configdir=/var/lib/mysql-cluster
MySQL Cluster Management Server mysql-5.7.48 ndb-7.5.36
[root@mgmd /]# netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1527/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      13043/cupsd
tcp        0      0 0.0.0.0:1186            0.0.0.0:*               LISTEN      26104/ndb_mgmd
tcp6       0      0 :::22                   :::*                    LISTEN      1527/sshd
tcp6       0      0 ::1:631                 :::*                    LISTEN      13043/cupsd

在第一次启动ndb_mgmd时,必须使用-f或——config-file选项告诉它在哪里可以找到它的配置文件

2.在所有数据节点主机上执行如下命令启动ndbd进程:
数据节点A:

[root@ndbda /]# ndbd
2025-05-22 18:34:35 [ndbd] INFO     -- Angel connected to '10.10.10.102:1186'
2025-05-22 18:34:35 [ndbd] INFO     -- Angel allocated nodeid: 2
[root@ndbda /]# netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1527/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      11765/cupsd
tcp        0      0 10.10.10.104:2202     0.0.0.0:*               LISTEN      25455/ndbd
tcp6       0      0 :::22                   :::*                    LISTEN      1527/sshd
tcp6       0      0 ::1:631                 :::*                    LISTEN      11765/cupsd

数据节点B:

[root@ndbdb /]# ndbd
2025-05-22 18:35:08 [ndbd] INFO     -- Angel connected to '10.10.10.102:1186'
2025-05-22 18:35:08 [ndbd] INFO     -- Angel allocated nodeid: 3
[root@ndbdb /]# netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1526/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      13086/cupsd
tcp        0      0 10.10.10.105:2202     0.0.0.0:*               LISTEN      26140/ndbd
tcp6       0      0 :::22                   :::*                    LISTEN      1526/sshd
tcp6       0      0 ::1:631                 :::*                    LISTEN      13086/cupsd

3.如果您使用RPM文件在SQL节点所在的集群主机上安装MySQL,则可以(并且应该)使用提供的启动脚本在SQL节点上启动MySQL服务器进程。

[root@mysqld mysql]# service mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/mysqld.err'.
. SUCCESS!

[root@mysqld mysql]# netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1529/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      13038/cupsd
tcp6       0      0 :::3306                 :::*                    LISTEN      26418/mysqld
tcp6       0      0 :::22                   :::*                    LISTEN      1529/sshd
tcp6       0      0 ::1:631                 :::*                    LISTEN      13038/cupsd

如果一切顺利,并且集群已经正确设置,那么集群现在应该可以运行了。你可以通过调用ndb_mgm管理节点客户端来测试这一点。输出应该如下 所示,不过你可能会发现不同版本的MySQL的输出略有不同:

[root@mgmd /]# 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    @10.10.10.104  (mysql-5.7.48 ndb-7.5.36, Nodegroup: 0, *)
id=3    @10.10.10.105  (mysql-5.7.48 ndb-7.5.36, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @10.10.10.102  (mysql-5.7.48 ndb-7.5.36)

[mysqld(API)]   1 node(s)
id=4    @10.10.10.103  (mysql-5.7.48 ndb-7.5.36)

ndb_mgm>

SQL节点在这里被引用为[mysqld(API)],这反映了mysqld进程作为NDB集群API节点的事实。

SHOW命令输出中显示的给定NDB Cluster SQL或其他API节点的IP地址是SQL或API节点连接到集群数据节点的地址,而不是连接到任何管理节点的 地址。

现在您应该已经准备好处理NDB Cluster中的数据库、表和数据了

发表评论

电子邮件地址不会被公开。