The complete packages are available on the apt repo and instructions for installing are
Installing MySQL NDB Cluster Using the APT Repository
and
NDB Cluster Installation.
Still, no service files for systemd are provided for management server and data nodes. The systemd model does not map nicely to MySQL Cluster.
Below follow an example of configuration and service files that should work for many cases, but not all.
One limitation is the clusters must have exactly one management server, and at most one data node per host.
If there are several management servers one will need to distinguish between restarting management server with or without --reload
. And one can not use ExecReload
in an easy way for the reload configuration cases since management server needs to be restarted also in that case.
Systemd Service Files Example
Note, using these systemd service files is not the recommended way to manage cluster since there are several short comings with them.
Example uses paths as they appear on Ubuntu 22.10 using the MySQL APT repo.
The example depends on these extra directories to be created
# mkdir /etc/mysql/cluster
# mkdir -m 700 /var/lib/mysql-cluster
# chown mysql:mysql /var/lib/mysql-cluster
And these configuration files to be added
/etc/mysql/conf.d/cluster.cnf
:
[mysql_cluster]
ndb-connectstring=<hostname-for-managementserver>
[mysqld]
ndbcluster
[ndb_mgmd]
config-file=/etc/mysql/cluster/config.ini
config-dir=/var/lib/mysql-cluster
/etc/mysql/cluster/config.ini
(the sections also has alias names [MGM] same as [ndb_mgmd], [DB] same as [ndbd], [API] same as [mysqld]):
[MGM]
DataDir=/var/lib/mysql-cluster
HostName=<hostname-for-managentserver>
[DB default]
DataDir=/var/lib/mysql-cluster
NoOfReplicas=3
LockPagesInMainMemory=1
DataMemory=100M
[DB]
HostName=<host#1-for-data-node>
[DB]
HostName=<host#2-for-data-node>
[DB]
HostName=<host#3-for-data-node>
[API]
HostName=<host#1-for-mysql-server>
[API]
HostName=<host#2-for-mysql-server>
[API]
HostName=<host#3-for-mysql-server>
[API]
# Empty section to be able to run other ndb client programs from anywhere
Service file for management server
/lib/systemd/system/ndb_mgmd.service
:
[Unit]
Description=MySQL Cluster Management Node
Documentation=man:ndb_mgmd(8)
After=network-online.target
Wants=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
WorkingDirectory=/var/lib/mysql-cluster
# Starting with --reload forces the config-file to be reread, but it works if
# there is only one managment server in the cluster.
# If there are more management servers one need to ensure that at most one
# management server at restarts with --reload.
ExecStart=/usr/sbin/ndb_mgmd --nodaemon --reload
Restart=on-failure
Service file for data node
/lib/systemd/system/ndbd.service
:
[Unit]
Description=MySQL Cluster Data Node
Documentation=man:ndbmtd(8)
After=network-online.target
Wants=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
WorkingDirectory=/var/lib/mysql-cluster
CapabilityBoundingSet=CAP_IPC_LOCK CAP_SYS_NICE
ExecStart=/usr/sbin/ndbmtd --nodaemon
Restart=on-failure
System Start
When bringing up the cluster, so called system (re)start, one first starts the management server
> systemctl start ndb_mgmd
and then all configured data nodes must be started, on each host with data nodes do:
> systemctl start ndbd
and then start all your MySQL servers:
> systemctl start mysql
Configuration Change
After updating the cluster configuration file, config.ini
, one first need to restart the management server with --reload
> systemctl restart ndb_mgmd
And then restart all data nodes and MySQL server such that they are aware of the new configuration. For data nodes one can use ndb_mgm
for restarts.
> ndb_mgm
ndb_mgm> 2 RESTART
Node 2: Node shutdown initiated
Node 2: Node shutdown completed, restarting, no start.
Node 2 is being restarted
Node 2: Start initiated (version 8.0.33)
Node 2: Started (version 8.0.33)
ndb_mgm> 3 RESTART
...
ndb_mgm> 4 RESTART
...
For configuration changes that needs initial node restarts one need to use 'RESTART -i'.
Configuration changes that need initial system restart will be trickier. That can not be handled using ndb_mgm
but one need to stop all data nodes and then start them with an extra --initial
option to the start command.
Systemd do not have alternative start command, and the ndbd service does not and should not include --initial
in the ExecStart
command. Instead one need to manually remove all the data from disk
# rm -rf /var/lib/mysql-cluster/ndb_<number>_fs/
And then start service as usual
# systemctl start ndbd
Warning: ExecReload=kill -HUP
does not work!
I searched internet for systemd service files for Ndb, and I found several all suggesting using kill -HUP
for ExecReload
to reload configuration - that does not work and have never worked, ndb_mgmd
ignores HUP
signal. Also for data nodes it is meaningless.
For ndb_mgmd
to reread config.ini
it needs to be restarted with --reload
command line option (except for the first time when there is no previous configuration read).
Comment on Comments on Question
The below is not really part of the answer but addresses some of the OP comments on question.
Comment#1
I want to add a third node to the cluster that will NOT have the data, as a tiebreaker.
If this about already having two data nodes in a nodegroup that have data, and then later add a third data node to the same nodegroup, that is not supported online by cluster.
All nodes in a nodegroup always must have the same data.
Changing the number of replicas requires so called initial system restart, start with an empty cluster and restore data from backup.
Adding nodes when adding a nodegroup can be done online, in this case the new nodegroup(s) will not have the same data as the original nodegroup(s), for this see Adding NDB Cluster Data Nodes Online
Comment#2
Which is highly frustrating as there is no node 3 in config.ini! It ONLY contains info for this one single host, and that ndbd config is node 2.
This sounds that the management server has not reread config.ini
, make sure that you restart management server using ndb_mgmd ... --reload
option after changing config.ini
.
Running on a different configuration than expected will bring much confusion.