Home Database Mysql Tutorial MySQL - Detailed explanation of MySQL Cluster cluster construction (based on RPM installation package dual management center)

MySQL - Detailed explanation of MySQL Cluster cluster construction (based on RPM installation package dual management center)

Jan 21, 2017 pm 12:01 PM

1. Download mysql-cluster 7.3.7

http://dev.mysql.com/downloads/cluster/


2. Environment Cleaning and installation

1) Clean up the MySQL service that comes with CentOS6.5. I don’t have to execute the first command. If it is not possible on other systems, it is recommended to execute it

# yum -y remove mysql  
# rpm -qa | grep mysql*  
# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
Copy after login

2) Environment preparation
Create folders (divided into the following three categories to create corresponding folders)

存储节点:# mkdir /var/lib/mysql/data   
管理节点:# mkdir /var/lib/mysql-cluster    SQL节点:可不用  文件夹授权  
进程DIR:# mkdir /var/run/mysqld                
使用如下的命令来变更权限保证可写入:  
# chmod -R 1777 /var/lib/mysql  
# chmod -R 1777 /var/run/mysqld  
# chmod -R 1777 /var/lib/mysql-cluster
Copy after login

3) Install mysql-cluster

首先解压MySQL-Cluster-gpl-7.4.2-1.el6.x86_64.rpm-bundle.tar  
# tar xvf MySQL-Cluster-gpl-7.4.2-1.el6.x86_64.rpm-bundle.tar  
然后执行如下命令安装  
# rpm -ivh MySQL-Cluster-server-gpl-7.3.4-1.el6.x86_64.rpm  
# rpm -ivh MySQL-Cluster-client-gpl-7.3.4-1.el6.x86_64.rpm
Copy after login

Pay special attention when the installation is completed After the server gpl package, the following prompt message will appear, reminding us that the first super account password after the entire cluster is installed exists in the file /root/.mysql_secret.

---------------------------------------------------------------------------------------------------------------------  
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !  
You will find that password in '/root/.mysql_secret'.  
You must change that password on your first connect,  
no other statement but 'SET PASSWORD' will be accepted.  
See the manual for the semantics of the 'password expired' flag.  
Also, the account for the anonymous user has been removed.  
In addition, you can run:  
/usr/bin/mysql_secure_installation  
which will also give you the option of removing the test database.  
This is strongly recommended for production servers.  
-----------------------------------------------------------
Copy after login

3. Configure the management node

1) Execute the following command:

# cd /var/lib/mysql-cluster  
# vi config.ini
Copy after login

2) Configure the config.ini file, such as the configuration in attachment
100.218 File:

config.ini

Configuration information:

[computer]  
Id=mgr-server-01  
HostName=192.168.100.218  
[mgm default]  
datadir=/var/lib/mysql-cluster  
[mgm]  
HostName=192.168.100.218  
NodeId=60  
[mgm]  
HostName=192.168.100.217  
NodeId=61  
[ndbd default]  
NoOfReplicas = 2  
DataMemory = 50M  
IndexMemory = 50M  
MaxNoOfTables = 1024  
MaxNoOfAttributes = 5000000  
MaxNoOfOrderedIndexes = 10000  
[ndbd]  
HostName=192.168.100.217  
DataDir=/var/lib/mysql  
NodeId=1  
[ndbd]  
HostName=192.168.100.218  
DataDir=/var/lib/mysql  
NodeId=2  
[mysqld]  
HostName=192.168.100.217  
NodeId=81  
[mysqld]  
HostName=192.168.100.218  
NodeId=82
Copy after login

100.217 configuration file
config.ini

[computer]  
Id=mgr-server-02  
HostName=192.168.100.217  
[mgm default]  
datadir=/var/lib/mysql-cluster  
[mgm]  
HostName=192.168.100.218  
NodeId=60  
[mgm]  
HostName=192.168.100.217  
NodeId=61  
[ndbd default]  
NoOfReplicas = 2  
DataMemory = 50M  
IndexMemory = 50M  
MaxNoOfTables = 1024  
MaxNoOfAttributes = 5000000  
MaxNoOfOrderedIndexes = 10000  
[ndbd]  
HostName=192.168.100.217  
DataDir=/var/lib/mysql  
NodeId=1  
[ndbd]  
HostName=192.168.100.218  
DataDir=/var/lib/mysql  
NodeId=2  
[mysqld]  
HostName=192.168.100.217  
NodeId=81  
[mysqld]  
HostName=192.168.100.218  
NodeId=82
Copy after login

In fact, there is no difference between the two files The big one lies in the name and ID in the computer configuration


4. Configuration of SQL node and data node

Modify the my.cnf file , add the following content:

[client]  
socket=/var/lib/mysql/mysql.sock  
[mysqld]  
max_connections=100  
datadir=/var/lib/mysql  
socket=/var/lib/mysql/mysql.sock  
ndbcluster  
ndb-connectstring=192.168.100.218,192.168.100.217  
[mysqld_safe]  
log-error=/var/log/mysqld.log  
#pid-file=/var/run/mysqld/mysqld.pid  
pid-file=/var/lib/mysql/mysqld.pid  
[mysql_cluster]  
ndb-connectstring=192.168.100.218,192.168.100.217
Copy after login

5. MySQL Cluster initial startup command and user password change adjustment: (Please start in strict accordance with the order)

1) Start mysql-cluster
Perform initial startup Please confirm that the firewalls of the two machines are turned off (service iptables stop or set the firewall ports to be passable, the two ports are communication port 1186 and data port 3306)
Start mgt console command for the first time: ndb_mgmd -f /var/ lib/mysql-cluster/config.ini (initialization needs to be added --initial)
Start a balanced node command: NDBD-Initial
Start Data Node Command: MySQLD_SAFE-DEFAULTS-FILE =/usr/my.cnf --explicit_defaults_for_timestamp &
my.cnf is in the etc directory in some systems
Note that the entire console output needs to be monitored during the startup process. If any error messages are found, they need to be resolved promptly and based on the error log content.
-------------------------------------------------- -------------------------------------------------- --------
If everything is normal, use the following command to open the Management console: ndb_mgm
Execute# show
Check whether each node has been fully started, as follows, each node has been connected , if there is a node that is not connected, you will see

ndb_mgm> show  
Connected to Management Server at: 192.168.100.218:1186  
Cluster Configuration  
---------------------  
[ndbd(NDB)] 2 node(s)  
id=1 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0)  
id=2 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0, *)  
[ndb_mgmd(MGM)] 1 node(s)  
id=60 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2)  
id=61 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2)  
[mysqld(API)] 2 node(s)  
id=81 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2)  
id=82 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2)
Copy after login

If there is a node that is not connected, as shown below, a line with id=81 means there is no connection, check the problem fault point

ndb_mgm> show  
Cluster Configuration  
---------------------  
[ndbd(NDB)] 2 node(s)  
id=1 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0)  
id=2 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0, *)  
[ndb_mgmd(MGM)] 1 node(s)  
id=60 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2)  
id=61 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2)  
[mysqld(API)] 2 node(s)  
id=81 (not connected, accepting connect from 192.168.100.217)  
id=82 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2)
Copy after login

2) Modify password
When mysqld starts normally (you can use pgrep mysqld to obtain the process ID), we can use the following command to modify:
mysql -u root -p;
Random password (see /root for details) /.mysql_secret file), use the following command to change the password after entering:
SET PASSWORD = PASSWORD('new password');
But this new password must be a hash value, so use the following method to obtain the password characters The hash value of the string
select password('111111');
However, executing the above command will ask you to set the password first, which is frustrating, but it comes back again, so go to mysql elsewhere and execute it## The hash value of #111111 is "*FD571203974BA9AFE270FE62151AE967ECA5E0AA"
SET PASSWORD = PASSWORD('*FD571203974BA9AFE270FE62151AE967ECA5E0AA');
It’s so depressing. After setting it up, you still have to use ciphertext to log in. Well, just Use ciphertext Go in, use the following command after entering, force the use of clear text to log in

use mysql;  
delete from user;  
grant all on *.* to root@'%' identified by "111111" with grant option;  
flush privileges;  
quit;
Copy after login
然后,可以使用明文密码登陆了
几台装有SQL数据节点的服务器皆需要执行一遍上述命令;

6、当上面步奏都操作完成以后,测试cluster是否正常工作
1)简单功能测试
在218上进入mysql后执行如下:
Copy after login
create database clustertest;  
use clustertest;   
CREATE TABLE testtable(Count INT) ENGINE=NDBCLUSTER;
Copy after login

Note: ENGINE=NDBCLUSTER; The engine must use NDBCLUSTER to synchronize, otherwise the synchronization will not be performed

Check whether it is successful, on 217, Go to mysql and check whether the database and table are automatically created. If they are created, it means success. If it fails, please check the environment configuration
2) Test whether the data can be synchronized in disaster recovery situations (one database is stopped and restarted Will the lost data be automatically replenished?)
Stop the mysql service on 217, execute

insert into testtable values (1);
Copy after login

on 218 to start the mysql service of 217, and use show to confirm that the database node of 217 has been connected. Now, execute the following statement


select * from testtable;
Copy after login

If data is found, it means the function is complete



7. Close Cluster: (Requires strict Execute in order)

Close the data node: # mysqld stop (SQL node can be shut down using mysqladmin shutdown or other methods. )

Execute on the management node: # ndb_mgm -e shutdown
will safely shut down the management node and data node.
After closing, use the following process detection command to check whether it exited:

# pgrep mysqld  
# ps aux | grep nbdb
Copy after login

If not, find the corresponding pid and perform the kill operation

kill -9 process number


8. Start the Cluster plan again:

The sequence of starting the entire cluster. Note that some statements have been subtracted from the initialization content:

ndb_mgmd -f /var/lib/mysql-cluster/config.ini  
ndbd  
mysqld_safe --defaults-file=/usr/my.cnf --explicit_defaults_for_timestamp &
Copy after login

备注:

1、mysql安装后,默认会自动启动的,每次启动cluster的时候,都需要先把mysql的服务关闭,太麻烦,于是可以执行如下命令(我出手有点狠):

chkconfig --level 123456 mysql off
Copy after login

2、防火墙问题,偷个懒,我懒得去一一开放端口,干脆把防火墙直接关了(极不推荐的做法)

chkconfig --level 123456 iptables off
Copy after login

参考相关文档:

MySQL Cluster config.ini文件配置详解:

    http://note.youdao.com/share/?id=376407a1136d2032afb6ef68aa39fba5&type=note

    http://note.youdao.com/share/?id=3906996cbe3298a22fbb5a2196d6cbed&type=note

MySQL Cluster 备份与恢复 http://www.linuxidc.com/Linux/2013-06/85295.htm

MySQL Cluster安装配置 http://www.linuxidc.com/Linux/2013-07/87705.htm

MySQL Cluster 3台机器搭建集群环境 DOC http://www.linuxidc.com/Linux/2013-01/78249.htm

MySQL Cluster7.2在线增加数据节点存在重大弊端 http://www.linuxidc.com/Linux/2012-08/67605.htm

搭建MySQL-Cluster集群架构   http://www.linuxidc.com/Linux/2014-05/102218.htm

以上就是 MySQL之——MySQL Cluster集群搭建详解(基于RPM安装包 双管理中心)的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Monitor Redis Droplet with Redis Exporter Service Monitor Redis Droplet with Redis Exporter Service Apr 10, 2025 pm 01:36 PM

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings

How to view sql database error How to view sql database error Apr 10, 2025 pm 12:09 PM

The methods for viewing SQL database errors are: 1. View error messages directly; 2. Use SHOW ERRORS and SHOW WARNINGS commands; 3. Access the error log; 4. Use error codes to find the cause of the error; 5. Check the database connection and query syntax; 6. Use debugging tools.

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

See all articles