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采用的是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)
root@10.1.6.205:~# tar -C /usr/local -xzvf mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz root@10.1.6.205:/usr/local# ln -s /usr/local/mysql-cluster-gpl-7.2.8-linux2.6-i686 /usr/local/mysql root@10.1.6.205:/usr/local# cd mysql root@10.1.6.205:/usr/local/mysql# scripts/mysql_install_db --user=mysql root@10.1.6.205:/usr/local/mysql# chown -R mysql:mysql /usr/local/mysql 同理10.1.6.203
2.配置SQL节点和存储NDB节点
root@10.1.6.205:/usr/local/mysql# vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql/ datadir=/usr/local/mysql/data/ user=mysql port=3306 socket=/tmp/mysql.sock ndbcluster max_connect_errors=10000 ndb-connectstring=10.1.6.205 connect_timeout = 300 [mysql_cluster] ndb-connectstring=10.1.6.205
同理10.1.6.203
3.配置管理节点
root@10.1.6.205:/usr/local/mysql# vim /opt/cluster/config.ini [ndbd default] NoOfReplicas=2 DataMemory=80M #分配data storage使用的内存 每个ndb占用 IndexMemory=18M #分配index storage使用的内存 每个ndb占用 [tcp default] portnumber=2205 #ndb监听端口 #设置管理节点 [ndb_mgmd] NodeId=1 hostname=10.1.6.205 datadir=/opt/cluster #在MGM上保存日志的目录 #设置存储节点NDB1 [ndbd] NodeId=2 hostname=10.1.6.203 datadir=/usr/local/mysql/data #设置存储节点NDB2 [ndbd] NodeId=3 hostname=10.1.6.205 datadir=/usr/local/mysql/data #设置SQL节点1 [mysqld] NodeId=4 hostname=10.1.6.203 #设置SQL节点2 [mysqld] NodeId=5 hostname=10.1.6.205 [mysqld] #运行任意ip连接 [mysqld]
4.启动mysql cluster
1)先启动管理节点服务器.2)启动NDB存储节点服务器.3)启动SQL节点服务器.
1)执行启动MGM节点进程
root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndb_mgmd -f /opt/cluster/config.ini MySQL Cluster Management Server mysql-5.5.22 ndb-7.2.6
必须用参数-f或--config-file告诉ndb_mgm配置文件config.ini文件所在的位置.
2)在2台存储节点服务器上,如果是第一次启动NDB进程的话,必须先执行以下命令:
root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndbd --initial 2013-08-28 23:40:36 [ndbd] INFO -- Angel connected to '10.1.6.205:1186' 2013-08-28 23:40:36 [ndbd] INFO -- Angel allocated nodeid: 2
注意:仅在首次启动NDB时,或者在备份/恢复或配置文件发生变化且重启NDB时才使用-initial参数.因为该参数会使节点删除由早期NDB实例创建的,用于恢复的任何文件,包括用于恢复的日志文件.
如果不是第一次启动,用以下命令
root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndbd
3)启动SQL节点服务器
root@10.1.6.203:/usr/local/mysql/bin# /usr/local/mysql/bin/mysqld_safe /etc/my.cnf &
5.查看各个节点情况
root@10.1.6.205:/usr/local/mysql# /usr/local/mysql/bin/ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> show Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 @10.1.6.203 (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0, Master) id=3 @10.1.6.205 (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @10.1.6.205 (mysql-5.5.22 ndb-7.2.6) [mysqld(API)] 4 node(s) id=4 @10.1.6.203 (mysql-5.5.22 ndb-7.2.6) id=5 @10.1.6.205 (mysql-5.5.22 ndb-7.2.6) id=6 (not connected, accepting connect from any host) id=7 (not connected, accepting connect from any host) ndb_mgm>
6.测试
注意:与没有使用Cluster的Mysql相比,在mysql cluster内操作数据的方式没有太大的区别.操作时注意
1)表必须用engine=NDB或engine=NDBCLUSTER选项创建
2)每个NDB表必须有一个主键.如果在创建表时用户未定义主键,NDB Cluster存储引擎会自动生成隐含的主键.
该隐含键也将占用空间,就像任何其他的表索引一样.由于没有足够的内存来容纳这些自动创建的键,所以很容易出现问题.
在203 sql节点1上创建表
root@10.1.6.203:/usr/local/mysql/bin# /usr/local/mysql/bin/mysql -uroot -p mysql> use test; mysql> create table dave (num int(10)) engine=ndb; mysql> show create table dave\G; *************************** 1. row *************************** Table: dave Create Table: CREATE TABLE `dave` ( `num` int(10) DEFAULT NULL ) ENGINE=ndbcluster DEFAULT CHARSET=latin1 1 row in set (0.00 sec) mysql> insert into dave -> values -> (100); Query OK, 1 row affected (0.01 sec) mysql> select * from dave; +------+ | num | +------+ | 100 | +------+
然后在205 sql节点2上查看该表
root@10.1.6.205:/usr/local/mysql# /usr/local/mysql/bin/mysql -uroot -p mysql> use test mysql> select * from dave; +------+ | num | +------+ | 100 | +------+
测试OK
关注一下表
mysql> select * from ndbinfo.memoryusage; +---------+--------------+--------+------------+----------+-------------+ | node_id | memory_type | used | used_pages | total | total_pages | +---------+--------------+--------+------------+----------+-------------+ | 2 | Data memory | 851968 | 26 | 83886080 | 2560 | | 2 | Index memory | 212992 | 26 | 19136512 | 2336 | | 3 | Data memory | 851968 | 26 | 83886080 | 2560 | | 3 | Index memory | 212992 | 26 | 19136512 | 2336 |
注意:使用量写满会访问不了,这时需要调整配置DataMemory,IndexMemory参数.各配置文件都需调整重启生效.
7.关闭cluster
root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndb_mgm -e shutdown Connected to Management Server at: 10.1.6.205:1186 3 NDB Cluster node(s) have shutdown. Disconnecting to allow management server to shutdown.
再关闭SQL节点mysqld服务
root@10.1.6.203:/usr/local/mysql/bin# /usr/local/mysql/bin/mysqladmin -uroot -p shutdown Enter password: 130829 02:19:57 mysqld_safe mysqld from pid file /usr/local/mysql/data//debian.pid ended [1]+ Done /usr/local/mysql/bin/mysqld_safe /etc/my.cnf
以上就是mysql cluster初步部署, 更多相关内容请关注PHP中文网(www.php.cn)!

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

TostorestringsefficientlyinMySQL,choosetherightdatatypebasedonyourneeds:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseTEXTforlong-formtextcontent.4)UseBLOBforbinarydatalikeimages.Considerstorageov

When selecting MySQL's BLOB and TEXT data types, BLOB is suitable for storing binary data, and TEXT is suitable for storing text data. 1) BLOB is suitable for binary data such as pictures and audio, 2) TEXT is suitable for text data such as articles and comments. When choosing, data properties and performance optimization must be considered.

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQLstringdatatypesshouldbechosenbasedondatacharacteristicsandusecases:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseBINARYorVARBINARYforbinarydatalikecryptographickeys.4)UseBLOBorTEXTforlargeuns


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

SublimeText3 Chinese version
Chinese version, very easy to use

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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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