一旦您确认 NDB 集群正在如期运行,您可以将管理节点和数据节点安装为 Windows 服务,以便这些进程在 Windows 启动或停止时自动启动和停止。这也使得您可以从命令行使用适当的 SC START 和 SC STOP 命令,或者使用 Windows 图形化的 服务 实用程序。NET START 和 NET STOP 命令也可以使用。
通常,安装程序作为 Windows 服务必须使用具有 Administrator 权限的帐户。
要在 Windows 中将管理节点安装为服务,请在管理节点主机的命令行中 invoke ndb_mgmd.exe,使用 --install
选项,如下所示:
C:\> C:\mysql\bin\ndb_mgmd.exe --install
Installing service 'NDB Cluster Management Server'
as '"C:\mysql\bin\ndbd.exe" "--service=ndb_mgmd"'
Service successfully installed.
安装 NDB 集群程序作为 Windows 服务时,始终指定完整的路径;否则,服务安装可能会失败,显示错误 系统找不到指定的文件。
必须首先使用 --install
选项,然后是其他可能指定的选项 ndb_mgmd.exe。然而,建议在选项文件中指定这些选项。如果您的选项文件不在默认位置,如 ndb_mgmd.exe --help
的输出所示,您可以使用 --config-file
选项指定其位置。
现在您应该能够像这样启动和停止管理服务器:
C:\> SC START ndb_mgmd
C:\> SC STOP ndb_mgmd
如果使用 NET 命令,您也可以使用描述性名称启动或停止管理服务器作为 Windows 服务,如下所示:
C:\> NET START 'NDB Cluster Management Server'
The NDB Cluster Management Server service is starting.
The NDB Cluster Management Server service was started successfully.
C:\> NET STOP 'NDB Cluster Management Server'
The NDB Cluster Management Server service is stopping..
The NDB Cluster Management Server service was stopped successfully.
通常更简单的是指定一个短服务名称或允许使用默认服务名称安装服务,然后在启动或停止服务时引用该名称。
C:\> C:\mysql\bin\ndb_mgmd.exe --install=mgmd1
Installing service 'NDB Cluster Management Server'
as '"C:\mysql\bin\ndb_mgmd.exe" "--service=mgmd1"'
Service successfully installed.
要指定其他服务名称,而不是 ndb_mgmd
,请将其追加到 --install
选项,如下所示:
C:\> SC START mgmd1
C:\> SC STOP mgmd1
现在您应该能够使用指定的名称启动或停止服务,如下所示:
C:\> SC DELETE mgmd1
要删除管理节点服务,请使用 SC DELETE service_name
:
C:\> C:\mysql\bin\ndb_mgmd.exe --remove
Removing service 'NDB Cluster Management Server'
Service successfully removed.
或者,invoke ndb_mgmd.exe 使用 --remove
选项,如下所示:
C:\> C:\mysql\bin\ndb_mgmd.exe --remove=mgmd1
Removing service 'mgmd1'
Service successfully removed.
如果您使用其他服务名称安装了服务,请将服务名称作为 ndb_mgmd.exe --remove
选项的值,像这样:
C:\> C:\mysql\bin\ndbd.exe --install
Installing service 'NDB Cluster Data Node Daemon' as '"C:\mysql\bin\ndbd.exe" "--service=ndbd"'
Service successfully installed.
安装 NDB 集群数据节点进程作为 Windows 服务可以以类似的方式完成,使用 --install
选项 for ndbd.exe (或 ndbmtd.exe),如下所示:
C:\> SC START ndbd
C:\> SC STOP ndbd
现在您可以像这样启动或停止数据节点:
C:\> SC DELETE ndbd
或者,使用ndbd.exe带有--remove
选项,如下所示:
C:\> C:\mysql\bin\ndbd.exe --remove
Removing service 'NDB Cluster Data Node Daemon'
Service successfully removed.
与ndb_mgmd.exe(和mysqld.exe)一样,当安装ndbd.exe作为 Windows 服务时,也可以指定服务的名称作为--install
的值,然后在启动或停止服务时使用该名称,如下所示:
C:\> C:\mysql\bin\ndbd.exe --install=dnode1
Installing service 'dnode1' as '"C:\mysql\bin\ndbd.exe" "--service=dnode1"'
Service successfully installed.
C:\> SC START dnode1
C:\> SC STOP dnode1
如果在安装数据节点服务时指定了服务名称,则可以在删除服务时使用该名称,如下所示:
C:\> SC DELETE dnode1
或者,可以将服务名称作为--remove
选项的值传递给ndbd.exe
,如下所示:
C:\> C:\mysql\bin\ndbd.exe --remove=dnode1
Removing service 'dnode1'
Service successfully removed.
SQL 节点作为 Windows 服务的安装、启动服务、停止服务和删除服务的操作与上述类似,使用mysqld--install
、SC START、SC STOP和SC DELETE(或mysqld--remove
)。NET 命令也可以用来启动或停止服务。有关更多信息,请参阅第 2.3.3.8 节,“以 Windows 服务形式启动 MySQL”。