search
HomeDatabaseMysql TutorialMysql Cluster概述与部署_MySQL

bitsCN.com

Mysql Cluster概述与部署

 

   MySql Cluster最显著的优点就是高可用性,高实时性,高冗余,扩展性强。

 

   它允许在无共享的系统中部署"内存中"数据库的Cluster.通过无共享体系结构,系统能够使用廉价的硬件.此外,由于每个组件有自己的内存和磁盘,所以不存在单点故障.

 

   它由一组计算机构成,每台计算机上均运行者多种进程,包括mysql服务器,NDB cluster的数据节点,管理服务启,以及专门的数据访问程序

 

   所有的这些节点构成一个完整的mysql集群体系.数据保存在"NDB存储服务器"的存储引擎中,表(结构)则保存在"mysql服务器"中.应用程序通过"mysql服务器"访问这些数据表,集群管理服务器通过管理工具(ndb_mgmd)来管理"NDB存储服务器".

 

基本概念

 

   "NDB"是一种"内存中"的存储引擎,它具有可用性高和数据一致性好的特点.下面介绍mysql cluster 节点时,它表示进程.在单台计算机上可以有任意数目的节点.

 

    管理节点(MGM):这类节点的作用是管理mysql cluster内的其他节点,如配置文件和cluster 日志,启动并停止节点,运行备份等.cluster中的每个节点从管理服务器上检索配置数据,并请求管理服务器所在位置的方式.当数据节点内出现新的事件时,节点将关于这类事件的信息传输到管理服务器上,然后,又将这类信息写入cluster日志。由于这类节点负责管理其他节点的配置,所以应在启动其他节点之前首先启动这类节点.MGM节点是用命令"ndb_mgmd"来启动

 

    数据节点(NDB):这类节点用于保存cluster的数据.数据节点的数目与副本的数目相关,是片段的倍数.假设有2个副本,每个副本有2个片段,那么就有4个数据节点.不过没有必要设置多个副本.数据节点是用命令"ndbd"来启动的.

 

   SQL节点:这是用来访问cluster数据的节点.对于MYSQL cluster来说,客户端节点是使用NDB cluster存储引擎的传统Mysql服务器.通常,sql节点使用将"ndbcluster"添加到"my.cnf"后使用"mysqld" 启动

 

   此外,可以有任意数目的cluster客户端进程或应该程序.它们分为两种类型,即标准mysql客户端和管理客户端.

 

   标准mysql客户端:能够从php,perl,c,c++,java,python,ruby等编写的现有mysql应用程序上访问mysql cluster

 

   管理客户端:这类客户端与管理服务器相连,并提供了启动和停止节点,启动和停止消息跟踪,显示节点版本和状态,启动和停止备份等命令.

 

以下是mysql cluster 架构示意图:

 

Mysql Cluster概述与部署_MySQL

 

由于Mysql Cluster采用的是TCP/IP方式连接,并且节点之间的数据传输没有加密,最后使用单独的子网里.

 

下面来实施部署

 

为了方便 这里我把管理节点,数据节点,sql节点放在一台机器上.

 

管理节点1 10.1.6.205  

 

数据节点1 10.1.6.203   

 

数据节点2 10.1.6.205

 

sql节点1   10.1.6.203 

 

sql节点2   10.1.6.205 

 

1.安装(这里安装7.2.6版本)

 

下载mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz 二进制包(里面包含ndb,mysql)1root@10.1.6.205:~# tar -C /usr/local -xzvf mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz2root@10.1.6.205:/usr/local# ln -s /usr/local/mysql-cluster-gpl-7.2.8-linux2.6-i686 /usr/local/mysql3root@10.1.6.205:/usr/local# cd mysql4root@10.1.6.205:/usr/local/mysql# scripts/mysql_install_db --user=mysql5root@10.1.6.205:/usr/local/mysql# chown -R mysql:mysql /usr/local/mysql同理10.1.6.2032.配置SQL节点和存储NDB节点01root@10.1.6.205:/usr/local/mysql# vim /etc/my.cnf02[mysqld]03basedir=/usr/local/mysql/04datadir=/usr/local/mysql/data/05user=mysql06port=330607socket=/tmp/mysql.sock0809ndbcluster10max_connect_errors=1000011ndb-connectstring=10.1.6.20512connect_timeout = 3001314[mysql_cluster]15ndb-connectstring=10.1.6.205同理10.1.6.2033.配置管理节点01root@10.1.6.205:/usr/local/mysql# vim /opt/cluster/config.ini02[ndbd default]03NoOfReplicas=2   04DataMemory=80M    #分配data storage使用的内存   每个ndb占用05IndexMemory=18M   #分配index storage使用的内存  每个ndb占用0607[tcp default]08portnumber=2205  #ndb监听端口0910#设置管理节点11[ndb_mgmd]12NodeId=113hostname=10.1.6.20514datadir=/opt/cluster  #在MGM上保存日志的目录1516#设置存储节点NDB117[ndbd]18NodeId=219hostname=10.1.6.20320datadir=/usr/local/mysql/data2122#设置存储节点NDB223[ndbd]24NodeId=325hostname=10.1.6.20526datadir=/usr/local/mysql/data2728#设置SQL节点129[mysqld]30NodeId=431hostname=10.1.6.2033233#设置SQL节点234[mysqld]35NodeId=536hostname=10.1.6.20537[mysqld]    #运行任意ip连接38[mysqld]4.启动mysql cluster1)先启动管理节点服务器.2)启动NDB存储节点服务器.3)启动SQL节点服务器.1)执行启动MGM节点进程1root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndb_mgmd -f /opt/cluster/config.ini2MySQL Cluster Management Server mysql-5.5.22 ndb-7.2.6必须用参数-f或--config-file告诉ndb_mgm配置文件config.ini文件所在的位置.2)在2台存储节点服务器上,如果是第一次启动NDB进程的话,必须先执行以下命令:1root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndbd  --initial22013-08-28 23:40:36 [ndbd] INFO     -- Angel connected to '10.1.6.205:1186'32013-08-28 23:40:36 [ndbd] INFO     -- Angel allocated nodeid: 2

 

注意:仅在首次启动NDB时,或者在备份/恢复或配置文件发生变化且重启NDB时才使用-initial参数.因为该参数会使节点删除由早期NDB实例创建的,用于恢复的任何文件,包括用于恢复的日志文件.

如果不是第一次启动,用以下命令

 

1root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndbd3)启动SQL节点服务器1root@10.1.6.203:/usr/local/mysql/bin# /usr/local/mysql/bin/mysqld_safe /etc/my.cnf &5.查看各个节点情况01root@10.1.6.205:/usr/local/mysql# /usr/local/mysql/bin/ndb_mgm02-- NDB Cluster -- Management Client --03ndb_mgm> show04Cluster Configuration05---------------------06[ndbd(NDB)] 2 node(s)07id=2    @10.1.6.203  (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0, Master)08id=3    @10.1.6.205  (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0)0910[ndb_mgmd(MGM)] 1 node(s)11id=1    @10.1.6.205  (mysql-5.5.22 ndb-7.2.6)1213[mysqld(API)]   4 node(s)14id=4    @10.1.6.203  (mysql-5.5.22 ndb-7.2.6)15id=5    @10.1.6.205  (mysql-5.5.22 ndb-7.2.6)16id=6 (not connected, accepting connect from any host)17id=7 (not connected, accepting connect from any host)1819ndb_mgm>

 

 

6.测试

 

注意:与没有使用Cluster的Mysql相比,在mysql cluster内操作数据的方式没有太大的区别.操作时注意

 

1)表必须用engine=NDB或engine=NDBCLUSTER选项创建

 

2)每个NDB表必须有一个主键.如果在创建表时用户未定义主键,NDB Cluster存储引擎会自动生成隐含的主键.

 

该隐含键也将占用空间,就像任何其他的表索引一样.由于没有足够的内存来容纳这些自动创建的键,所以很容易出现问题.

 

在203 sql节点1上创建表

 

01root@10.1.6.203:/usr/local/mysql/bin# /usr/local/mysql/bin/mysql -uroot -p02mysql> use test;03mysql> create table dave (num int(10)) engine=ndb;04mysql> show create table dave/G;05*************************** 1. row ***************************06       Table: dave07Create Table: CREATE TABLE `dave` (08  `num` int(10) DEFAULT NULL09) ENGINE=ndbcluster DEFAULT CHARSET=latin1101 row in set (0.00 sec)1112mysql> insert into dave13    -> values14    -> (100);15Query OK, 1 row affected (0.01 sec)16mysql> select * from dave;17+------+18| num  |19+------+20|  100 |21+------+然后在205 sql节点2上查看该表1root@10.1.6.205:/usr/local/mysql# /usr/local/mysql/bin/mysql -uroot -p2mysql> use test3mysql> select * from dave;4+------+5| num  |6+------+7|  100 |8+------+测试OK关注一下表1mysql> select * from ndbinfo.memoryusage;2+---------+--------------+--------+------------+----------+-------------+3| node_id | memory_type  | used   | used_pages | total    | total_pages |4+---------+--------------+--------+------------+----------+-------------+5|       2 | Data memory  | 851968 |         26 | 83886080 |        2560 |6|       2 | Index memory | 212992 |         26 | 19136512 |        2336 |7|       3 | Data memory  | 851968 |         26 | 83886080 |        2560 |8|       3 | Index memory | 212992 |         26 | 19136512 |        2336 |注意:使用量写满会访问不了,这时需要调整配置DataMemory,IndexMemory参数.各配置文件都需调整重启生效.7.关闭cluster1root@10.1.6.205:/usr/local/mysql/bin#  /usr/local/mysql/bin/ndb_mgm -e shutdown2Connected to Management Server at: 10.1.6.205:118633 NDB Cluster node(s) have shutdown.4Disconnecting to allow management server to shutdown.再关闭SQL节点mysqld服务1root@10.1.6.203:/usr/local/mysql/bin# /usr/local/mysql/bin/mysqladmin -uroot -p shutdown2Enter password:3130829 02:19:57 mysqld_safe mysqld from pid file /usr/local/mysql/data//debian.pid ended4[1]+  Done                    /usr/local/mysql/bin/mysqld_safe /etc/my.cnf

 

 

以上就是mysql cluster初步部署, 之后会写haproxy+keepalive 双机高可用.

bitsCN.com
Statement
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
How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you handle large datasets in MySQL?How do you handle large datasets in MySQL?Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

How do you drop a table in MySQL using the DROP TABLE statement?How do you drop a table in MySQL using the DROP TABLE statement?Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you create indexes on JSON columns?How do you create indexes on JSON columns?Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

How do you represent relationships using foreign keys?How do you represent relationships using foreign keys?Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

See all articles

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

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.