


Detailed explanation of MySQL-Cluster cluster construction (based on RPM installation package dual management center)
There is no special point in the following. They are all commands that need to be executed by both servers. Since it is a dual management center configuration, in fact, the two machines have some different configurations of identification id and ip. The parameter configurations are basically the same
1. Downloadmysql-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 other systems are not possible, it is still recommended to perform
# yum -y remove mysql # rpm -qa | grep mysql* # rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
2) Environment preparation
Create folders (divided into the following 3 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
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
Pay 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 in /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. -----------------------------------------------------------
3. Configure the management node
1) Execute the following command:
# cd /var/lib/mysql-cluster # vi config.ini
2) Configure the config.ini file, as shown in the attachment
100.218Configuration 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
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
In fact, there is not much difference between the two files. It lies in the name and identification id in the computer configuration
4, the configuration of SQL node and data node
Modify 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
5. MySQL Cluster initial startup command and user password change adjustment: (Please start in strict accordance with the order)
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 ports to be accessible, 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 (initialization needs to add --initial)
Start a balanced node command: NDBD-Intial
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 you need to monitor the entire console output during the startup process and find that there are error messages It needs to be solved in time 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)
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) 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)
2) Change the password
When mysqld starts normally (you can use pgrep mysqld to get the process ID), we can use the following command to modify it:
mysql -u root -p;
Random password (please ask for details) See the /root/.mysql_secret file to obtain). After entering, use the following command to change the password:
SET PASSWORD = PASSWORD('new password');
But this new password must be a hash value , so you need to use the following method to get the hash value of the password String
select password('111111');
However, executing the above command will make you set the password first, which is frustrating, and then come back. , then go to mysql elsewhere and execute it.
The hash value of 111111 is "*FD571203974BA9AFE270FE62151AE967ECA5E0AA"
SET PASSWORD = PASSWORD('*FD571203974BA9AFE270FE62151AE967ECA5E0AA');
Okay It’s frustrating. After setting it up, You must use ciphertext to log in. Well, just use ciphertext to enter. After entering, use the following command to force the use of clear text for login
use mysql; delete from user; grant all on *.* to root@'%' identified by "111111" with grant option; flush privileges; quit;
Then, you can use the clear text password to log in
Each server equipped with SQL data nodes needs to execute the above command once;
6. After the above steps are completed, test whether the cluster is working normally
1) Simple function Test
After entering mysql on 218, execute the following:
create database clustertest; use clustertest; CREATE TABLE testtable(Count INT) ENGINE=NDBCLUSTER;
Note: ENGINE=NDBCLUSTER; The engine must use NDBCLUSTER to synchronize, otherwise the synchronization will not be performed.
Check whether it is successful, in 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) , will the lost data be automatically supplemented when restarting?)
Stop the mysql service on 217 and execute on 218
insert into testtable values (1);
启动217的mysql服务,使用show确认217的数据库节点已经连接上了,执行如下语句
select * from testtable;
如果发现有数据,则表示功能完备
7、关闭Cluster:(需要严格按照次序执行)
关闭数据节点:# mysqld stop (SQL节点可以用mysqladmin shutdown或别的方式关闭。)
在管理节点上执行:# ndb_mgm -e shutdown
将安全的关闭管理节点和数据节点。
关闭后使用如下的进程检测命令查看一下是否退出来了:
# pgrep mysqld # ps aux | grep nbdb
如果没有,找到对应的pid进行kill 操作即可
kill -9 进程号
8、再次启动Cluster方案:
启动整个cluster的次序,注意,一些语句已经减去了初始化的内容:
ndb_mgmd -f /var/lib/mysql-cluster/config.ini ndbd mysqld_safe --defaults-file=/usr/my.cnf --explicit_defaults_for_timestamp &
备注:
1、mysql安装后,默认会自动启动的,每次启动cluster的时候,都需要先把mysql的服务关闭,太麻烦,于是可以执行如下命令(我出手有点狠):
chkconfig --level 123456 mysql off
2、防火墙问题,偷个懒,我懒得去一一开放端口,干脆把防火墙直接关了(极不推荐的做法)
chkconfig --level 123456 iptables off
The above is the detailed content of Detailed explanation of MySQL-Cluster cluster construction (based on RPM installation package dual management center). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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.

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.

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

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

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.

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.

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.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA
