NDB cluster installation
introduce
https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-basics.html
NDBCLUSTER (also known as NDB )Is a memory storage engine that provides high availability and data persistence.
Of NDBCLUSTER The storage engine can be configured with a range of failover and load balancing options, but the simplest is to start the storage engine at the cluster level. NDB Cluster's NDB The storage engine contains a complete set of data, which only depends on other data within the cluster itself.
The configuration of the cluster part of the NDB cluster is independent of the MySQL server. In an NDB cluster, each part of the cluster is treated as a node.
There are three types of cluster nodes, and in the smallest NDB cluster configuration, there will be at least three nodes, one of these types:
-
Management node: this type of node is used to manage other nodes in the NDB cluster, perform functions such as providing configuration data, starting and stopping nodes, and running backups. Because this node type manages the configuration of other nodes, you should start this type of node before starting any other nodes. Use command ndb_mgmd Start an MGM node.
-
Data node: this type of node stores cluster data.
NDB cluster tables are usually completely stored in memory, not on disk (that's why we call NDB clusters memory databases). However, some NDB cluster data can be stored on disk.
-
SQL node: This is the node that accesses the cluster data. For NDB clusters, SQL nodes use the NDBCLUSTER Traditional MySQL server for storing engine.
The SQL node is actually just a special type of API node that specifies any application accessing NDB cluster data. Another example of an API node is for restoring cluster backups ndb_restore Utility. You can write such an application using the NDB API.
1. Resource Planning
node |
IP address |
hardware resource |
system |
|
|
Management node (mgmd) |
192.168.137.128 |
1 CPU, 1G memory |
Centos7 |
|
|
Management node (mgmd) |
192.168.137.129 |
1 CPU, 1G memory |
Centos7 |
|
|
Data node "A" (ndbd) SQL node (mysqld) |
192.168.137.130 |
1 CPU, 3G memory (data nodes eat memory) |
Centos7 |
|
|
Data node "B" (ndbd) SQL node (mysqld) |
192.168.137.131 |
1 CPU, 3G memory |
Centos7 |
|
|
2. Download the installation files (192.168.137.130, 192.168.137.131)
Official website address: https://dev.mysql.com/downloads/cluster/
3.2 SQL node
Change the location to the directory containing the downloaded files, extract the archive files, and create a symbolic link named mysql to the mysql directory.
useradd mysql
tar -xf mysql-cluster-gpl-8.0.20-linux-glibc2.12-x86_64.tar.gz
mv mysql-cluster-gpl-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql
3.3 change the location to mysql directory, and use mysqld to set the system database -- initialize, as shown below:
#rm -rf /data/apps/mysql-8.0/ mkdir -p /data/apps/mysql-8.0/logs && chown -R mysql.mysql /data/apps/mysql-8.0 chown -R mysql.mysql /usr/local/mysql cat > /usr/local/mysql/my.cnf <<EOE [mysqld] basedir=/usr/local/mysql datadir=/data/apps/mysql-8.0/data socket=/tmp/mysql.sock user=mysql symbolic-links=0 lower_case_table_names=1 max_connections=2000 wait_timeout=120 interactive_timeout=120 key_buffer_size=128M tmp_table_size=16M read_buffer_size=4M read_rnd_buffer_size=16M sort_buffer_size=32M innodb_buffer_pool_size=1024M ndbcluster [mysqld_safe] log-error=/data/apps/mysql-8.0/logs/mysqld.log pid-file=/data/apps/mysql-8.0/mysqld.pid user=mysql [mysql_cluster] ndb-connectstring=192.168.137.128,192.168.137.129 EOEmv /etc/my.cnf /etc/my.cnf_`date +%F-%s`
ln -s /usr/local/mysql/my.cnf /etc/my.cnf
3.4 initialize database
/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/data/apps/mysql-8.0/data --initialize --user=mysql
Remember the code. Use it later
3.4 copy the MySQL startup script to the appropriate directory, make it executable, and set it to start when the operating system starts:
cp support-files/mysql.server /etc/rc.d/init.d/ chmod +x /etc/rc.d/init.d/mysql.server chkconfig --add mysql.server
4.1 for data nodes, copy the startup files of data nodes, for example, data nodes and sql nodes are on the same platform. This step is ignored
scp 192.168.137.130:/usr/local/mysql/bin/{ndbd,ndbmtd} /usr/local/bin/. cd /usr/local/bin chmod +x ndb* mkdir -p /data/apps/mysql-8.0
Repeat the above steps on each data node host.
5.1 management node. 137.128,137.129
scp 192.168.137.130:/usr/local/mysql/bin/ndb_mgm* /usr/local/bin/. cd /usr/local/bin chmod +x ndb_mgm*
mkdir -p /usr/local/mysql/mysql-cluster
5.2 configuration management node.
#Profile details
#https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-config-file.html
cat > /usr/local/mysql/config.ini <<EOE [ndbd default] # Options affecting ndbd processes on all data nodes: NoOfReplicas=2 # Number of replicas DataMemory=98M # How much memory to allocate for data storage [ndb_mgmd] NodeId=1 # Management process options: HostName=192.168.137.128 # Hostname or IP address of MGM node DataDir=/usr/local/mysql/mysql-cluster # Directory for MGM node log files [ndb_mgmd] NodeId=2 # Management process options: HostName=192.168.137.129 # Hostname or IP address of MGM node DataDir=/usr/local/mysql/mysql-cluster # Directory for MGM node log files [ndbd] # Options for data node "A": # (one [ndbd] section per data node) HostName=192.168.137.130 # Hostname or IP address NodeId=3 # Node ID for this data node DataDir=/data/apps/mysql-8.0 # Directory for this data node's data files [ndbd] # Options for data node "B": HostName=192.168.137.131 # Hostname or IP address NodeId=4 # Node ID for this data node DataDir=/data/apps/mysql-8.0 # Directory for this data node's data files [mysqld] NodeId=5 # SQL node options: HostName=192.168.137.130 # Hostname or IP address # (additional mysqld connections can be # specified for this node for various
[mysqld] # SQL node options: NodeId=6 HostName=192.168.137.131 # purposes such as running ndb_restore) EOE
6. Initial startup of NDB cluster
6.1 management host
/usr/local/mysql/bin/ndb_mgmd -f /usr/local/mysql/config.ini --initial (Add only after initialization)
6.2 on each data node host, run the following command to start ndbd Process:
ndbd --initial
If an error is reported, execute the following command
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1 ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
Restart successful:
6.3 Sql node start database:
/usr/local/mysql/bin/mysqld &
If all goes well and the cluster is set up correctly, the cluster should now be operational. You can call ndb_mgm Manage node clients to test this. The output should look like what is shown here, although you may see some slight differences in the output, depending on the MySQL version used:
Management node
The SQL node is called [mysqld(API)] here, which reflects mysqld The fact that a process acts as an NDB cluster API node.
7. Safely shut down and restart the NDB cluster
7.1 to shut down the cluster, enter the following command in the shell on the computer that hosts the management node:
NDB? MGM - e shutdown - e the options here are used to pass commands from the shell to the NDB? MGM client.
7.2 restart, management node executes
ndb_mgmd -f /usr/local/mysql/config.ini
7.3 execution at each data node
ndbd
7.4 use the NDB? MGM client to verify that both data nodes have started successfully.
7.5 on the SQL host:
/usr/local/mysql/bin/mysqld &
If one of the data nodes is hung up, one of the nodes must be fully recovered before the cluster can continue to use it
8. Other notes
You must set the primary key and add ENGINE=NDBCLUSTER when creating the table
create table s_position ( id int not null auto_increment, name varchar(20) not null default 'manager', #Set default description varchar(100), primary key PK_positon (id) #Set primary key ) ENGINE=NDBCLUSTER;