Mysql cluster安装说明 一、说明 本文档介绍了如何规划、安装、配置和运行MySQL集群的基本知识。 二、Mysql集群结构图 三、名词解释 ? 管理节点: 这类节点的作用是管理MySQL簇内的其他节点,如提供配置数据、启动并停止节点、运行备份等。由于这类节点负责
Mysql cluster安装说明
一、 说明
本文档介绍了如何规划、安装、配置和运行MySQL集群的基本知识。
二、 Mysql集群结构图
三、 名词解释
? 管理节点:这类节点的作用是管理MySQL簇内的其他节点,如提供配置数据、启动并停止节点、运行备份等。由于这类节点负责管理其他节点的配置,应在启动其他节点之前首先启动这类节点。
? 数据节点:这类节点用于保存簇的数据。数据节点的数目与副本的数目相关,是片段的倍数。例如,对于两个副本,每个副本有两个片段,那么就有4个数据节点。没有必要有一个以上的副本。数据节点是用命令ndbd启动的。
? SQL节点:这是用来访问簇数据的节点。对于MySQL簇,客户端节点是使用NDB簇存储引擎的传统MySQL服务器。
四、 安装环境
1. 操作系统
Linux version2.6.18-164.el5
2. 安装结构图
3. 部署列表
名称 |
Ip |
(MGM)管理节点 (NDBD)数据节点1 |
192.168.10.10 192.168.10.20 |
(NDBD)数据节点2 |
192.168.10.40 |
SQL节点1 |
192.168.10.30 |
SQL节点2 |
192.168.10.50 |
五、 安装软件
MySQL-Cluster-gpl-management-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-storage-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-tools-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-client-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-server-7.1.29-1.rhel5.x86_64.rpm
下载地址:http://www.mysql.com/downloads/cluster/7.1.html
六、 安装步骤
1. 管理节点安装
上传
MySQL-Cluster-gpl-management-7.1.29-1.rhel5.x86_64.rpm,MySQL-Cluster-gpl-tools-7.1.29-1.rhel5.x86_64.rpm到服务器192.168.10.10上
安装:
[root@192.168.10.10 ]# rpm -ivh MySQL-Cluster-gpl-management-7.1.29-1.rhel5.x86_64.rp [root@192.168.10.10 ]# rpm -ivh MySQL-Cluster-gpl-tools-7.1.29-1.rhel5.x86_64.rpm [root@192.168.10.10 ]# mkdir /var/lib/mysql-cluster [root@192.168.10.10 ]# vi /var/lib/mysql-cluster/config.ini
修改配置文件config.ini
[ndbd default] NoOfReplicas=2 DataMemory=80M IndexMemory=18M [tcp default] SendBufferMemory=2M ReceiveBufferMemory=2M [NDB_MGMD DEFAULT] PortNumber=1186 datadir=/var/lib/mysql-cluster [ndb_mgmd] NodeId=1 hostname=192.168.10.10 [ndbd] NodeId=2 hostname=192.168.10.20 datadir=/var/lib/mysql-data [ndbd] NodeId=4 hostname=192.168.10.40 datadir=/var/lib/mysql-data [mysqld] NodeId=3 hostname=192.168.10.30 [mysqld] NodeId=5 hostname=192.168.10.50
注意:NoOfReplicas的数字要和数据节点的数量一样!
2. 数据节点安装
上传MySQL-Cluster-gpl-storage-7.1.29-1.rhel5.x86_64.rpm分别到服务器192.168.10.20和192.168.10.40上
执行
[root@192.168.10.20]# rpm -ivh MySQL-Cluster-gpl-storage-7.1.29-1.rhel5.x86_64.rpm 输出如下成功 Preparing... ########################################### [100%] 1:MySQL-Cluster-gpl-stora########################################### [100%] [root@192.168.10.20]# mkdir /var/lib/mysql-data [root@192.168.10.20]# chmod 777 /var/lib/mysql-data –R [root@192.168.10.20]#vi /etc/my.cnf
修改my.cnf
192.168.10.40的安装同上
3. SQL节点安装
上传MySQL-Cluster-gpl-client-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-server-7.1.29-1.rhel5.x86_64.rpm分别到服务器192.168.10.30和192.168.10.50上
执行
[root@192.168.10.30]#rpm -ivh MySQL-Cluster-gpl-server-7.1.29-1.rhel5.x86_64.rpm 输出如下成功 Preparing... ########################################### [100%] 1:MySQL-Cluster-gpl-serve########################################### [100%] PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems with the /usr/bin/mysqlbug script! [root@192.168.10.30]# rpm -ivh MySQL-Cluster-gpl-client-7.1.29-1.rhel5.x86_64.rpm --nodeps –force 输出如下成功 Preparing... ########################################### [100%] 1:MySQL-Cluster-gpl-clien########################################### [100%] [root@192.168.10.30]# vi /etc/my.cnf
修改my.cnf
[mysqld] ndbcluster ndb-connectstring=192.168.10.10:1186 [mysql_cluster] ndb-connectstring=192.168.10.10:1186
192.168.10.50的安装同上
七、 Mysql集群启动
启动顺序为管理节点、数据节点、sql节点
1. 管理节点启动
//管理节点启动 //第一次启动 [root@192.168.10.10]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini //以后启动 [root@192.168.10.10]# ndb_mgmd //config.ini 修改启动 [root@192.168.10.10]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini //启动成功为: MySQL Cluster Management Server mysql-5.1.72 ndb-7.1.29 //查看状态 [root@192.168.10.10]# ndb_mgm ndb_mgm>show 如下信息,各个节点的状态 [ndbd(NDB)] 2 node(s) id=2 @192.168.10.20 (mysql-5.1.72 ndb-7.1.29, Nodegroup: 0, *) id=4 @192.168.10.40 (mysql-5.1.72 ndb-7.1.29, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.10.10 (mysql-5.1.72 ndb-7.1.29) [mysqld(API)] 2 node(s) id=3 (not connected, accepting connect from 192.168.10.30) id=5 (not connected, accepting connect from 192.168.10.50)
2. 数据节点启动
//数据节点启动 第一个数据节点启动时用 –initial其它不需要 [root@192.168.10.20]# ndbd –initial //输出如下成功 2013-12-25 23:36:23 [ndbd] INFO -- Angel connected to '192.168.10.10:1186' 2013-12-25 23:36:23 [ndbd] INFO -- Angel allocated nodeid: 2
192.168.10.40 操作同上
3. Sql节点启动
//sql节点启动 [root@192.168.10.20]# mysqld_safe //输出如下成功 131226 01:02:43 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'. 131226 01:02:43 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
192.168.10.50 操作同上
如果启动出现如下提示
//sql节点启动 131226 01:01:50 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'. 131226 01:01:51 mysqld_safe A mysqld process already exists
手动杀掉mysql的进程重新启动
八、 验证
在其中一个sql节点上建一个库,并建立一个测试表插入数据,再从另外一个sql节点登陆看是否同步,如果同步成功,否则失败。
九、 关闭集群
1.关闭管理节点和数据节点,只需要在管理节点里执行:
[root@192.168.10.10]# ndb_mgm -e shutdown Node 2: Cluster shutdown initiated Node 4: Cluster shutdown initiated Node 4: Node shutdown completed. Node 2: Node shutdown completed. 3 NDB Cluster node(s) have shutdown. Disconnecting to allow management server to shutdown.
2.然后关闭Sql节点,分别在2个节点里运行:
[root@192.168.10.30]# service mysql stop
十、 重要说明
1.在建表的时候一定要用ENGINE=NDB或ENGINE=NDBCLUSTER指定使用NDB集群存储引擎,或用ALTERTABLE选项更改表的存储引擎。
2.NDB表必须有一个主键,因此创建表的时候必须定义主键,否则NDB存储引擎将自动生成隐含的主键。
3.Sql节点的用户权限表仍然采用MYISAM存储引擎保存的,所以在一个Sql节点创建的MySql用户只能访问这个节点,如果要用同样的用户访问别的Sql节点,需要在对应的Sql节点追加用户。
十一、 其它
先看看都安装了什么包:
如果安装过程中出现错误,删除重新装
rpm -qa|grep MySQL
然后把这些包都卸载掉
rpm -e MySQL-server*
rpm -e MySQL-client*

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

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.