官方文档翻译版本(5.7.22-ndb-7.5.10-cluster-gpl)

一、环境搭建

共需要5台服务器,服务器分配如下: 
管理节点:192.168.1.117

数据节点1:192.168.1.228
数据节点2:192.168.1.229
sql节点1:192.168.1.230
sql节点2:192.168.1.232
设备的连接方式如下图所示:

Installing an NDB Cluster Binary Release on Linux

4.2.1 Installing an NDB Cluster Binary Release on Linux

4.2.2 Installing NDB Cluster from RPM

4.2.3 Installing NDB Cluster Using .deb Files

4.2.4 Building NDB Cluster from Source on Linux

This section covers installation methods for NDB Cluster on Linux and other Unix-like operating systems. While the next few sections refer to a Linux operating system, the instructions and procedures given there should be easily adaptable to other supported Unix-like platforms. For manual installation and setup instructions specific to Windows systems, see Section 4.3, “Installing NDB Cluster on Windows”.

Each NDB Cluster host computer must have the correct executable programs installed. A host running an SQL node must have installed on it a MySQL Server binary (mysqld). Management nodes require the management server daemon (ndb_mgmd); data nodes require the data node daemon (ndbd or ndbmtd). It is not necessary to install the MySQL Server binary on management node hosts and data node hosts. It is recommended that you also install the management client (ndb_mgm) on the management server host.

Installation of NDB Cluster on Linux can be done using precompiled binaries from Oracle (downloaded as a .tar.gz archive), with RPM packages (also available from Oracle), or from source code. All three of these installation methods are described in the section that follow.

Regardless of the method used, it is still necessary following installation of the NDB Cluster binaries to create configuration files for all cluster nodes, before you can start the cluster. See Section 4.4, “Initial Configuration of NDB Cluster”.

4.2.1 Installing an NDB Cluster Binary Release on Linux

This section covers the steps necessary to install the correct executables for each type of Cluster node from precompiled binaries supplied by Oracle.

For setting up a cluster using precompiled binaries, the first step in the installation process for each cluster host is to download the binary archive from the NDB Cluster downloads page. (For the most recent 64-bit NDB 7.5 release, this is mysql-cluster-gpl-7.5.10-linux-glibc2.12-x86_64.tar.gz.) We assume that you have placed this file in each machine's /var/tmp directory.

If you require a custom binary, see Installing MySQL Using a Development Source Tree.

Note

After completing the installation, do not yet start any of the binaries. We show you how to do so following the configuration of the nodes (see Section 4.4, “Initial Configuration of NDB Cluster”).

SQL nodes.  On each of the machines designated to host SQL nodes, perform the following steps as the system root user:

0.

复制mysql-cluster-gpl-7.5.10-linux-glibc2.12-x86_64.tar.gz/var/tmp

1. 

Check your /etc/passwd and /etc/group files (or use whatever tools are provided by your operating system for managing users and groups) to see whether there is already a mysql group and mysql user on the system. Some OS distributions create these as part of the operating system installation process. If they are not already present, create a new mysql user group, and then add a mysql user to this group:

2. 

shell> groupadd mysql

shell> useradd -g mysql -s /bin/false mysql

3. 

The syntax for useradd and groupadd may differ slightly on different versions of Unix, or they may have different names such as adduser and addgroup.

4. 

Change location to the directory containing the downloaded file, unpack the archive, and create a symbolic link named mysql to the mysql directory.

Note

5. 

The actual file and directory names vary according to the NDB Cluster version number.

6. 

shell> cd /var/tmp

shell> tar -C /usr/local -xzvf mysql-cluster-gpl-7.5.10-linux-glibc2.12-x86_64.tar.gz

shell> ln -s /usr/local/mysql-cluster-gpl-7.5.10-linux-glibc2.12-x86_64 /usr/local/mysql

7. 

Change location to the mysql directory and set up the system databases using mysqld --initialize as shown here:

8. 

shell> /usr/local/mysql/bin/mysqld --initialize

 

[root@service4 bin]# /usr/local/mysql/bin/mysqld --initialize

2018-05-22T03:30:38.134372Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more

 details).2018-05-22T03:30:39.989963Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-05-22T03:30:40.201769Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-05-22T03:30:40.318136Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 80307a3

a-5d70-11e8-a573-000c294bee12.2018-05-22T03:30:40.322041Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2018-05-22T03:30:40.343593Z 1 [Note] A temporary password is generated for root@localhost: rurs(>qiA3yu

 

[root@service5 tmp]# /usr/local/mysql/bin/mysqld --initialize

2018-05-22T05:09:03.827871Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for mor

e details).2018-05-22T05:09:04.329622Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-05-22T05:09:04.474954Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-05-22T05:09:04.608591Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3f6bb4

56-5d7e-11e8-a06a-000c2978f015.2018-05-22T05:09:04.611151Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2018-05-22T05:09:04.629256Z 1 [Note] A temporary password is generated for root@localhost: 3UDcdLqbc<I!

 

 

9. 

This generates a random password for the MySQL root account. If you do not want the random password to be generated, you can substitute the --initialize-insecure option for --initialize. In either case, you should review Initializing the Data Directory Manually Using mysqld, for additional information before performing this step. See also mysql_secure_installation — Improve MySQL Installation Security.

 --initialize-insecure代替 --initialize可以不产生密码

10. 

Set the necessary permissions for the MySQL server and data directories:

11. 

shell> cd /usr/local/mysql

shell> chown -R root .

shell> chown -R mysql data

shell> chgrp -R mysql .

12. 

Copy the MySQL startup script to the appropriate directory, make it executable, and set it to start when the operating system is booted up:

13. 

shell> cp support-files/mysql.server /etc/rc.d/init.d/

shell> chmod +x /etc/rc.d/init.d/mysql.server

shell> chkconfig --add mysql.server

14. 

(The startup scripts directory may vary depending on your operating system and version—for example, in some Linux distributions, it is /etc/init.d.)

15. 

Here we use Red Hat's chkconfig for creating links to the startup scripts; use whatever means is appropriate for this purpose on your platform, such as update-rc.d on Debian.

16. 

Remember that the preceding steps must be repeated on each machine where an SQL node is to reside.

Data nodes.  Installation of the data nodes does not require the mysqld binary. Only the NDB Cluster data node executable ndbd (single-threaded) or ndbmtd (multi-threaded) is required. These binaries can also be found in the .tar.gz archive. Again, we assume that you have placed this archive in /var/tmp.

As system root (that is, after using sudosu root, or your system's equivalent for temporarily assuming the system administrator account's privileges), perform the following steps to install the data node binaries on the data node hosts:

1. 

Change location to the /var/tmp directory, and extract the ndbd and ndbmtd binaries from the archive into a suitable directory such as /usr/local/bin:

2. 

shell> cd /var/tmp

shell> tar -zxvf mysql-cluster-gpl-7.5.10-linux-glibc2.12-x86_64.tar.gz

shell> cd mysql-cluster-gpl-7.5.10-linux-glibc2.12-x86_64

shell> cp bin/ndbd /usr/local/bin/ndbd

shell> cp bin/ndbmtd /usr/local/bin/ndbmtd

3. 

(You can safely delete the directory created by unpacking the downloaded archive, and the files it contains, from/var/tmp once ndb_mgm and ndb_mgmd have been copied to the executables directory.)

4. 

Change location to the directory into which you copied the files, and then make both of them executable:

5. 

shell> cd /usr/local/bin

shell> chmod +x ndb*

6. 

The preceding steps should be repeated on each data node host.

Although only one of the data node executables is required to run an NDB Cluster data node, we have shown you how to install both ndbd and ndbmtd in the preceding instructions. We recommend that you do this when installing or upgrading NDB Cluster, even if you plan to use only one of them, since this will save time and trouble in the event that you later decide to change from one to the other.

Note

The data directory on each machine hosting a data node is /usr/local/mysql/data. This piece of information is essential when configuring the management node. (See Section 4.4, “Initial Configuration of NDB Cluster”.)

Management nodes.  Installation of the management node does not require the mysqld binary. Only the NDB Cluster management server (ndb_mgmd) is required; you most likely want to install the management client (ndb_mgm) as well. Both of these binaries also be found in the .tar.gz archive. Again, we assume that you have placed this archive in /var/tmp.

As system root, perform the following steps to install ndb_mgmd and ndb_mgm on the management node host:

1. 

Change location to the /var/tmp directory, and extract the ndb_mgm and ndb_mgmd from the archive into a suitable directory such as /usr/local/bin:

2. 

shell> cd /var/tmp

shell> tar -zxvf mysql-cluster-gpl-7.5.10-linux-glibc2.12-x86_64.tar.gz

shell> cd mysql-cluster-gpl-7.5.10-linux-glibc2.12-x86_64

shell> cp bin/ndb_mgm* /usr/local/bin

3. 

(You can safely delete the directory created by unpacking the downloaded archive, and the files it contains, from/var/tmp once ndb_mgm and ndb_mgmd have been copied to the executables directory.)

4. 

Change location to the directory into which you copied the files, and then make both of them executable:

5. 

shell> cd /usr/local/bin

shell> chmod +x ndb_mgm*

6. 

In Section 4.4, “Initial Configuration of NDB Cluster”, we create configuration files for all of the nodes in our example NDB Cluster.

 

 

 

4.4 Initial Configuration of NDB Cluster

In this section, we discuss manual configuration of an installed NDB Cluster by creating and editing configuration files.

NDB Cluster also provides a GUI installer which can be used to perform the configuration without the need to edit text files in a separate application. For more information, see Section 4.1, “The NDB Cluster Auto-Installer”.

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.

· 

Each data node or SQL node requires a my.cnf file that provides two pieces of information: a connection stringthat 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 the NDBCLUSTER storage engine.

· 

For more information on connection strings, see Section 5.3.3, “NDB Cluster Connection Strings”.

· 

The management node needs a config.ini file telling it how many 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.

· 

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:

shell> vi /etc/my.cnf

Note

We show vi being used here to create the file, but any text editor should work just as well.

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=192.168.1.117  # location of management server

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.

Important

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 will fail with an error. This is by design.

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 asroot):

shell> mkdir /var/lib/mysql-cluster

shell> cd /var/lib/mysql-cluster

shell> vi 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 replicas

DataMemory=80M    # How much memory to allocate for data storage

IndexMemory=18M   # How much memory to allocate for index storage

                  # For DataMemory and IndexMemory, we have used the

                  # default values. Since the "world" database takes up

                  # only about 500KB, this should be more than enough for

                  # this example NDB Cluster setup.

ServerPort=2202   # This the default value; however, you can use any

                  # port that is free for all the hosts in the cluster

                  # Note1: It is recommended that you do not specify the port

                  # number at all and simply allow the default value to be used

                  # instead

                  # Note2: The port was formerly specified using the PortNumber

                  # TCP parameter; this parameter is no longer available in NDB

                  # Cluster 7.5.

[ndb_mgmd]

# Management process options:

HostName=198.51.100.10          # Hostname or IP address of MGM node

DataDir=/var/lib/mysql-cluster  # Directory for MGM 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)

Note

[ndbd default]

# Options affecting ndbd processes on all data nodes:

NoOfReplicas=2    # Number of replicas

DataMemory=80M    # How much memory to allocate for data storage

IndexMemory=18M   # How much memory to allocate for index storage

                  # For DataMemory and IndexMemory, we have used the

                  # default values. Since the "world" database takes up

                  # only about 500KB, this should be more than enough for

                  # this example NDB Cluster setup.

ServerPort=2202   # This the default value; however, you can use any

                  # port that is free for all the hosts in the cluster

                  # Note1: It is recommended that you do not specify the port

                  # number at all and simply allow the default value to be used

                  # instead

                  # Note2: The port was formerly specified using the PortNumber

                  # TCP parameter; this parameter is no longer available in NDB

                  # Cluster 7.5.

[ndb_mgmd]

# Management process options:

HostName=192.168.1.117          # Hostname or IP address of MGM node

DataDir=/var/lib/mysql-cluster  # Directory for MGM node log files

[ndbd]

# Options for data node "A":

                                # (one [ndbd] section per data node)

HostName=192.168.1.228          # 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=192.168.1.229          # 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=192.168.1.230          # Hostname or IP address

                                # (additional mysqld connections can be

                                # specified for this node for various

                                # purposes such as running ndb_restore)

[mysqld]

# SQL node options:

HostName=192.168.1.232          # Hostname or IP address

                                # (additional mysqld connections can be

                                # specified for this node for various

                                # purposes such as running ndb_restore)

 

~                                                                                 

The world database can be downloaded from http://dev.mysql.com/doc/index-other.html.

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 inSection 4.5, “Initial Startup of NDB Cluster”.

For more detailed information about the available NDB Cluster configuration parameters and their uses, seeSection 5.3, “NDB Cluster Configuration Files”, and Chapter 5, Configuration of NDB Cluster. For configuration of NDB Cluster as relates to making backups, see Section 7.3.3, “Configuration for NDB Cluster Backups”.

Note

The default port for Cluster management nodes is 1186; the default port for data nodes is 2202. However, the cluster can automatically allocate ports for data nodes from those that are already free.

4.5 Initial Startup of NDB Cluster

Starting the cluster is not very difficult after it has been configured. Each cluster node process must be started separately, and on the host where it resides. The management node should be started first, followed by the data nodes, and then finally by any SQL nodes:

1. 

On the management host, issue the following command from the system shell to start the management node process:

2. 

mkdir -p /var/lib/mysql-cluster/

chown -R root /var/lib/mysql-cluster

如果不创建目录会报错:

[root@service1 mysql-cluster]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini

MySQL Cluster Management Server mysql-5.7.22 ndb-7.5.10

2018-05-22 13:44:49 [MgmtSrvr] INFO     -- The default config directory '/usr/local/mysql/mysql-cluster' does not exist. Trying to create it...

Failed to create directory '/usr/local/mysql/mysql-cluster', error: 2

2018-05-22 13:44:49 [MgmtSrvr] ERROR    -- Could not create directory '/usr/local/mysql/mysql-cluster'. Either create it manually or specify a different directory with --configdir

=<path>

 

shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini

3. 

The first time that it is started, ndb_mgmd must be told where to find its configuration file, using the -f or --config-file option. (See Section 6.4, “ndb_mgmd — The NDB Cluster Management Server Daemon”, for details.)

4. 

For additional options which can be used with ndb_mgmd, see Section 6.32, “Options Common to NDB Cluster Programs — Options Common to NDB Cluster Programs”.

5. 

6. 

On each of the data node hosts, run this command to start the ndbd process:

7. 

mkdir -p /usr/local/mysql/data

chown -R root /usr/local/mysql/data

如果不创建目录会报错:

[root@service2 bin]# ndbd

2018-05-22 14:05:30 [ndbd] INFO     -- Angel connected to '192.168.1.117:1186'

2018-05-22 14:05:30 [ndbd] INFO     -- Angel allocated nodeid: 2

2018-05-22 14:05:30 [ndbd] WARNING  -- Cannot change directory to '/usr/local/mysql/data', error: 2

2018-05-22 14:05:30 [ndbd] ERROR    -- Couldn't start as daemon, error: 'Failed to open logfile '/usr/local/mysql/data/ndb_2_out.log' for write, errno: 2'

 

shell> ndbd

8. 

If you used RPM files to install MySQL on the cluster host where the SQL node is to reside, you can (and should) use the supplied startup script to start the MySQL server process on the SQL node.

service mysql.server start

 

9. 

If all has gone well, and the cluster has been set up correctly, the cluster should now be operational. You can test this by invoking the ndb_mgm management node client. The output should look like that shown here, although you might see some slight differences in the output depending upon the exact version of MySQL that you are using:

shell> ndb_mgm

-- NDB Cluster -- Management Client --

ndb_mgm> SHOW

Connected to Management Server at: localhost:1186

Cluster Configuration

---------------------

[ndbd(NDB)]     2 node(s)

id=2    @198.51.100.30  (Version: 5.7.22-ndb-7.5.11, Nodegroup: 0, *)

id=3    @198.51.100.40  (Version: 5.7.22-ndb-7.5.11, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)

id=1    @198.51.100.10  (Version: 5.7.22-ndb-7.5.11)

[mysqld(API)]   1 node(s)

id=4    @198.51.100.20  (Version: 5.7.22-ndb-7.5.11)

The SQL node is referenced here as [mysqld(API)], which reflects the fact that the mysqld process is acting as an NDB Cluster API node.

Note

The IP address shown for a given NDB Cluster SQL or other API node in the output of SHOW is the address used by the SQL or API node to connect to the cluster data nodes, and not to any management node.

You should now be ready to work with databases, tables, and data in NDB Cluster. See Section 4.6, “NDB Cluster Example with Tables and Data”, for a brief discussion.

 

二、数据同步性测试 

1.更改密码及远程连接

[root@service5 mysql]# /usr/local/mysql/bin/mysql -u root -p

mysql>use mysql;

mysql> alter user 'root'@'localhost' identified by '';

Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;  

Query OK, 0 rows affected (0.01 sec)

开启远程连接:
mysql> update user set host = '%' where user = 'root'; 
mysql> flush privileges;  
mysql>  select host,user,authentication_string from user;

+-----------+---------------+-------------------------------------------+

| host      | user          | authentication_string                     |

+-----------+---------------+-------------------------------------------+

| %         | root          |                                           |

| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |

| localhost | mysql.sys     | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |

+-----------+---------------+-------------------------------------------+

3 rows in set (0.01 sec)

 

mysql>

2. 数据测试

192.168.1.230节点测试(SQL节点1):

[root@service4 mysql]# /usr/local/mysql/bin/mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 12

Server version: 5.7.22-ndb-7.5.10-cluster-gpl MySQL Cluster Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database testdb2;

Query OK, 1 row affected (0.06 sec)

 

mysql> use testdb2;

Database changed

mysql> CREATE TABLE td_test2 (i INT) ENGINE=NDB;

Query OK, 0 rows affected (0.35 sec)

 

mysql> INSERT INTO td_test2() VALUES (1);

Query OK, 1 row affected (0.03 sec)

mysql> SELECT * FROM td_test2;

+------+

| i    |

+------+

|    1 |

+------+

1 row in set (0.01 sec)

mysql>

192.168.1.232节点测试(SQL节点2):

mysql> use testdb2;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> SELECT * FROM td_test2;

+------+

| i    |

+------+

|    1 |

+------+

1 row in set (0.00 sec)

mysql>

三、关闭及重启

1. 管理节点及数据节点关闭

[root@service1 mysql-cluster]# /usr/local/bin/ndb_mgm -e shutdown

Connected to Management Server at: localhost:1186

3 NDB Cluster node(s) have shutdown.

Disconnecting to allow management server to shutdown.

[root@service1 mysql-cluster]#

2. SQL节点关闭

service mysql.server stop

3. 启动管理节点

[root@service1 mysql-cluster]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini

MySQL Cluster Management Server mysql-5.7.22 ndb-7.5.10

4. 启动数据节点

[root@service2 ~]# ndbd

2018-05-22 16:06:29 [ndbd] INFO     -- Angel connected to '192.168.1.117:1186'

2018-05-22 16:06:29 [ndbd] INFO     -- Angel allocated nodeid: 2

5.启动SQL节点

service mysql.server start

5. 从管理节点看其他节点状态

[root@service1 mysql-cluster]# ndb_mgm

-- NDB Cluster -- Management Client --

ndb_mgm> show

Connected to Management Server at: localhost:1186

Cluster Configuration

---------------------

[ndbd(NDB)] 2 node(s)

id=2 @192.168.1.228  (mysql-5.7.22 ndb-7.5.10, Nodegroup: 0, *)

id=3 @192.168.1.229  (mysql-5.7.22 ndb-7.5.10, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)

id=1 @192.168.1.117  (mysql-5.7.22 ndb-7.5.10)

[mysqld(API)] 2 node(s)

id=4 @192.168.1.230  (mysql-5.7.22 ndb-7.5.10)

id=5 @192.168.1.232  (mysql-5.7.22 ndb-7.5.10)

 

 


 

猜你喜欢

转载自blog.csdn.net/w892824196/article/details/80407338