Home Database Mysql Tutorial Detailed explanation of MySQL-Cluster cluster construction (based on manual compilation of installation packages)

Detailed explanation of MySQL-Cluster cluster construction (based on manual compilation of installation packages)

Mar 14, 2017 pm 04:41 PM

Recently, due to being very busy at work, I haven’t updated my blog for a while. Today I will bring you an article on how to build a MySQL Cluster cluster. Okay, let’s go directly to the topic.

First of all, we need to uninstall the MySQL originally installed on the server. For details, please refer to the blog post "MySQL-Completely Uninstall MySQL Code Example under CentOS". At the same time, enter the following command on the command line to install the preparation environment:

yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc
* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*
Copy after login

This article will build a simplest MySQL Cluster system. All commands in the configuration method are run as the root account. This MySQL Cluster contains one management node, two data nodes, and two SQL nodes. These five nodes will be installed on five virtual machines respectively. The names and IPs of the virtual machines are as follows:

#192.168.124.142##Data nodeNode

#Management node

mysql-mgm

##192.168.124.141

##Data node

1

mysql-ndbd-1

2

mysql-ndbd-2

#192.168.124.143

##SQL
Node

1mysql-sql-1

192.168.124.144

##SQL

2

mysql-sql-2

192.168.124.145

一、公共配置

请在三个虚拟机上分别配置此处的配置项。


1. 安装虚拟机

虚拟机操作系统安装CentOS 6.5的x86_64版本,使用NAT网络,并且还要安装vmware-tools,具体安装方法此处不详述。

2. 拷贝mysql cluster

下载以下版本的MySQL-Cluster:

http://dev.mysql.com/Downloads/MySQL-Cluster-7.3/mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64.tar.gz

下载得到的压缩包拷贝至虚拟机的/root/Downloads目录,然后在shell中运行以下命令:

cd /root/Downloads
tar -xvzf mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64.tar.gz
mv mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64 /usr/local/mysql
Copy after login

3. 关闭安全策略

关闭iptables防火墙(或者打开防火墙的1186、3306端口),在Shell中运行以下命令:

chkconfig --level 35 iptables off
Copy after login

关闭SELinux,在Shell中运行以下命令:

gedit /etc/selinux/config
Copy after login

将config文件中的SELINUX项改为disabled,修改后的config文件的内容如下:


# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
Copy after login

最后重启系统

二、配置管理结点(192.168.124.141)

1. 配置config.ini配置文件

在shell中运行以下命令:


mkdir /var/lib/mysql-cluster
cd /var/lib/mysql-cluster
gedit config.ini
Copy after login

配置文件config.ini内容如下:


[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[ndb_mgmd]
NodeId=1
hostname=192.168.124.141
datadir=/var/lib/mysql-cluster
[ndbd]
NodeId=2
hostname=192.168.124.142
datadir=/usr/local/mysql/data
[ndbd]NodeId=3hostname=192.168.124.143datadir=/usr/local/mysql/data
[mysqld]NodeId=4hostname=192.168.124.144
[mysqld]
NodeId=5
hostname=192.168.124.145
Copy after login

2. 安装管理结点

安装管理节点,不需要mysqld二进制文件,只需要MySQL Cluster服务端程序(ndb_mgmd)和监听客户端程序(ndb_mgm)。在shell中运行以下命令:


cp /usr/local/mysql/bin/ndb_mgm* /usr/local/bin
cd /usr/local/bin
chmod +x ndb_mgm*
Copy after login

三、配置数据结点(192.168.124.142、192.168.124.143)

1. 添加mysql组和用户

在shell中运行以下命令:


groupadd mysql
useradd -g mysql mysql
Copy after login
Copy after login

2. 配置my.cnf配置文件

在shell中运行以下命令:


gedit /etc/my.cnf
Copy after login
Copy after login

配置文件my.cnf的内容如下:


[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/sock/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=192.168.124.141
Copy after login

3. 创建系统数据库

在shell中运行以下命令:


cd /usr/local/mysql
mkdir sock
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Copy after login
Copy after login

4. 设置数据目录

在shell中运行以下命令:


chown -R root .
chown -R mysql.mysql /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/sock
chgrp -R mysql .
Copy after login
Copy after login

5. 配置MySQL服务

在shell中运行以下命令:


cp support-files/mysql.server /etc/rc.d/init.d/
chmod +x /etc/rc.d/init.d/mysql.server
chkconfig --add mysql.server
Copy after login
Copy after login

四、配置SQL结点(192.168.124.144、192.168.124.145)

1. 添加mysql组和用户

在shell中运行以下命令:


groupadd mysql
useradd -g mysql mysql
Copy after login
Copy after login

2. 配置my.cnf配置文件

在shell中运行以下命令:


gedit /etc/my.cnf
Copy after login
Copy after login

配置文件my.cnf的内容如下:

[client]
socket=/usr/local/mysql/sock/mysql.sock
[mysqld]
ndbcluster
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/sock/mysql.sock
ndb-connectstring=192.168.124.141
[mysql_cluster]
ndb-connectstring=192.168.124.141
Copy after login

3. 创建系统数据库

在shell中运行以下命令:


cd /usr/local/mysql
mkdir sock
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Copy after login
Copy after login

4. 设置数据目录

在shell中运行以下命令:


chown -R root .
chown -R mysql.mysql /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/sock
chgrp -R mysql .
Copy after login
Copy after login

5. 配置MySQL服务

在shell中运行以下命令:


cp support-files/mysql.server /etc/rc.d/init.d/
chmod +x /etc/rc.d/init.d/mysql.server
chkconfig --add mysql.server
Copy after login
Copy after login


五、Cluster环境启动

注意启动顺序:首先是管理节点,然后是数据节点,最后是SQL节点。

1. 启动管理结点

在shell中运行以下命令:


ndb_mgmd -f /var/lib/mysql-cluster/config.ini
Copy after login

还可以使用ndb_mgm来监听客户端,如下:


ndb_mgm
Copy after login

2. 启动数据结点

首次启动,则需要添加--initial参数,以便进行NDB节点的初始化工作。在以后的启动过程中,则是不能添加该参数的,否则ndbd程序会清除在之前建立的所有用于恢复的数据文件和日志文件。


/usr/local/mysql/bin/ndbd --initial
Copy after login

如果不是首次启动,则执行下面的命令。


/usr/local/mysql/bin/ndbd
Copy after login

3. 启动SQL结点

若MySQL服务没有运行,则在shell中运行以下命令:


/usr/local/mysql/bin/mysqld_safe --user=mysql &
Copy after login

4. 启动测试

查看管理节点,启动成功:


六、集群测试

1. 测试一

现在我们在其中一个SQL结点上进行相关数据库的创建,然后到另外一个SQL结点上看看数据是否同步。


在SQL结点1(192.168.124.144)上执行:


shell> /usr/local/mysql/bin/mysql -u root -p
mysql>show databases;
mysql>create database aa;
mysql>use aa;
mysql>CREATE TABLE ctest2 (i INT) ENGINE=NDB; //这里必须指定数据库表的引擎为NDB,否则同步失败
mysql> INSERT INTO ctest2 () VALUES (1);
mysql> SELECT * FROM ctest2;
Copy after login

然后在SQL结点2上看数据是否同步过来了



经过测试,在非master上创建数据,可以同步到master上

查看表的引擎是不是NDB,>show create table 表名;

2. 测试二

关闭一个数据节点 ,在另外一个节点写输入,开启关闭的节点,看数据是否同步过来。

首先把数据结点1重启,然后在结点2上添加数据

在SQL结点2(192.168.124.145)上操作如下:


mysql> create database bb;
mysql> use bb;
mysql> CREATE TABLE ctest3 (i INT) ENGINE=NDB;
mysql> use aa;
mysql> INSERT INTO ctest2 () VALUES (3333);
mysql> SELECT * FROM ctest2;
Copy after login

等数据结点1启动完毕,启动数据结点1的服务


#/usr/local/mysql/bin/ndbd --initial#service mysqld start
Copy after login

然后登录进去查看数据


# /usr/local/mysql/bin/mysql -u root –p
Copy after login

可以看到数据已经同步过来了,说明数据可以双向同步了。

七、关闭集群

1. 关闭管理节点和数据节点,只需要在管理节点(ClusterMgm--134)里执行:


shell> /usr/local/mysql/bin/ndb_mgm -e shutdown
Copy after login

显示


Connected to Management Server at: localhost:1186
2 NDB Cluster node(s) have shutdown.
Disconnecting to allow management server to shutdown.
Copy after login

2. 然后关闭Sql节点(135,136),分别在2个节点里运行:


shell> /etc/init.d/mysql.server stop
Shutting down MySQL... SUCCESS!
Copy after login

注意:要再次启动集群,就按照第五部分的启动步骤即可,不过这次启动数据节点的时候就不要加”-initial”参数了。


The above is the detailed content of Detailed explanation of MySQL-Cluster cluster construction (based on manual compilation of installation packages). For more information, please follow other related articles on the PHP Chinese website!

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)

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

See all articles