Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Building and testing of MySQL Cluster

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Server preparation

1) MySQL Node 1 10.41.1.85

2) MySQL Node 2 10.41.1.84

3) ndb Node 1 10.41.1.83

4) ndb Node 2 10.41.1.82

5) Management node 10.41.1.81

2. Test environment

The five servers are all the same, which is not necessary, so the servers have been turned off iptables and selinux. Please decide the production environment according to the actual situation.

Systemctl stop firewalld # turn off the firewall

Systemctl disable firewalld # permanently turn off the firewall

Setenforce 0 # temporarily shuts down selinux

Sed-I / etc/selinux/config # permanently close selinux

Getenforce # View current status

3. Software preparation

Mysql-cluster-gpl-7.2.4-linux2.6-x86_64.tar.gz

4. Manage node installation and configuration

Create a directory:

Mkdir / usr/local/mysql/bin-p

Mkdir / data/mysql-cluster-p

Prepare the document

Cp. / mysql-cluster-gpl-7.2.4-linux2.6-x86_64/bin/ndb_mgm / usr/local/mysql/bin/

Cp. / mysql-cluster-gpl-7.2.4-linux2.6-x86_64/bin/ndb_mgmd / usr/local/mysql/bin/

Environment variable

Echo "export PATH=$PATH:/usr/local/mysql/bin" > > / etc/profile

Source / etc/profile

Configuration

Cd / data/mysql-cluster/

Touch config.ini

Cat / data/mysql-cluster/config.ini

[NDBD DEFAULT]

NoOfReplicas=1

DataMemory=64M

IndexMemory=16M

# manage nodes

[NDB_MGMD]

Nodeid=1

Hostname=10.41.1.81

Datadir=/data/mysql-cluster

# the first ndbd node:

[NDBD]

Nodeid=2

Hostname=10.41.1.83

Datadir=/data/mysql-cluster/data

# second ndbd node:

[NDBD]

Nodeid=3

Hostname=10.41.1.82

Datadir=/data/mysql-cluster/data

SQL node:

[MySQLD]

Nodeid=4

Hostname=10.41.1.85

[MySQLD]

Nodeid=5

Hostname=10.41.1.84

[MySQLD]

6. NDB node installation (data node)

Data Node 1: 10.41.1.83

Data Node 2: 10.41.1.82

Establish a user

Useradd mysql

Decompress mysql cluster

Tar zxf mysql-cluster-gpl-7.2.4-linux2.6-x86_64.tar.gz

Mv mysql-cluster-gpl-7.2.4-linux2.6-x86_64/ / usr/local/mysql/

Authorization

Cd / usr/local/mysql

Chown-R mysql.

Chgrp-R mysql.

Create a data directory and authorize (for data stored when not using NDB)

Mkdir / data/mysql-p

Chown-R mysql.mysql / data/mysql/

Initialization

/ usr/local/mysql/scripts/mysql_install_db-user=mysql-datadir=/data/mysql/-basedir=/usr/local/mysql

Authorized root

Chown-R root.

Configuration

\ cp support-files/my-large.cnf / etc/my.cnf

Cp support-files/mysql.server / etc/init.d/mysqld

Chmod 755 / etc/init.d/mysqld

Environment variable

Echo "export PATH=$PATH:/usr/local/mysql/bin" > > / etc/profile

Source / etc/profile

Create a directory (store the data of the NDB node)

Mkdir / data/mysql-cluster/data-p

Modify / etc/my.cnf file

Cat / etc/my.cnf

[mysqld]

Datadir=/data/mysql

Basedir= / usr/local/mysql

Ndbcluster

Ndb-connectstring=10.41.1.81

[MYSQL_CLUSTER]

Ndb-connectstring=10.41.1.81

Description:

If you want the environment to be as consistent as possible, it is recommended that you install the entire MySQL Server with the NDB Cluster storage engine on the NDB node as well as the SQL node. (the NDB node does not have to initialize the data, it has been tested, but I will still initialize.) the installation details are exactly the same as the SQL node above.

7. Install the MySQL node

Sql Node 1: 10.41.1.85

Sql Node 2: 10.41.1.84

Establish a user

Useradd mysql

Decompress mysql cluster

Tar zxf mysql-cluster-gpl-7.2.4-linux2.6-x86_64.tar.gz

Mv mysql-cluster-gpl-7.2.4-linux2.6-x86_64/ / usr/local/mysql/

Authorization

Cd / usr/local/mysql

Chown-R mysql.

Chgrp-R mysql.

Create a data directory and authorize (for data stored when not using NDB)

Mkdir / data/mysql-p

Chown-R mysql.mysql / data/mysql/

Initialization

/ usr/local/mysql/scripts/mysql_install_db-user=mysql-datadir=/data/mysql/-basedir=/usr/local/mysql

Authorized root

Chown-R root.

Configuration

\ cp support-files/my-large.cnf / etc/my.cnf

Cp support-files/mysql.server / etc/init.d/mysqld

Chmod 755 / etc/init.d/mysqld

Environment variable

Echo "export PATH=$PATH:/usr/local/mysql/bin" > > / etc/profile

Source / etc/profile

Create a directory (store the data of the NDB node)

Mkdir / data/mysql-cluster/data-p

Modify / etc/my.cnf file

Cat / etc/my.cnf

[mysqld]

Datadir=/data/mysql

Basedir= / usr/local/mysql

Ndbcluster

Ndb-connectstring=10.41.1.81

[MYSQL_CLUSTER]

Ndb-connectstring=10.41.1.81

Start using Cluster:

8. Start

The startup sequence is: manage node-> data node-> SQL node (very important)

A) start the management node:

Ndb_mgmd-f / data/mysql-cluster/config.ini

Check:

Netstat-ntlp | grep 1186

Ps-ef | grep ndb_mgmd | grep-v grep

B) start NDB (data node)

Note:

Add the-initial parameter only when you start for the first time or restart ndbd after a backup / restore or configuration change!

Ndbd-initial

Check:

Ps-ef | grep ndbd | grep-v grep

C) start the SQL node (start the mysql service)

/ etc/init.d/mysqld start

9. Ndb_mgm tool

A) show command to view cluster status

Ndb_mgm > show

Cluster Configuration

[ndbd (NDB)] 2 node (s)

Id=2 @ 10.41.1.83 (mysql-5.5.19 ndb-7.2.4, Nodegroup: 0, Master)

Id=3 @ 10.41.1.82 (mysql-5.5.19 ndb-7.2.4, Nodegroup: 1)

[ndb_mgmd (MGM)] 1 node (s)

Id=1 @ 10.41.1.81 (mysql-5.5.19 ndb-7.2.4)

[mysqld (API)] 3 node (s)

Id=4 @ 10.41.1.85 (mysql-5.5.19 ndb-7.2.4)

Id=5 @ 10.41.1.84 (mysql-5.5.19 ndb-7.2.4)

Id=6 (not connected, accepting connect from any host)

10. Test 1-NDB storage engine test

(1) create test tables test_table01 (no engine specified) and test_table02 (NDB storage engine) in the test_cluster library of any SQL node (I choose 10.41.1.85 here), set the storage engine to NDB, and insert two pieces of test data:

Mysql > create table test_table01 (id int, name varchar (20)) engine=ndb

Mysql > create table test_table02 (id int, name varchar (20))

Mysql > show tables

+-- +

Tables_in_test_cluster

+-- +

Test_table01

Test_table02

+-- +

2 rows in set (0.01sec)

Another sql node:

Mysql > show tables

+-- +

Tables_in_test_cluster

+-- +

Test_table02

+-- +

1 row in set (0.02 sec)

Indicates that only the ndb engine is synchronized.

(2) insert two pieces of test data into test_table02

Mysql > insert into T1 select 1 recording yayun'

Query OK, 1 row affected (0.11 sec)

Records: 1 Duplicates: 0 Warnings: 0

Mysql > insert into T1 select 1

Query OK, 1 row affected (0.03 sec)

Records: 1 Duplicates: 0 Warnings: 0

Data can be found on both sql nodes.

Mysql > select * from test_table02

+-+ +

Id | name

+-+ +

1 | cluster01

2 | cluster02

+-+ +

2 rows in set (0.00 sec)

Obviously, the data queried by the two SQL nodes are consistent.

(3) change the test table test_table02 engine to MyISAM on SQL node 10.41.1.85, and insert the test data again:

Mysql > alter table test_table02 engine=myisam

Query OK, 2 rows affected (0.90 sec)

Records: 2 Duplicates: 0 Warnings: 0

Mysql > insert into test_table02 value (3 recordings cluster03'); # 10.41.1.84

ERROR 1412 (HY000): Table definition has changed, please retry transaction

Insert the data and report the error directly.

11. Single point of failure testing

The management node does not require special configuration, but only needs to put the management tools and configuration files on multiple servers.

SQL node

The MySQL service stops on 10.41.1.84

Management node:

[mysqld (API)] 3 node (s)

Id=4 @ 10.41.1.85 (mysql-5.5.19 ndb-7.2.4)

Id=5 (not connected, accepting connect from 10.41.1.84)

Id=6 (not connected, accepting connect from any host)

10.41.1.85:

Mysql > insert into test_table02 value (4 minutes club 04')

Query OK, 1 row affected (0.00 sec)

Mysql > select from test_table02

+-+ +

Id | name

+-+ +

2 | cluster02

3 | cluster03

4 | cluster04

1 | cluster01

+-+ +

4 rows in set (0.00 sec)

10.41.1.85 Service enabled:

Mysql > select from test_table02

+-+ +

Id | name

+-+ +

3 | cluster03

4 | cluster04

1 | cluster01

2 | cluster02

+-+ +

4 rows in set (0.01sec)

The data is synchronized again.

NDB (data node)

The NDB process stops on data node 10.41.1.82

[root@node3 mysql] # ps-ef | grep ndbd

Root 15969 1 0 14:37? 00:00:04 ndbd-initial

Root 15970 15969 1 14:37? 00:00:47 ndbd-initial

Root 16029 15801 0 15:36 pts/3 00:00:00 grep-color=auto ndbd

Killall ndbd

Any sql node query:

Mysql > select from test_table02

ERROR 1296 (HY000): Got error 157' Unknown error code' from NDBCLUSTER

Unable to query

10.41.1.81:

Grep 'NoOfReplicas' / data/mysql-cluster/config.ini

NoOfReplicas=1 # number of mirrors per data node

Change the NoOfReplicas in the configuration file to 2, restart the cluster according to the previous steps, unable to start, and the NoOfReplicas parameters cannot be changed temporarily. We need to set it up at the beginning, and don't think of changing it later. If you re-ndbd-- initial, all data will be lost.

NoOfReplicas=2:

Management node needs to be started with initial parameter

Ndb_mgmd-- initial-f / data/mysql-cluster/config.ini

Data node (NDB) startup also needs to use ndbd-initial, data loss

Mysql > select from test_table02

ERROR 1146 (42S02): Table 'test_cluster.test_table02' doesn't exist

Mysql > create table test (

-> id int

-> name varchar (20)

->) engine=ndb

Query OK, 0 rows affected (0.85 sec)

Mysql > show tables

+-- +

Tables_in_test_cluster

+-- +

Test

+-- +

1 row in set (0.01 sec)

Mysql > insert into test value (1)

Query OK, 1 row affected (0.00 sec)

Mysql > insert into test value (2)

Query OK, 1 row affected (0.00 sec)

Mysql > select * from test

+-+ +

Id | name

+-+ +

1 | one

2 | two

+-+ +

2 rows in set (0.00 sec)

Stop the data node 10.41.1.82 again:

Both nodes can query normal data.

12. Shutdown of MySQL Cluster cluster

Shutdown order: SQL Node-> data Node-> Management Node (in MySQL Cluster environment, the shutdown of both the NDB node and the management node can be done in the hypervisor of the management node, or it can be shut down by nodes, but the SQL node cannot. Therefore, when shutting down the entire MySQL Cluster environment or shutting down a SQL node, you must first go to the host of the SQL node to close the SQL node program. The shutdown method is the same as the shutdown of MySQL Server. )

(1) SQL node shuts down

/ etc/init.d/mysqld stop

(2) (NDB) data node shutdown

Ndbd stop

(3) shutdown of the management node

Ndb_mgm > shutdown or command line: ndb_mgm-e shutdown

Summary:

The parameter NoOfReplicas cannot be changed temporarily.

Selinux,iptables and other related issues.

Note: refer to a large amount of network data.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report