要配置一个Cluster集群,至少得需要配置1个MGM(管理结点)+1个SQL结点+2 Data 结点MGM可以和SQL结点共用一台机器,数据结点单独占
要配置一个Cluster集群,至少得需要配置
1个MGM(管理结点)+1个SQL结点+2 Data 结点
MGM可以和SQL结点共用一台机器,数据结点单独占一台服务器。
这样最少也需要3台服务器。
有时候这样会觉得很麻烦,如果是学习阶段,可考虑在单台服务器搭建一个MySQL Cluster。
下文就是教你如何在一台服务器上搭建Cluster。
一,先确认Cluster的包已经正确安装
[root@cluster-one ~]# rpm -aq|grep -i mysql
MySQL-Cluster-client-gpl-7.2.10-1.el6.x86_64
MySQL-Cluster-server-gpl-7.2.10-1.el6.x86_64
MySQL-Cluster-shared-compat-gpl-7.2.10-1.el6.x86_64
MySQL-Cluster-devel-gpl-7.2.10-1.el6.x86_64
二,创建如下几个配置文件,下面启动时要用到
[root@cluster-one mysqlData]# more config.ini
[NDBD DEFAULT]
NoOfReplicas=2
[TCP DEFAULT]
#portnumber=3388
[NDB_MGMD]
NodeId = 1
hostname=localhost
datadir=/mysqlData/clustermgmd-data/
[NDBD]
NodeId = 2
hostname=localhost
datadir=/mysqlData/clusterndb1-data/
[NDBD]
NodeId = 3
hostname=localhost
datadir=/mysqlData/clusterndb2-data/
[MYSQLD]
NodeId = 4
hostname=localhost
[MYSQLD]
NodeId = 5
hostname=localhost
[MYSQLD]
[root@cluster-one mysqlData]# more my1.cnf
[mysqld]
ndbcluster
socket=/data/socket/n1.sock
pid-file=/data/socket/n1.pid
log-error = /data/log/n1_err.log
port = 3501
[mysql_cluster]
ndb-connectstring=localhost
[root@cluster-one mysqlData]# more my2.cnf
[mysqld]
ndbcluster
socket=/data/socket/n2.sock
pid-file=/data/socket/n2.pid
log-error = /data/log/n2_err.log
port = 3502
[mysql_cluster]
ndb-connectstring=localhost
[root@cluster-one mysqlData]# more /etc/my.cnf
[mysqld]
ndbcluster
socket=/var/lib/mysql/mysql.sock
pid-file=/data/socket/mysqld.pid
datadir=/mysqlData/clusterapi
log-bin=mysql-bin
log-bin-index=mysql-bin.index
binlog-format=ROW
server-id=1
port = 3401
[mysql_cluster]
ndb-connectstring=localhost
[client]
socket=/var/lib/mysql/mysql.sock
三,分别启动所有结点 (需要注意的是,如果是第一次启动,请在 管理结点/数据结点 的启动参数后面加上 --initial)
启动结点之前,请确保,上面配置文件指定的目录都存在。
不存在,,请自行先创建一个,或是你修改配置文件指定其它目录。目录有:
/mysqlData/clustermgmd-data/
/mysqlData/clusterndb1-data/
/mysqlData/clusterndb2-data/
/mysqlData/clusterapi
/data/socket/mysqld.pid
/data/socket/
/data/log/
管理结点
[root@cluster-one ~]# ndb_mgmd -f /mysqlData/config.ini
MySQL Cluster Management Server mysql-5.5.29 ndb-7.2.10
数据结点1
[root@cluster-one ~]# ndbd --defaults-file=/mysqlData/my1.cnf
2013-12-20 02:35:42 [ndbd] INFO -- Angel connected to 'localhost:1186'
2013-12-20 02:35:42 [ndbd] INFO -- Angel allocated nodeid: 2
数据结点2
[root@cluster-one ~]# ndbd --defaults-file=/mysqlData/my2.cnf
2013-12-20 02:35:46 [ndbd] INFO -- Angel connected to 'localhost:1186'
2013-12-20 02:35:46 [ndbd] INFO -- Angel allocated nodeid: 3
查询结点,如果没有/etc/init.d/mysql这个文件,可以 把 “
/usr/share/mysql/mysql.server” 拷贝到/etc/init.d目录下,并改名为mysql
[root@cluster-one ~]# /etc/init.d/mysql start
Starting MySQL
相关阅读:
搭建基于Corosync+DRBD的高可用MySQL集群
Corosync+Pacemaker+DRBD+MySQL 实现高可用(HA)的MySQL集群
Heartbeat+MySQL+NFS 实现高可用(HA)的MySQL集群
MySQL集群架构全自动化实现切换(M-M-S-S)
SUSE Linux 下 MySQL集群配置

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 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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.

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

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