在本节中,我们将讨论通过创建和编辑配置文件来手动配置已安装的 NDB 集群。In this section, we discuss manual configuration of an installed NDB Cluster by creating and editing configuration files.
对于我们的四节点、四主机 NDB 集群(参见 集群节点和主机计算机),需要编写四个配置文件,每个节点主机一个。For our four-node, four-host NDB Cluster (see Cluster nodes and host computers), it is necessary to write four configuration files, one per node host.
每个数据节点或 SQL 节点都需要一个
my.cnf文件,该文件提供两条信息:一个 连接字符串,用于告诉节点在哪里可以找到管理节点,以及一行告诉此主机上的 MySQL 服务器(承载数据节点的机器)启用NDBCLUSTER存储引擎。Each data node or SQL node requires amy.cnffile that provides two pieces of information: a connection string that tells the node where to find the management node, and a line telling the MySQL server on this host (the machine hosting the data node) to enable theNDBCLUSTERstorage engine.有关连接字符串的更多信息,请参见 第 25.4.3.3 节,“NDB 集群连接字符串”。For more information on connection strings, see Section 25.4.3.3, “NDB Cluster Connection Strings”.
管理节点需要一个
config.ini文件来告知它需要维护多少个片段副本,每个数据节点为数据和索引分配多少内存,在哪里找到数据节点,每个数据节点将数据保存到磁盘的位置,以及如何找到任何 SQL 节点。The management node needs aconfig.inifile telling it how many fragment replicas to maintain, how much memory to allocate for data and indexes on each data node, where to find the data nodes, where to save data to disk on each data node, and where to find any SQL nodes.
配置数据节点和 SQL 节点。 数据节点所需的my.cnf文件相对简单。配置文件应位于/etc目录下,可以使用任何文本编辑器进行编辑。(如果文件不存在,请创建它。)例如:Configuring the data nodes and SQL nodes.
The my.cnf file needed for the data nodes
is fairly simple. The configuration file should be located in
the /etc directory and can be edited using
any text editor. (Create the file if it does not exist.) For
example:
$> vi /etc/my.cnf
这里我们使用vi来创建文件,但任何文本编辑器都可以同样有效。We show vi being used here to create the file, but any text editor should work just as well.
对于我们示例设置中的每个数据节点和 SQL 节点,my.cnf应如下所示:For each data node and SQL node in our example setup,
my.cnf should look like this:
[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
输入上述信息后,保存此文件并退出文本编辑器。对托管数据节点“A”、数据节点“B”以及 SQL 节点的机器执行此操作。After entering the preceding information, save this file and exit the text editor. Do this for the machines hosting data node “A”, data node “B”, and the SQL node.
一旦你按照前面所示的方式在 my.cnf 文件的 [mysqld] 和 [mysql_cluster] 部分使用 ndbcluster 和 ndb-connectstring 参数启动了 mysqld 进程,你在没有实际启动集群的情况下无法执行任何 CREATE TABLE 或 ALTER TABLE 语句。否则,这些语句将会出错。这是设计使然。Once you have started a mysqld process with
the ndbcluster and
ndb-connectstring parameters in the
[mysqld] and
[mysql_cluster] sections of the
my.cnf file as shown previously, you cannot
execute any CREATE TABLE or
ALTER TABLE statements without
having actually started the cluster. Otherwise, these statements
fail with an error. This is by design.
配置管理节点。 配置管理节点的第一步是创建存放配置文件的目录,然后创建配置文件本身。例如(以 root 运行):Configuring the management node.
The first step in configuring the management node is to create
the directory in which the configuration file can be found and
then to create the file itself. For example (running as
root):
$>mkdir /var/lib/mysql-cluster$>cd /var/lib/mysql-cluster$>vi config.ini
对于我们的示例设置,config.ini 文件应如下所示:For our representative setup, the config.ini
file should read as follows:
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2 # Number of fragment replicas
DataMemory=98M # How much memory to allocate for data storage
[ndb_mgmd]
# Management process options:
HostName=198.51.100.10 # Hostname or IP address of management node
DataDir=/var/lib/mysql-cluster # Directory for management 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)
world 数据库可以从 https://dev.mysql.com/doc/index-other.html 下载。The world database can be downloaded from
https://dev.mysql.com/doc/index-other.html.
在创建了所有配置文件并指定了这些最小选项之后,您就可以继续启动集群并验证所有进程是否正在运行。我们在第 25.3.4 节,“NDB 集群的初始启动”中讨论了具体操作方法。After all the configuration files have been created and these minimal options have been specified, you are ready to proceed with starting the cluster and verifying that all processes are running. We discuss how this is done in Section 25.3.4, “Initial Startup of NDB Cluster”.
有关可用 NDB 集群配置参数及其用途的更详细信息,请参见 第 25.4.3 节,“NDB 集群配置文件”,以及 第 25.4 节,“NDB 集群配置”。有关 NDB 集群备份相关的配置,请参见 第 25.6.8.3 节,“NDB 集群备份配置”。For more detailed information about the available NDB Cluster configuration parameters and their uses, see Section 25.4.3, “NDB Cluster Configuration Files”, and Section 25.4, “Configuration of NDB Cluster”. For configuration of NDB Cluster as relates to making backups, see Section 25.6.8.3, “Configuration for NDB Cluster Backups”.
集群管理节点的默认端口是 1186。对于数据节点,集群可以自动分配已空闲的端口。The default port for Cluster management nodes is 1186. For data nodes, the cluster can automatically allocate ports from those that are already free.