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

Detailed code explanation of MySQL-Cluster cluster construction (based on RPM installation package)

Mar 14, 2017 pm 04:41 PM

1. Downloadmysql-cluster 7.3.7

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

2. Environment cleanup and installation

1) Clean up the mysql service that comes with CentOS6.5. I don’t have to execute the first command. If it doesn’t work 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 as follows 3 classes to create corresponding folders)
##

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

Unzip it firstMySQL-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
Copy after login

Then execute the following command to install


# 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

Special attention: after the server gpl package is installed, the following prompt message will appear to remind us that the initial super account password after the entire cluster installation exists /root /.mysql_secret in this file.


---------------------------------------------------------------------------------------------------------------------
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

2. 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


[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
 ExecuteOnComputer=mgr-server-01
 PortNumber=1186
 ArbitrationRank=2
 [ndbd default]
 NoOfReplicas=2
 DataMemory=500M
 IndexMemory=500M
 [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

3. Configuration of SQL nodes and data nodes

Modify the my.cnf file and 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
 [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
Copy after login

4. MySQL Cluster initial startup command and user password change adjustment: (Please strictly follow Sequential startup)

1) Start mysql-cluster
Before executing the initial startup, please confirm that the firewalls of the two machines are turned off (service iptables stop or set the firewall port to be passable. The two ports are communication port 1186 and data Port 3306)
Start the mgt console command for the first time: ndb_mgmd -f /var/lib/mysql-cluster/config.ini
Start the balancing node command:               ndbd --initial
Start the data node command:                                                                                                                                                                                                  defaults-file=/etc/my.cnf --explicit_defaults_for_timestamp &
Note that you need to monitor the entire console output during the startup process. If you find any
error messages, you need to solve them in time and solve them according to the contents of the error log. -------------------------------------------------- -------------------------------------------------- --------
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)
[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 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)
[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) Change the 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;
Copy after login

Random password (see /root for details) /.mysql_secret file), use the following command to change the password after entering:


SET PASSWORD = PASSWORD('新密码');
Copy after login

But this new password must be a

hash value, so use the following method to obtain the passwordThe hash value of string

select password('111111');
Copy after login

However, executing the above command will ask you to set a password first. Depressed, 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 for login, okay? Just use password After entering, use the following command to 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

Then, you can use the clear text password to log in

Several servers equipped with SQL data nodes need to execute the above command. ;

5. After the above steps are completed, test whether the cluster is working normally
1) Simple functional test
After entering mysql on 218, execute the following:

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 Failed, please check the environment configuration

2) Test whether the data can be synchronized in disaster recovery situations (if a database is stopped, will the lost data be automatically replenished when it is restarted)
Stop 217 mysql service, executed on 218

insert into testtable values (1);
Copy after login

启动217的mysql服务,使用show确认217的数据库节点已经连接上了,执行如下语句

select * from testtable;
Copy after login

如果发现有数据,则表示功能完备
6、关闭Cluster:(需要严格按照次序执行)
关闭数据节点:# mysqld stop (SQL节点可以用mysqladmin shutdown或别的方式关闭。)
在管理节点上执行:# ndb_mgm -e shutdown
将安全的关闭管理节点和数据节点。
关闭后使用如下的进程检测命令查看一下是否退出来了:

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

如果没有,找到对应的pid进行kill 操作即可
kill -9 进程号
7、再次启动Cluster方案:
启动整个cluster的次序,注意,一些语句已经减去了初始化的内容:

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

备注:
1、mysql安装后,默认会自动启动的,每次启动cluster的时候,都需要先把mysql的服务关闭,太麻烦,于是可以执行如下命令(我出手有点狠):
    chkconfig --level 123456 mysql off
2、防火墙问题,偷个懒,我懒得去一一开放端口,干脆把防火墙直接关了
    chkconfig --level 123456 mysql off

The above is the detailed content of Detailed code explanation of MySQL-Cluster cluster construction (based on RPM installation package). 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

Can I retrieve the database password in Navicat? Can I retrieve the database password in Navicat? Apr 08, 2025 pm 09:51 PM

Navicat itself does not store the database password, and can only retrieve the encrypted password. Solution: 1. Check the password manager; 2. Check Navicat's "Remember Password" function; 3. Reset the database password; 4. Contact the database administrator.

Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Apr 08, 2025 pm 07:12 PM

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

How to create navicat premium How to create navicat premium Apr 09, 2025 am 07:09 AM

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

How to view mysql How to view mysql Apr 08, 2025 pm 07:21 PM

View the MySQL database with the following command: Connect to the server: mysql -u Username -p Password Run SHOW DATABASES; Command to get all existing databases Select database: USE database name; View table: SHOW TABLES; View table structure: DESCRIBE table name; View data: SELECT * FROM table name;

How to view database password in Navicat for MariaDB? How to view database password in Navicat for MariaDB? Apr 08, 2025 pm 09:18 PM

Navicat for MariaDB cannot view the database password directly because the password is stored in encrypted form. To ensure the database security, there are three ways to reset your password: reset your password through Navicat and set a complex password. View the configuration file (not recommended, high risk). Use system command line tools (not recommended, you need to be proficient in command line tools).

How to copy tables in mysql How to copy tables in mysql Apr 08, 2025 pm 07:24 PM

Copying a table in MySQL requires creating new tables, inserting data, setting foreign keys, copying indexes, triggers, stored procedures, and functions. The specific steps include: creating a new table with the same structure. Insert data from the original table into a new table. Set the same foreign key constraint (if the original table has one). Create the same index. Create the same trigger (if the original table has one). Create the same stored procedure or function (if the original table is used).

See all articles