21.2.5 NDB 群集的初始配置
在本节中,我们将讨论通过创建和编辑配置文件来手动配置已安装的 NDB 群集。
NDB Cluster 还提供了一个 GUI 安装程序,可用于执行配置,而无需在单独的应用程序中编辑文本文件。有关更多信息,请参见第 21.2.1 节“ NDB 群集自动安装程序(NDB 7.5)”。
对于我们的四节点,四主机 NDB 群集(请参见群集节点和主机),有必要编写四个配置文件,每个节点主机一个。
- 每个数据节点或 SQL 节点都需要一个
my.cnf
文件,该文件提供两段信息:一个连接字符串,告诉节点在哪里可以找到 Management 节点;以及一行,告诉该主机上的 MySQL 服务器(托管数据节点的机器)到启用NDBCLUSTER存储引擎。
有关连接字符串的更多信息,请参见第 21.3.3.3 节“ NDB 群集连接字符串”。
- Management 节点需要一个
config.ini
文件,告诉它要维护多少个副本,为每个数据节点上的数据和索引分配多少内存,在何处查找数据节点,在何处将数据保存到磁盘上以及在何处存储数据。查找任何 SQL 节点。
配置数据节点和 SQL 节点. 数据节点所需的my.cnf
文件非常简单。配置文件应位于/etc
目录中,并且可以使用任何文本编辑器进行编辑。 (如果文件不存在,则创建它.)例如:
shell> vi /etc/my.cnf
Note
我们显示这里使用 vi 来创建文件,但是任何文本编辑器也应该可以正常工作。
对于示例设置中的每个数据节点和 SQL 节点,my.cnf
应该看起来像这样:
[mysqld]
# Options for mysqld process:
ndbcluster # run NDB storage engine
[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=198.51.100.10 # location of management server
Importing 上述信息后,保存此文件并退出文本编辑器。对托管数据节点“ A”,数据节点“ B”和 SQL 节点的计算机执行此操作。
Important
如前所示,一旦在my.cnf
文件的[mysqld]
和[mysql_cluster]
部分中使用ndbcluster
和ndb-connectstring
参数启动了mysqld进程,您就无法执行任何CREATE TABLE或ALTER TABLE语句,而无需实际启动集群。否则,这些语句将失败并显示错误。这是设计使然。
配置 Management 节点. 配置 Management 节点的第一步是创建可在其中找到配置文件的目录,然后创建文件本身。例如(以root
运行):
shell> mkdir /var/lib/mysql-cluster
shell> cd /var/lib/mysql-cluster
shell> vi config.ini
对于我们的代 table 性设置,config.ini
文件应如下所示:
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2 # Number of replicas
DataMemory=80M # How much memory to allocate for data storage
IndexMemory=18M # 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.
# NOTE: IndexMemory is deprecated in NDB 7.6 and later; in
# these versions, resources for all data and indexes are
# allocated by DataMemory and any that are set for IndexMemory
# are added to the DataMemory resource pool
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=198.51.100.10 # Hostname or IP address of MGM node
DataDir=/var/lib/mysql-cluster # Directory for MGM node log files
[ndbd]
# Options for data node "A":
# (one [ndbd] section per data node)
HostName=198.51.100.30 # 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=198.51.100.40 # 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=198.51.100.20 # Hostname or IP address
# (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)
Note
可以从https://dev.mysql.com/doc/index-other.html下载world
数据库。
在创建了所有配置文件并指定了这些最小选项之后,您就可以开始启动集群并验证所有进程是否正在运行。我们将在第 21.2.6 节“ NDB 群集的初始启动”中讨论如何完成此操作。
有关可用的 NDB 群集配置参数及其用法的更多详细信息,请参阅第 21.3.3 节“ NDB 群集配置文件”和第 21.3 节“ NDB 群集的配置”。有关与备份有关的 NDB 群集的配置,请参见第 21.5.8.3 节“ NDB 群集备份的配置”。
Note
群集 Management 节点的默认端口为 1186;默认端口为 1186.数据节点的默认端口为 2202.但是,群集可以自动为那些已经空闲的数据节点分配端口。