1、准备三台服务器 2、为三台机器分别安装Linux操作系统(Oracle Linux / RHEL 6.5 x86_64bit) 3、分别IP地址 管理节点 192.168.1.110 (负责管理整个集群) SQL节点 192.168.1.111 (负责操作数据库) SQL节点 192.168.1.112 (负责操作数据库) 数据节点 192.168.
1、准备三台服务器
2、为三台机器分别安装Linux操作系统(Oracle Linux / RHEL 6.5 x86_64bit)
3、分别IP地址
管理节点 192.168.1.110 (负责管理整个集群)
SQL节点 192.168.1.111 (负责操作数据库)
SQL节点 192.168.1.112 (负责操作数据库)
数据节点 192.168.1.111 (负责存储数据)
数据节点 192.168.1.112 (负责存储数据)
SQL节点和数据节点可以同在一台机器上
4、修改三台服务器的/etc/hosts文件,修改完后的内容如下:
127.0.0.1 localhost localhost.domain
192.168.1.110 node01
192.168.1.111 node02
192.168.1.112 node03
5、修改三台服务器的/etc/sysconfig/nework文件,修改完后的内容分别如下:
NETWORKING=yes
HOSTNAME=node01
GATEWAY=192.168.1.1 (网关地址因所处网络的不同而不同)
NETWORKING=yes
HOSTNAME=node02
GATEWAY=192.168.1.1 (网关地址因所处网络的不同而不同)
NETWORKING=yes
HOSTNAME=node03
GATEWAY=192.168.1.1 (网关地址因所处网络的不同而不同)
6、分别重启三台服务器
7、下载NDB集群软件mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz
集群软件有三种格式:
a、以tar.gz结尾的二制进格式
b、以rpm结尾的rpm包形式
c、以源文件编译安装方式
rpm包安装方式,由于是自动安装的,所以不方便配置软件安装位置和数据存储位置
所以通常选用.tar.gz结尾的二进制格式的安装文件
注意:mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz包含了mysql数据库软件和NDB集群软件
8、分别复制mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz文件到三台服务器上的/usr/local/目录下
9、新建用户mysql
# groupadd mysql
# useradd -r -g mysql mysql (由于mysql用户只是用于安装配置NDB集群或mysql软件,而不用用于登陆系统)
(所以以-r参数来创建mysql用户,并且不用为该用户设置密码)
10、分别在三台服务器上解压mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz文件
# cd /usr/local
# tar zxvf mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz
# ln -s mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64 mysql
# chown -R mysql.mysql mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64
# cd mysql
# chown -R mysql.mysql .
配置完成以后,结果如下
11、在192.168.1.111和192.168.1.112两个数据节点(两台服务器)上安装mysql数据库软件
由于是二进制安装,所以mysql数据库软件就安装在/usr/local/mysql下,
但数据库的数据可以存放到其它地方,如/u01/app/mysql/data/下面
注意:以下命令在两台数据节点服务器上都要执行
# mkdir -p /u01/app/mysql/data
# chown -R mysql.mysql /u01
# cd /usr/local/mysql
# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/u01/app/mysql/data --user=mysql
执行完这条命令以后,数据库的数据文件(包括mysql,test , performance_schema等数据库)就被安装到了
/u01/app/mysql/data目录下了
# cp bin/ndbd /usr/local/bin/
# cp bin/ndbmtd /usr/local/bin/
然后将启动数据库服务的启动文件复制到/etc/rc.d/init.d/目录下
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld (改名)
执行完上面这条命令以后,就可以使用service mysqld start | stop | restart命令来管理数据库服务了
# cp my.cnf /etc/my.cnf
# vi /etc/my.cnf
[mysqld]
ndbcluster
basedir=/usr/local/mysql
datadir=/u01/app/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql_cluster]
ndb-connectstring=192.168.1.110
再次注意:以上命令在两台数据节点服务器上都要执行
到此,数据节点和SQL节点的安装配置就结束了,如果数据节点和SQL节点是分开在不同的机器上,则每个数据节点
和每个SQL节点都要执行以上命令。
12、在管理节点上进行安装配置
由于第10步已经解压缩mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz 安装包到了/usr/local
目录下,并进行了软连接等操作,所以这些工作就不用重复做了,接着往下配置即可
# cd /usr/local/mysql
# mkdir mysql-cluster (创建mysql-cluster目录,后面启动集群管理服务时要用)
# cp bin/ndb_mgm* /usr/local/bin/
# cd /var/lib
# mkdir mysql-cluster
# cd mysql-cluster
# vi config.ini (这是管理节点上的集群配置文件,很重要)
[ndbd default]
NoOfReplicas=1 # Number of replicas
DataMemory=80M # How much memory to allocate for data storage
IndexMemory=18M # How much memory to allocate for index storage
# For DataMemory and IndexMemory, we have used the
# default values. Since the "world" database takes up
# only about 500KB, this should be more than enough for
# this example Cluster setup.
[tcp default]
# This the default; however, you can use any
# port that is free for all the hosts in the cluster
# Note: It is recommended that you do not specify the port
# number at all and simply allow the default value to be used
# instead
[ndb_mgmd]
hostname=192.168.1.110 # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster # Directory for MGM node log files
NodeId=1
[ndbd]
hostname=192.168.1.111 # Hostname or IP address
datadir=/u01/app/mysql/data # Directory for this data node's data files
NodeId=2
[ndbd]
hostname=192.168.1.112 # Hostname or IP address
datadir=/u01/app/mysql/data # Directory for this data node's data files
NodeId=3
[mysqld]
hostname=192.168.1.111 # Hostname or IP address
NodeId=4 # (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)
[mysqld]
hostname=192.168.1.112 # Hostname or IP address
NodeId=5 # (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)
配置说明:
[ndbd default] 这部分是公共部分,对于每一个数据节点都有效,只需要配置一份
NoOfReplicas=1 数据镜像几份(各数据节点之间相互备份)
[tcp default] 针对每个数据节点及管理节点之间使用哪个端口进行通讯,
在旧版本的NDB集群软件配置时,这个地方通常配置portnumber=2202
但新版的NDB软件这里不需要配置,并且MySQL官方也强烈建议不要配置
[ndb_mgmd] 管理节点的配置部分(通常只有一个)
注意NodeId=1指明管理节点的节点ID为1,如果不指定,在启动集群时,会报错
hostname=192.168.1.110 指明管理节点的IP地址
datadir=/var/lib/mysql-cluster 指明集群管理日志存放的位置
[ndbd] 数据节点配置部分,有几个数据节点就配置几个[ndbd]
hostname=192.168.1.111 指明数据节点的IP地址
datadir=/u01/app/mysql/data 指明数据节点上的数据库文件存放的位置
NodeId=2 指明该数据节点在整个集群中的nodeid号(很重要)
[mysqld] SQL节点配置部分,有几个SQL节点,就配置几个[mysqld]
13、配置好上面的所有配置以后就可以在管理节点上启动怎个集群了
注意: 在管理节点上,不用执行/usr/local/mysql/scripts/mysql_install_db --basedir= --datadir= --user=命令
来安装数据库了。
# ndb_mgmd -f /var/lib/mysql-cluster/config.ini (第一次启动时这样执行,如果后面新添加了数据节点)
(执行此命令时,需要带上--initital参数,否则新添加的节点)
(无法被识别)
(# ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial)
# ndb_mgm (查看启动后的集群状态,看看集群是否成功启动,如果看到以下内容,表示集群已经成功配置并启动)
[root@mysql01 mysql-cluster]# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from 192.168.1.111)
id=3 (not connected, accepting connect from 192.168.1.112)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.110 (mysql-5.6.17 ndb-7.3.5)
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from 192.168.1.111)
id=5 (not connected, accepting connect from 192.168.1.112)
现在看到集群中包含两个数据节点、一个管理节点、两个SQL节点,但是数据节点和SQL节点都还没有启动,
所以显示的连接状态是not connected
14、分别登陆两台数据节点执行以下命令启动数据节点
# ndbd --initial (第一次启动时,需要加--initial来初始化数据节点,第二次启动时,就不需要这个参数了)
[root@mysql02 support-files]# ndbd --initial
2014-06-12 05:42:04 [ndbd] INFO -- Angel connected to '192.168.1.110:1186'
2014-06-12 05:42:04 [ndbd] INFO -- Angel allocated nodeid: 2
[root@mysql03 bin]# ndbd --initial
2014-06-12 05:41:38 [ndbd] INFO -- Angel connected to '192.168.1.110:1186'
2014-06-12 05:41:38 [ndbd] INFO -- Angel allocated nodeid: 3
15、再登陆到管理节点查看现在整个集群的状态
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.111 (mysql-5.6.17 ndb-7.3.5, Nodegroup: 0, *)
id=3 @192.168.1.112 (mysql-5.6.17 ndb-7.3.5, Nodegroup: 1)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.110 (mysql-5.6.17 ndb-7.3.5)
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from 192.168.1.111)
id=5 (not connected, accepting connect from 192.168.1.112)
现在可以看到,两个数据节点已经连接上来了,表示两个数据节点成功启动了
16、分别登陆到两个SQL节点上启动SQL节点
[root@mysql02 ~]# cd /usr/local/mysql/bin
[root@mysql02 bin]# ./mysqld_safe --user=mysql
140612 05:51:00 mysqld_safe Logging to '/u01/app/mysql/data/mysql02.err'.
140612 05:51:00 mysqld_safe Starting mysqld daemon with databases from /u01/app/mysql/data
[root@mysql03 ~]# cd /usr/local/mysql/bin
[root@mysql03 bin]# ./mysqld_safe --user=mysql
140612 05:52:07 mysqld_safe Logging to '/u01/app/mysql/data/mysql03.err'.
140612 05:52:07 mysqld_safe Starting mysqld daemon with databases from /u01/app/mysql/data
17、再次回到管理节点查看整个集群的状态
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.111 (mysql-5.6.17 ndb-7.3.5, Nodegroup: 0, *)
id=3 @192.168.1.112 (mysql-5.6.17 ndb-7.3.5, Nodegroup: 1)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.110 (mysql-5.6.17 ndb-7.3.5)
[mysqld(API)] 2 node(s)
id=4 @192.168.1.111 (mysql-5.6.17 ndb-7.3.5)
id=5 @192.168.1.112 (mysql-5.6.17 ndb-7.3.5)
到此整个集群就搭建完成,并成功启动运行了
18、安全关闭整个集群
首先登陆到两个SQL节点,执行service mysqld stop命令关闭SQL节点
[root@mysql02 ~]# service mysqld stop
Shutting down MySQL...... SUCCESS!
[root@mysql03 ~]# service mysqld stop
Shutting down MySQL..... SUCCESS!
然后登陆到管理节点上,执行shutdown命令关闭整个集群
[root@mysql01 mysql-cluster]# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from 192.168.1.111)
id=3 (not connected, accepting connect from 192.168.1.112)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.110 (mysql-5.6.17 ndb-7.3.5)
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from 192.168.1.111)
id=5 (not connected, accepting connect from 192.168.1.112)
ndb_mgm> shutdown
1 NDB Cluster node(s) have shutdown.
Disconnecting to allow management server to shutdown.
ndb_mgm> exit
7 测试。
1、从SQL节点A登录,创建数据库和表,进行简单测试。
mysql> create database zxztest ;
mysql> use zxztest;
Database changed
mysql> create table test1(id int,name varchar(10)) engine=ndb ;
mysql> insert into test1 values(1,'zhaoxuezhi');
mysql> select * from test1 ;
+------+---------+
| id | name |
+------+---------+
| 1 | zhaoxuezhi |
+------+---------+

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

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.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

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


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools