准备将独立 MySQL 集群导入 MySQL 集群管理器时的第一个任务是创建一个“目标” 集群,一旦完成,我们修改目标的配置,直到它与 我们要导入的“野生”集群的配置相匹配。在示例的稍后部分,我们还展示了如何在尝试执行实际导入之前在试运行中测试配置。
要创建并配置目标集群,请按照此处列出的步骤操作:
安装 MySQL Cluster Manager 并在所有主机上启动mcmd ;我们假设您已将 MySQL Cluster Manager 安装到推荐的位置,在本例中为目录
/opt/mcm-1.3.6
。(有关更多信息,请参阅 第 2.3 节,“MySQL Cluster Manager 安装”。)完成此操作后,您可以在这些主机中的任何一台上启动 mcm客户端(请参阅 第 3.3 节,“启动 MySQL Cluster Manager 客户端”)以执行接下来的几个步骤。使用命令创建包含所有这四台主机的 MySQL Cluster Manager 站点
create site
,如下所示:mcm> create site --hosts=alpha,beta,gamma,delta newsite; +---------------------------+ | Command result | +---------------------------+ | Site created successfully | +---------------------------+ 1 row in set (0.15 sec)
我们已将此站点命名为
newsite
。您应该能够在list sites
命令的输出中看到它,类似于此处显示的内容:mcm> list sites; +---------+------+-------+------------------------+ | Site | Port | Local | Hosts | +---------+------+-------+------------------------+ | newsite | 1862 | Local | alpha,beta,gamma,delta | +---------+------+-------+------------------------+ 1 row in set (0.01 sec)
使用命令添加引用 MySQL Cluster 二进制文件的 MySQL Cluster Manager 包
add package
;此命令的--basedir
选项可用于指向正确的位置。此处显示的命令创建了这样一个包,名为newpackage
:mcm> add package --basedir=/usr/local/mysql newpackage; +----------------------------+ | Command result | +----------------------------+ | Package added successfully | +----------------------------+ 1 row in set (0.70 sec)
您不需要在路径
bin
中包含包含 MySQL Cluster 可执行文件的目录 。--basedir
由于可执行文件位于 中/usr/local/mysql/bin
,因此指定/usr/local/mysql
; MySQL Cluster Manager 自动检查bin
由--basedir
.创建目标集群,其中至少包括独立集群使用的一些相同进程和主机。 不要包括不属于该集群的任何进程或主机。为了防止潜在的中断过程或集群操作意外干扰导入过程,强烈建议您使用命令的
--import
选项创建用于导入的集群create cluster
。您还必须注意
config.ini
为每个节点保留正确的节点 ID(如前面所示的文件中所列)。在 MySQL Cluster Manager 1.3.1 及更高版本中,使用该--import
选项可以为数据节点以外的节点指定 49 以下的节点 ID,否则在使用时将被阻止create cluster
(该限制自 MySQL Cluster Manager 1.3.4 起解除)。以下命令创建
newcluster
用于导入的集群,包括管理和数据节点,但不包括 SQL 或 “免费” API 节点(我们在下一步中添加):mcm> create cluster --import --package=newpackage \ --processhosts=ndb_mgmd:50@alpha,ndbd:1@beta,ndbd:2@gamma \ newcluster; +------------------------------+ | Command result | +------------------------------+ | Cluster created successfully | +------------------------------+ 1 row in set (0.96 sec)
show status
您可以通过使用--process
(-r
) 选项 检查 的输出来验证集群是否已正确创建,如下所示:mcm> show status -r newcluster; +--------+----------+-------+--------+-----------+------------+ | NodeId | Process | Host | Status | Nodegroup | Package | +--------+----------+-------+--------+-----------+------------+ | 50 | ndb_mgmd | alpha | import | | newpackage | | 5 | ndbd | beta | import | n/a | newpackage | | 6 | ndbd | gamma | import | n/a | newpackage | +--------+----------+-------+--------+-----------+------------+ 3 rows in set (0.01 sec)
如有必要,使用一个或多个命令添加上一步中未包含的“ wild ”集群中的 任何剩余进程和主机。
add process
我们还没有考虑到 wild 集群中的 2 个节点:节点 ID 为 100 的 SQL 节点,在主机上delta
;以及具有节点 ID 101 且未绑定到任何特定主机的 API 节点。您可以使用以下命令将这两个进程添加到newcluster
:mcm> add process --processhosts=mysqld:100@delta,ndbapi:101@* newcluster; +----------------------------+ | Command result | +----------------------------+ | Process added successfully | +----------------------------+ 1 row in set (0.41 sec)
再次检查 的输出
show status
-r
,我们看到mysqld
和ndbapi
进程已按预期添加:mcm> show status -r newcluster; +--------+----------+-------+--------+-----------+------------+ | NodeId | Process | Host | Status | Nodegroup | Package | +--------+----------+-------+--------+-----------+------------+ | 50 | ndb_mgmd | alpha | import | | newpackage | | 5 | ndbd | beta | import | n/a | newpackage | | 6 | ndbd | gamma | import | n/a | newpackage | | 100 | mysqld | delta | import | | newpackage | | 101 | ndbapi | * | import | | | +--------+----------+-------+--------+-----------+------------+ 5 rows in set (0.08 sec)
您还可以看到,由于
newcluster
是使用create cluster
命令的--import
选项创建的,因此该集群中所有进程(包括我们刚刚添加的进程)的状态为import
. 这意味着我们还不能启动newcluster
它的任何进程,如下所示:mcm> start process 50 newcluster; ERROR 5317 (00MGR): Unable to perform operation on cluster created for import mcm> start cluster newcluster; ERROR 5317 (00MGR): Unable to perform operation on cluster created for import
import
状态及其对 集群进程 的影响newcluster
一直存在,直到我们完成将另一个集群导入到newcluster
.执行
add process
前面显示的命令后,目标newcluster
集群现在具有与原始独立集群相同的进程、相同的节点 ID 和相同的主机。我们准备好进行下一步。在目标集群中复制 wild 集群的配置属性。
import config
在 MySQL Cluster Manager 1.3.1 及更高版本中,您可以使用命令处理其中的大部分 。首先通过使用选项运行命令来测试命令的效果--dryrun
(该步骤仅在您 在集群的 mysqld 节点上创建了 mcmd 用户时才有效):mcm> import config --dryrun newcluster; +---------------------------------------------------------------------------+ | Command result | +---------------------------------------------------------------------------+ | Import checks passed. Please check log for settings that will be applied. | +---------------------------------------------------------------------------+ 1 row in set (5.36 sec)
重要的在执行此命令之前,有必要在mcm客户端中使用该命令
ndb_mgmd
为mysqld
进程 设置任何非默认端口。set
As indicated by the output from
import config --dryrun
, you can see the configuration attributes and values that would be copied tonewcluster
by the unimpeded command in the agent log file (mcmd.log
), which by default is created in the MySQL Cluster Manager installation directory. If you open this file in a text editor, you can locate a series ofset
commands that would accomplish this task, similar to what is shown here in emphasized texts:2014-03-14 16:05:11.896: (message) [T0x1ad12a0 CMGR ]: Got new message mgr_import_configvalues {84880f7a 35 0} 2014-03-14 16:05:11.896: (message) [T0x1ad12a0 CMGR ]: Got new message mgr_import_configvalues {84880f7a 36 0} 2014-03-14 16:05:11.896: (message) [T0x1ad12a0 CMGR ]: Got new message mgr_import_configvalues {84880f7a 37 0} 2014-03-14 16:05:13.698: (message) [T0x7f4fb80171a0 RECFG]: All utility process have finished 2014-03-14 16:05:13.698: (message) [T0x7f4fb80171a0 RECFG]: Process started : /usr/local/mysql/bin/mysqld --no-defaults --help --verbose 2014-03-14 16:05:13.698: (message) [T0x7f4fb80171a0 RECFG]: Spawning mysqld --nodefaults --help --verbose asynchronously 2014-03-14 16:05:13.904: (message) [T0x7f4fb80171a0 RECFG]: Successfully pulled default configuration from mysqld 100 2014-03-14 16:05:13.905: (warning) [T0x7f4fb80171a0 RECFG]: Failed to remove evsource! 2014-03-14 16:05:15.719: (message) [T0x7f4fb80171a0 RECFG]: All utility process have finished 2014-03-14 16:05:15.725: (message) [T0x7f4fb80171a0 RECFG]: Applying mysqld configuration to cluster... 2014-03-14 16:05:16.186: (message) [T0x1ad12a0 CMGR ]: Got new message mgr_import_configvalues {84880f7a 38 0} 2014-03-14 16:05:16.187: (message) [T0x1ad12a0 CMGR ]: Got new message x_trans {84880f7a 39 0} 2014-03-14 16:05:16.286: (message) [T0x1ad12a0 CMGR ]: Got new message x_trans {84880f7a 40 0} 2014-03-14 16:05:16.286: (message) [T0x7f4fb80171a0 RECFG]: The following will be applied to the current cluster config: set DataDir:ndb_mgmd:50="" newcluster set IndexMemory:ndbd:5=1073741824 newcluster set DataMemory:ndbd:5=1073741824 newcluster set DataDir:ndbd:5=/usr/local/mysql/mysql-cluster/data newcluster set ThreadConfig:ndbd:5="" newcluster set IndexMemory:ndbd:6=1073741824 newcluster set DataMemory:ndbd:6=1073741824 newcluster set DataDir:ndbd:6=/usr/local/mysql/mysql-cluster/data newcluster set ThreadConfig:ndbd:6="" newcluster set basedir:mysqld:100=/usr/local/mysql newcluster set character_sets_dir:mysqld:100=/usr/local/mysql/share/charsets newcluster set datadir:mysqld:100=/usr/local/mysql/data newcluster set general_log_file:mysqld:100=/usr/local/mysql/data/delta.log newcluster set lc_messages_dir:mysqld:100=/usr/local/mysql/share newcluster set log_error:mysqld:100=/usr/local/mysql/data/delta.err newcluster set ndb_connectstring:mysqld:100=alpha newcluster set ndb_mgmd_host:mysqld:100=alpha newcluster set optimizer_trace:mysqld:100=enabled=off,one_line=off newcluster set pid_file:mysqld:100=/usr/local/mysql/data/delta.pid newcluster set plugin_dir:mysqld:100=/usr/local/mysql/lib/plugin newcluster set report_port:mysqld:100=3306 newcluster set slow_query_log_file:mysqld:100=/usr/local/mysql/data/delta-slow.log newcluster set sql_mode:mysqld:100=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION newcluster
Options used at the command line instead of in a configuration file to start a node of the standalone cluster are not imported into the target cluster by the
import config
command; moreover, they will cause one of the following to happen when theimport config
--dryrun
is run:For some options, MySQL Cluster Manager will issue a warning that “Option
<param>
may be removed on next restart of process<type>
<nodeid>
,” meaning that those options will not be imported into the target cluster, and thus will not be applied when those nodes are restarted after the import. Here are the lists of such options for each node type:For ndb_mgmd nodes: -
--configdir
,--initial
,--log-name
,--reload
,--verbose
For ndbd and ndbmtd nodes:
--connect-retries
,--connect-delay
,--daemon=false
,--nodaemon
,--verbose
For mysqld nodes:
--ndbcluster
, the--ndbinfo-*
options,--verbose
,--datadir
,--defaults-group-suffix
When a warning is received for any of these options but you want its value to be included as part of the configuration for your target cluster, you will need to set the option value for your target cluster manually using the set command before you perform the final
import cluster
step.For some other options, while their values will also not be imported into the target cluster, unlike options described in (i) above, no warnings will be issued for them. Here are lists of such options for each node type:
For ndb_mgmd nodes:
--config-cache
,--daemon
,--ndb-nodeid
,--nodaemon=false
,--config-file
,--skip-config-cache
For ndbd and ndbmtd nodes:
--daemon
,--foreground
,--initial
,--ndb-connectstring
,--connect-string
,--ndb-mgmd-host
,--ndb-nodeid
,--nodaemon=false
For mysqld nodes:
--ndb-connectstring
,--ndb-mgmd-host
,--ndb-nodeid
,--defaults-file
,--no-defaults
,--basedir
For options that belong to neither of the groups in (i) or (ii) above, having started the standalone cluster's nodes with them at the command line will cause the
import config
--dryrun
command to fail with an error, complaining that the options are unsupported. You have to restart the wild cluster's nodes without those options, and then retry theimport config
--dryrun
command.
Assuming that the dry run was successful, you should now be able to import the wild cluster's configuration into newcluster, with the command and a result similar to what is shown here:
mcm> import config newcluster; +------------------------------------------------------------------------------------------------------------------+ | Command result | +------------------------------------------------------------------------------------------------------------------+ | Configuration imported successfully. Please manually verify plugin options, abstraction level and default values | +------------------------------------------------------------------------------------------------------------------+
You should check the log from the dry run and the resulting configuration of
newcluster
carefully against the configuration of the wild cluster. If you find any inconsistencies, you must correct these innewcluster
using the appropriateset
commands afterwards.
Manual configuration import (MySQL Cluster Manager 1.3.0).
In MySQL Cluster Manager 1.3.0, which does not support the
import config
command, it
is necessary to copy the wild cluster's configuration
manually, using set
commands in the mcm client (once you have
obtained the values of any attributes that differ from their
defaults). The remainder of this section applies primarily
to MySQL Cluster Manager 1.3.0 and the process described here is generally
not needed in MySQL Cluster Manager 1.3.1 and later.
MySQL Cluster global configuration data is stored in a file
that is usually (but not always) named
config.ini
. Its location on a management
node host is arbitrary (there is no default location for it),
but if this is not already known, you can determine it by
checking—for example, on a typical Linux
system—the output of ps
for the --config-file
option
value that the management node was started with, shown with
emphasized text in the output:
$> ps ax | grep ndb_mgmd
18851 ? Ssl 0:00 ./ndb_mgmd --config-file=/var/lib/mysql-cluster/config.ini
18922 pts/4 S+ 0:00 grep --color=auto ndb_mgmd
This file uses INI
format to store global
configuration information, and is thus easy to read, or to
parse with a script. We start the setup of the target
cluster' configuration by checking each section of this
file in turn. The first section is repeated here:
[ndbd default]
DataMemory= 16G
IndexMemory= 12G
NoOfReplicas= 2
The [ndbd default]
heading indicates that
all attributes defined in this section apply to all cluster
data nodes. We can set all three attributes listed in this
section of the file for all data nodes in
newcluster
, using the
set
command shown here:
mcm> set DataMemory:ndbd=16G,IndexMemory:ndbd=12G,NoOfReplicas:ndbd=2 newcluster;
+-----------------------------------+
| Command result |
+-----------------------------------+
| Cluster reconfigured successfully |
+-----------------------------------+
1 row in set (0.36 sec)
You can verify that the desired changes have taken effect
using the get
command, as
shown here:
mcm> get DataMemory:ndbd,IndexMemory:ndbd,NoOfReplicas:ndbd newcluster;
+--------------+-------+----------+---------+----------+---------+---------+---------+
| Name | Value | Process1 | NodeId1 | Process2 | NodeId2 | Level | Comment |
+--------------+-------+----------+---------+----------+---------+---------+---------+
| DataMemory | 16G | ndbd | 5 | | | Process | |
| IndexMemory | 12G | ndbd | 5 | | | Process | |
| NoOfReplicas | 2 | ndbd | 5 | | | Process | |
| DataMemory | 16G | ndbd | 6 | | | Process | |
| IndexMemory | 12G | ndbd | 6 | | | Process | |
| NoOfReplicas | 2 | ndbd | 6 | | | Process | |
+--------------+-------+----------+---------+----------+---------+---------+---------+
6 rows in set (0.07 sec)
The next section in the file is shown here:
[ndb_mgmd]
HostName=alpha
NodeId=1
This section of the file applies to the management node. We
set its NodeId
and
HostName
attributes
previously, when we created newcluster
. No
further changes are required at this time.
The next two sections of the config.ini
file, shown here, contain configuration values specific to
each of the data nodes:
[ndbd]
NodeId=5
HostName=beta
DataDir=/var/lib/mysql-cluster
[ndbd]
NodeId=6
HostName=gamma
DataDir=/var/lib/mysql-cluster
As was the case for the management node, we already provided
the correct node IDs and host names for the data nodes when we
created newcluster
, so only the
DataDir
attribute
remains to be set. We can accomplish this by executing the
following command in the mcm client:
mcm> set DataDir:ndbd:5=/var/lib/mysql-cluster,DataDir:ndbd:6=/var/lib/mysql-cluster \
newcluster;
+-----------------------------------+
| Command result |
+-----------------------------------+
| Cluster reconfigured successfully |
+-----------------------------------+
1 row in set (0.42 sec)
You may have noticed that we could have set the
DataDir
attribute on
the process level using the shorter and simpler command
set DataDir:ndbd=/var/lib/mysql-cluster
newcluster
, but since this attribute was defined
individually for each data node in the original configuration,
we match this scope in the new configuration by setting this
attribute for each ndbd instance instead.
Once again, we check the result using the
mcm client
get
command, as shown here:
mcm> get DataDir:ndbd newcluster;
+---------+------------------------+----------+---------+----------+---------+-------+---------+
| Name | Value | Process1 | NodeId1 | Process2 | NodeId2 | Level | Comment |
+---------+------------------------+----------+---------+----------+---------+-------+---------+
| DataDir | /var/lib/mysql-cluster | ndbd | 5 | | | | |
| DataDir | /var/lib/mysql-cluster | ndbd | 6 | | | | |
+---------+------------------------+----------+---------+----------+---------+-------+---------+
2 rows in set (0.01 sec)
Configuration attributes for the SQL node are contained the next section of the file, shown here:
[mysqld]
NodeId=100
HostName=delta
The NodeId
and
HostName
attributes
were already set when we added the mysqld
process to newcluster
, so no additional
set
commands are required at
this point. Keep in mind that there may be
additional local configuration values for this
mysqld that must be accounted for in the
configuration we are creating for
newcluster
; we discuss how to
determine these values on the SQL node later in this section.
The remaining section of the file, shown here, contains a section defining attributes for a “free” API node that is not required to connect from any particular host:
[ndbapi]
NodeId=101
We have already set the NodeId
and there is
no need for a HostName
for a free process.
There are no other attributes that need to be set for this
node.
For more information about the MySQL
config.ini
global configuration file, see
NDB Cluster Configuration Files, and
NDB Cluster Configuration: Basic Example.
As mentioned earlier in this section, each
mysqld process (SQL node) may have, in
addition to any attributes set in
config.ini
, its own configuration data in
the form of system variables which are specific to that
mysqld. These can be set in two ways:
Because the initial values of many options can be changed at
runtime, it is recommended that—rather than attempt to
read the my.cnf
or
my.ini
file—you check values for
all system variables on each SQL node “live” in
the mysql client by examining the output of
the SHOW VARIABLES
statement,
and execute set
commands
setting each of these values where it differs from the default
for that variable on that SQL node.
The mcm client can execute a script file
containing client commands. The contents of such a script,
named my-commands.mcm
, which contains all
commands we executed to create and configure
newcluster
, are shown here:
create cluster --import --package=newpackage --processhosts=ndb_mgmd:50@alpha,ndbd:5@beta,ndbd:6@gamma newcluster;
add process --processhosts=mysqld:100@delta,ndbapi:101@* newcluster;
set DataMemory:ndbd=16G,IndexMemory:ndbd=12G,NoOfReplicas:ndbd=2 newcluster;
set DataDir:ndbd:5=/var/lib/mysql-cluster,DataDir:ndbd:6=/var/lib/mysql-cluster newcluster;
You can run such a script by invoking the client from the command line with a redirection operator, like this:
$> mcm < my-commands.mcm
脚本文件的名称完全是任意的。它必须仅包含有效的mcm客户端命令或注释。(注释由
#
字符分隔,并从行中找到注释的位置延伸到行尾。)任何有效的mcm客户端命令都可以在此类文件中使用。mcm必须能够读取该文件,但该文件不需要可执行,也不需要任何其他用户可读。