MySQL集群 MySQL Cluster
一、简要说明
MySQL Cluster 是MySQL适合于分布式计算环境的高实用、高冗余版本。它采用了NDB Cluster 存储引擎,“NDB” 是一种“内存中”的存储引擎,它具有可用性高和数据一致性好的特点
该技术允许在无共享的系统中部署“内存中”数据库的簇。通过无共享体系结构,系统能够使用廉价的硬件,而且对软硬件无特殊要求。此外,由于每个组件有自己的内存和磁盘,不存在单点故障。
MySQL Cluster 是用于解决高可用和高可靠性的解决方案。
MySQL Cluster 具有故障恢复、节点修复、数据同步、非单点故障等优点。
MySQL Cluster 是为提供99.999%以上的高可用性而设计的,采用分布式节点设计技术,不会因为单点故障而使整个 Cluster 瘫痪。
MySQL Cluster由 3 类节点组成:管理节点、数据节点、SQL节点。
1:数据节点
数据节点是整个系统中最主要的节点,它负责存储所有的数据以及数据的同步复制,以防单个或者更多的节点故障而使 MySQL Cluster 瘫痪。
2:管理节点
管理节点用于管理系统的配置信息,只在启动和重新配置 MySQL Cluster 的时候才起作用。一般情况下只需要 1 个管理节点,当然也可以运行几个管理节点。
3:SQL 节点
SQL 节点用于数据节点存取数据,提供统一的标准 SQL接口,跟平常的 MySQL Serve 一样,让应用程序和开发人员不用关心系统内部究竟是如何运行的。
二、下载与安装
1、官方下载:
download the latest MySQL Cluster NDB 7.2 binary archive
http://dev.mysql.com/downloads/mirrors.html 或
http://dev.mysql.com/downloads/cluster/#downloads
官方配置建议
http://www.mysqlab.net/tool/mysql-cluster/config.generator
在线文档
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster.html
2、安装数据节点和管理节点。
安装步骤:
a、Data nodes and SQL nodes. ( 192.168.1.217、192.168.1.218 )
On each of the machines designated to host data nodes or SQL nodes
每个数据节点都安装好。我这里两个节点,都按此顺序安装。
ls /root/work/software/mysql-cluster/mysql-cluster-gpl-7.2.5-linux2.6-x86_64.tar.gz
cd /root/work/software/mysql-cluster/
tar zvxf mysql-cluster-gpl-7.2.5-linux2.6-x86_64.tar.gz
groupadd mysql
useradd -r -g mysql mysql /* -r 是创建一个没有登录权限的系统账号 */
mv mysql-cluster-gpl-7.2.5-linux2.6-x86_64 /usr/local/mysql
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
cp support-files/my-medium.cnf /etc/my.cnf
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysqld /* 可以使用此方法启动关闭 service mysqld start/stop */
chkconfig --add mysql.server /* 加入开机自启动 */
b、Management nodes.
安装 Management 不需要安装mysqld ,只需要集群管理服务 ndb_mgmd 。 192.168.1.215
Installation of the management node does not require the mysqld binary. Only the MySQL Cluster management server (ndb_mgmd) is required;
ls /root/work/software/mysql-cluster/mysql-cluster-gpl-7.2.5-linux2.6-x86_64.tar.gz
cd /root/work/software/mysql-cluster/
tar zvxf mysql-cluster-gpl-7.2.5-linux2.6-x86_64.tar.gz
mv mysql-cluster-gpl-7.2.5-linux2.6-x86_64 /usr/local/mysql
cd /usr/local/mysql
cp bin/ndb_mgm* /usr/local/bin
cd /usr/local/bin
3、初始化配置:Initial Configuration of MySQL Cluster
a、 配置:数据节点( 192.168.1.217、192.168.1.218)
Each data node or SQL node requires a my.cnf file
provides two pieces of information:
a connectstring that tells the node where to find the management node.
a line telling the MySQL server on this host to enable the NDBCLUSTER storage engine.
Configuring the data nodes and SQL nodes
(For each data node and SQL node in our example setup, my.cnf should look like this:)
##################################
[mysqld]
# Options for mysqld process:
ndbcluster # run NDB storage engine
ndb-connectstring=192.168.0.10 # location of management server
[mysql_cluster]
# Options for ndbd process:
ndb-connectstring=192.168.0.10 # location of management server
##################################
b、 配置:管理节点. ( 192.168.1.215 )
Configuring the management node.
The management node needs a config.ini file
provides five pieces of information:
telling it how many replicas to maintain.
how much memory to allocate for data and indexes on each data node.
where to find the data nodes.
where to save data to disk on each data node.
where to find any SQL nodes.
shell> mkdir /var/lib/mysql-cluster
shell> cd /var/lib/mysql-cluster
shell> vi config.ini
##################################
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2 # Number of replicas #每个数据节点的镜像数量
DataMemory=2G # 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.
[ndb_mgmd]
# Management process options:
NodeId=10
hostname=192.168.1.215 # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster # Directory for MGM node log files
[ndbd]
# Options for data node "A":
NodeId=1
# (one [ndbd] section per data node)
hostname=192.168.1.217 # Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node's data files
[ndbd]
# Options for data node "B":
NodeId=2
hostname=192.168.1.218 # Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node's data files
[mysqld]
hostname=192.168.1.217
NodeId=20
# Hostname or IP address
# (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)
[mysqld]
NodeId=21
hostname=192.168.1.218
##################################
4、 安全启动服务和重新启动服务:
Safe Shutdown and Restart of MySQL Cluster
节点启动的顺序为: 管理节点-----> 数据节点----->SQL节点
关闭顺序为: 直接关闭管理节点,数据节点自动关闭。SQL节点
重启: 管理节点-----> 数据节点; SQL 节点可不重启。
a、 On the management host
Initial Startup of MySQL Cluster
The first time that it is started, ndb_mgmd must be told where to find its configuration file, using the -f
ndb_mgmd -f /var/lib/mysql-cluster/config.ini
b、 On each of the data node hosts, run this command to start the ndbd process:
(第一次启动使用 ~/mysql/bin/ndbd --initial)
[root@test217 bin]# ./ndbd --initial
2012-07-25 17:17:51 [ndbd] INFO -- Angel connected to '192.168.1.215:1186'
2012-07-25 17:17:51 [ndbd] INFO -- Angel allocated nodeid: 2
[root@test218 bin]# ./ndbd --initial
2012-07-25 17:18:10 [ndbd] INFO -- Angel connected to '192.168.1.215:1186'
2012-07-25 17:18:10 [ndbd] INFO -- Angel allocated nodeid: 3
c、 启动SQL节点 192.168.1.217、192.168.1.218
service mysqld start
d、 查看
ndb_mgm
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.217 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 0, Master)
id=3 @192.168.1.218 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.215 (mysql-5.5.20 ndb-7.2.5)
[mysqld(API)] 3 node(s)
id=4 @192.168.1.217 (mysql-5.5.20 ndb-7.2.5)
id=5 @192.168.1.218 (mysql-5.5.20 ndb-7.2.5)
ndb_mgm> all report mem
Node 2: Data usage is 78%(51186 32K pages of total 65536)
Node 2: Index usage is 27%(17904 8K pages of total 64032)
Node 3: Data usage is 78%(51186 32K pages of total 65536)
Node 3: Index usage is 27%(17904 8K pages of total 64032)
e、 关闭集群服务
先在管理服务器上执行 ndb_mgm -e shutdown,后关闭sql节点,service mysqld stop
[root@test215 mysql-cluster]# ndb_mgm -e shutdown
(The command causes the ndb_mgm, ndb_mgmd, and any ndbd or ndbmtd processes to terminate gracefully. )
rm /var/lib/mysql/mysql-cluster/ndb_1_config.bin.1 #不是必须的,如果config.ini有改动则要加上
Any SQL nodes can be terminated using mysqladmin shutdown
三、测试 (很重要,只有通过了测试才能放心的应用到实际的生产环境中。)
常规性操作测试:建库、建表、删库、删表; 记录增、删、改; 一节点上操作,另一节点校验;交叉执行校验。
数据恢复测试: 库导入导出、表导入导出,一节点执行,另一个节点校验,交叉执行校验。
故障测试:实时添加、卸载节点测试。( 当cluster启动之后mgm宕机对cluter没有影响。)
压力测试:目前生产环境的两个数据库的 queries :178次/秒 Queries:264次/秒 预计集群合并后达到442次/秒
计划写个shell脚本来压力测试,
专业性压力工具 独测试Mysql,使用sysbench, super smarck 这工具,推荐sysbench
性能测试:验证单条语句执行时间
1、 常规性操作测试:
MySQL Cluster Example with Tables and Data
For a table to be replicated in the cluster, it must use the NDBCLUSTER storage engine.
To specify this, use the ENGINE=NDBCLUSTER or ENGINE=NDB option when creating the table:
a 、
在 192.168.1.217 上执行
CREATE TABLE `t1` (`id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`)) ENGINE=ndbcluster ;
在 192.168.1.218 查看
show tables;
+----------------+
| Tables_in_test |
+----------------+
| t1 |
+----------------+
1 row in set (0.04 sec)
b 、insert into t1 values('');
2、数据导入导出测试,数据恢复测试
(1)、第一种情况:将普通的mysql数据库迁移到ysql cluster数据库上。
有普通mysql的普通备份。
如何将普通dump出来的数据,导入到cluster的数据中。
两种办法:
一种是修改备份的dump.sql 文件。
将ENGINE=inodb 或 ENGINE=mysam 改为 ENGINE=NDBCLUSTER
另一种是 将普通的sql文件直接导入到cluster数据库中,然后批量修改所有的表的默认engine
例如:ALTER TABLE cairh_user_account ENGINE=NDBCLUSTER;
测试环境将 600多M的数据库恢复到cluster中,花费23分钟。
#### 表的导出导入测试。
217服务器上导出一张 160万条记录的表 耗时12秒。
[root@test217 back]# date ; /usr/local/mysql/bin/mysqldump -uroot -padmin vse_bigsun cairh_week_revenue_log > vse_bigsun_cairh_week_revenue_log.sql ; date
2012年 08月 12日 星期日 10:04:37 CST
2012年 08月 12日 星期日 10:04:49 CST
218服务器上drop一个160万条记录的表耗时 0.89秒
mysql> drop table cairh_week_revenue_log;
Query OK, 0 rows affected (0.89 sec)
217服务器上 ,使用刚刚备份的表恢复 耗时1分23秒。
[root@test217 back]# date ; mysql -uroot -padmin vse_bigsun < vse_bigsun_cairh_week_revenue_log.sql ; date
2012年 08月 12日 星期日 10:13:37 CST
2012年 08月 12日 星期日 10:15:00 CST
验证导入的表的可用性,插入条记录
218服务器上 插入。
mysql> insert into cairh_week_revenue_log values('',1001,1130823,1,79367,1,20120812,935481.98665,968005.00754,0.03477,54);
Query OK, 1 row affected, 1 warning (0.06 sec)
217上查看。
mysql> select * from cairh_week_revenue_log where issue_date=20120812 limit 1;
+---------+----------------+---------+--------------+------------+------------+------------+-------------------+---------------------+--------------+-----------+
| id | vstock_zone_id | user_id | account_type | account_id | section_id | issue_date | start_total_asset | current_total_asset | revenue_rate | week_rank |
+---------+----------------+---------+--------------+------------+------------+------------+-------------------+---------------------+--------------+-----------+
| 2146376 | 1001 | 1130823 | 1 | 79367 | 1 | 20120812 | 935481.98665 | 968005.00754 | 0.03477 | 54 |
+---------+----------------+---------+--------------+------------+------------+------------+-------------------+---------------------+--------------+-----------+
1 row in set (0.18 sec)
#### 库的导出导出操作测试。
217服务器上导出一个600多M的数据库 耗时1分10秒。
[root@test217 back]# date ; /usr/local/mysql/bin/mysqldump -uroot -padmin vse_bigsun > vse_bigsun.sql ; date 2012年 08月 12日 星期日 10:07:02 CST
2012年 08月 12日 星期日 10:07:02 CST
2012年 08月 12日 星期日 10:08:12 CST
217服务器上 删除一个600多M的库 耗时 6.67秒。删除后创建。
mysql> drop database vse_bigsun;
Query OK, 48 rows affected (6.67 sec)
mysql> create database vse_bigsun;
Query OK, 1 row affected (0.10 sec)
将刚刚217服务器上备份的数据库压缩传输到218服务器上导入操作。
tar czvf vse_bigsun.sql.tar.gz vse_bigsun.sql && scp vse_bigsun.sql.tar.gz 192.168.1.218:/back
218服务器上恢复耗时 9分28秒。(后又217上恢复耗时12分)
[root@test218 back]# date ; mysql -uroot -padmin vse_bigsun < vse_bigsun.sql;date
Sun Aug 12 10:29:39 CST 2012
Sun Aug 12 10:39:07 CST 2012
单机上恢复一个数据库 耗时9分54秒。
[root@test219 back]# date ; mysql -uroot -pCrhTest214! vse_bigsun < vse_bigsun_201208120100.sql ; date
Sun Aug 12 11:06:09 CST 2012
Sun Aug 12 11:16:03 CST 2012
3、 故障测试: (http://qiufengy.blog.51cto.com/blog/391990/792523)
添加节点与删除节点
添加:
215服务器上编辑 config.ini,添加[ndbd]
NoOfReplicas=1 /这里非常重要 /
[ndbd]
hostname=192.168.1.219
datadir=/usr/local/mysql-cluster/data
第二步、停止管理节点
ndb_mgm> 1 STOP
Node 1 has shutdown. //节点1就是管理节点
Disconnecting to allow Management Server to shutdown
第三步、启动管理节点
[root@test215 mysql-cluster]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 4 node(s)
id=1 @192.168.1.217 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 0)
id=2 @192.168.1.218 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 0, Master)
id=3 (not connected, accepting connect from 192.168.1.219)
id=4 (not connected, accepting connect from 192.168.1.214)
[ndb_mgmd(MGM)] 1 node(s)
id=10 @192.168.1.215 (mysql-5.5.20 ndb-7.2.5)
[mysqld(API)] 2 node(s)
id=20 @192.168.1.217 (mysql-5.5.20 ndb-7.2.5)
id=21 @192.168.1.218 (mysql-5.5.20 ndb-7.2.5)
发现 ndbd id=3 的是新增的数据节点
第四步 、按顺序一个个启动存储节点
ndb_mgm> 1 RESTART
Node 1: Node shutdown initiated
Node 1: Node shutdown completed, restarting, no start.
Node 1 is being restarted
ndb_mgm> Node 1: Started (version 7.2.5)
ndb_mgm> 2 RESTART
Node 2: Node shutdown initiated
Node 2: Node shutdown completed, restarting, no start.
Node 2 is being restarted
ndb_mgm> Node 2: Start initiated (version 7.2.5)
Node 2: Started (version 7.2.5)
第五步、重启SQL节点(API节点)
[root@test217 data]# service mysqld restart
Shutting down MySQL.. [确定]
Starting MySQL................................ [确定]
[root@test218 data]# service mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL................................ [ OK ]
第六步、启动新存储几点并且初始化
[root@test219 bin]# /usr/local/mysql-cluster/bin/ndbd -c 192.168.1.215 --initial
2012-08-12 15:02:26 [ndbd] INFO -- Angel connected to '192.168.1.215:1186'
2012-08-12 15:02:26 [ndbd] INFO -- Angel allocated nodeid: 4
[root@test214 bin]# /usr/local/mysql-cluster/bin/ndbd -c 192.168.1.215 --initial
2012-08-12 15:02:26 [ndbd] INFO -- Angel connected to '192.168.1.215:1186'
2012-08-12 15:02:26 [ndbd] INFO -- Angel allocated nodeid: 4
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 4 node(s)
id=1 @192.168.1.217 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 0, Master)
id=2 @192.168.1.218 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 0)
id=3 @192.168.1.219 (mysql-5.5.20 ndb-7.2.5, no nodegroup) //这两个是新添加的,no nodegroup
id=4 @192.168.1.214 (mysql-5.5.20 ndb-7.2.5, no nodegroup)
[ndb_mgmd(MGM)] 1 node(s)
id=10 @192.168.1.215 (mysql-5.5.20 ndb-7.2.5)
[mysqld(API)] 2 node(s)
id=20 @192.168.1.217 (mysql-5.5.20 ndb-7.2.5)
id=21 @192.168.1.218 (mysql-5.5.20 ndb-7.2.5)
第七步、为新的节点分配组
ndb_mgm> CREATE NODEGROUP 3,4
Nodegroup 1 created
ndb_mgm> SHOW
Cluster Configuration
---------------------
[ndbd(NDB)] 4 node(s)
id=1 @192.168.1.217 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 0, Master)
id=2 @192.168.1.218 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 0)
id=3 @192.168.1.219 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 1) //这两个是新添加的 Nodegroup: 1,并且是连接状态
id=4 @192.168.1.214 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 1)
[ndb_mgmd(MGM)] 1 node(s)
id=10 @192.168.1.215 (mysql-5.5.20 ndb-7.2.5)
[mysqld(API)] 2 node(s)
id=20 @192.168.1.217 (mysql-5.5.20 ndb-7.2.5)
id=21 @192.168.1.218 (mysql-5.5.20 ndb-7.2.5)
第八步、重新分配数据
当新加入数据节点时,已经存在的数据或者索引不会被自动分配到新的节点上
在重新分配之前,新增加的数据节点没有内容。
ndb_mgm> all report mem
Node 1: Data usage is 71%(46919 32K pages of total 65536)
Node 1: Index usage is 25%(16032 8K pages of total 64032)
Node 2: Data usage is 71%(46919 32K pages of total 65536)
Node 2: Index usage is 25%(16032 8K pages of total 64032)
Node 3: Data usage is 0%(17 32K pages of total 65536)
Node 3: Index usage is 0%(0 8K pages of total 64032)
Node 4: Data usage is 0%(17 32K pages of total 65536)
Node 4: Index usage is 0%(0 8K pages of total 64032)
手工分配数据。
mysql> alter online table cairh_week_revenue_log reorganize partition;
查看新增的数据节点,已经有内容了。
ndb_mgm> all report mem
Connected to Management Server at: localhost:1186
Node 1: Data usage is 71%(46934 32K pages of total 65536)
Node 1: Index usage is 23%(15324 8K pages of total 64032)
Node 2: Data usage is 71%(46933 32K pages of total 65536)
Node 2: Index usage is 23%(15324 8K pages of total 64032)
Node 3: Data usage is 6%(3933 32K pages of total 65536)
Node 3: Index usage is 2%(1492 8K pages of total 64032)
Node 4: Data usage is 5%(3927 32K pages of total 65536)
Node 4: Index usage is 2%(1492 8K pages of total 64032)
#### 添加节点测试:
首先,新增加的节点,按照手册上给出的步骤,必须重启所有的NODB数据节点,并且重启所有的SQL节点,从设计上就很不合理,重启数据节点,避免不了造成性能下降,重启SQL节点,很可能造成前端程序,比如PHP访问不了数据库,当然,SQL节点可以通过安装LVS+Keepalive避免这个问题的发生,但避免不了造成性能下降。
重大弊端是:前端PHP程序往里面插入数据的时候,新增加的节点不能往里面写数据,手册上说的,必须通过命令ALTER ONLINE TABLE test.t1 OPTIMIZE TABLE;重新进行分片,这样才能激活新增加的节点,假如我有个表很大,70多G,那么这么大的表进行分片操作,时间就会非常长,而且这个时候会锁表,导致前端访问不了该表,并且有可能出现未知的错误。这点设计上非常的傻,不能自动识别,而且手工识别,风险太大。
4、 压力测试:
sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。数据库目前支持MySQL/Oracle/PostgreSQL。
sysbench按照指定的数量开启线程,每个线程与MySQL建立一个连接,每个线程不停地进行事务操作,打开事务,然后进行一些查询、更新、插入操作,提交事务,再开始新的事务;
所有的SQL只访问一个表--sbtest,是由sysbench的prepare命令建好的。其中的记录数,也是在prepare时指定好并创建的。
测试结束,会有一个统计结果,包括例如每秒事务数、平均响应时间等等;
a、下载安装略:
b、测试:
(1)、cpu性能测试
sysbench --test=cpu --cpu-max-prime=20000 run
cpu测试主要是进行素数的加法运算,在上面的例子中,指定了最大的素数为 20000,自己可以根据机器cpu的性能来适当调整数值。
(2)、线程测试
sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
(3)、磁盘IO性能测试
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw prepare
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run
说sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw cleanup
上述参数指定了最大创建16个线程,创建的文件总大小为3G,文件读写模式为随机读。
(4)、内存测试
sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run
上述参数指定了本次测试整个过程是在内存中传输 4G 的数据量,每个 block 大小为 8K。
5、 性能测试:
验证:
在整个mysql cluster 的测试过程当中,对于insert、update 、delete、groupby或order by等等都会执行的很快,远远超出单台机器的性能,可以说四台机器能够超过一台机器的4倍以上的速度。
同一条sql语句 分在两组mysql 中执行。
普通单机mysql
mysql> explain select count(*) from fundaccount_register_log ;
+----+-------------+--------------------------+-------+---------------+---------------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------------------+-------+---------------+---------------+---------+------+------+-------------+
| 1 | SIMPLE | fundaccount_register_log | index | NULL | index_user_id | 9 | NULL | 174 | Using index |
+----+-------------+--------------------------+-------+---------------+---------------+---------+------+------+-------------+
1 row in set (0.31 sec)
集群mysql
mysql> explain select count(*) from fundaccount_register_log ;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Select tables optimized away |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
1 row in set (0.02 sec)
插入测试:
集群:
mysql> insert into fundaccount_register_log values ('',1184444,nick,13587238895,68812437,20120606,1338950872,1001);
Query OK, 1 row affected, 1 warning (0.00 sec)
单机:
mysql> insert into fundaccount_register_log values ('',1184444,nick,13587238895,68812437,20120606,1338950872,1001);
Query OK, 1 row affected, 1 warning (0.03 sec)
mysql> insert into fundaccount_register_log values ('',1185444,nick,13587238895,69812437,20120606,1338950872,1001);
Query OK, 1 row affected, 1 warning (0.18 sec)
四、 管理及调优
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-management.html
1、日常备份
ndb_mgm管理客户端中的start backup命令来备份MySQL Cluster,通过ndb_restore命令进行MySQL Cluster的还原过程。首先是备份:
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-backup.html
五、注意
1:如果发现关闭一台机器的ndbd进程,另一台机器的ndbd的进程也关闭,则需要修改参数NoOfReplicas。
2:./ndbd --initial 不能同时在所有数据节点机器上执行,如执行,会删除所有数据
3:可以像操作非簇类型的数据库那样,操作mysqld节点
4:每次修改config.ini文件,重启ndb_mgmd时,需要删除mysql-cluster文件下的ndb_1_config.bin.1文件,因为他默认调用此文件
5:NDB 簇不支持自动发现数据库的功能,这点很重要,一旦在一个数据节点上创建了世界(world)数据库和它的表,
在簇中的每个SQL节点上还需要发出命令 CREATE DATABASE world,后跟FLUSH TABLES。这样,节点就能
识别数据库并读取其表定义。(在本版本MySQL Cluster 7.1.5下数据库也会自动同步的)
6:如果在相关节点服务器启动时,注意查看~/mysql/mysql-cluster目录内的相关日志文件以获取错误信息.
7:在管理节点的配置文件里各[mysqld],[ndbd]和[ndb_mgmd]配置的选项值顺序应该如下:
[mysqld]
Id=4
HostName=192.168.208.3
Id在顶端紧跟其后的是HostName,如果顺序错了,当SQL或数据节点连接管理节点时,管理节点无法正确的定位
到其对应的节点配置上.
因为无法定位到对应的节点配置,当没有剩余的[空节点]时,客户端节点启动时(./mysqld or ./ndbd)
还会报:
Configuration error: Error : Could not alloc node id at 192.168.0.231 port 1186: No free
node id found for mysqld
(API).Failed to initialize consumers
8:[空节点]是没有指定HostName选项的节点配置均为空节点,空节点可以用来动态配置一些动态IP的节点,
一般管理节点的 配置文件要预留3个以上的空节点,因为备份时需要连接一个节点,如下:
[mysqld]
Id=6
FAQ:
MYSQL CLUSTER 自带了一个错误代码的查看的小程序。通过这个小东西我们可以方便的把问题解决。
/usr/local/mysql/bin/perror --ndb 136
shell> perror 126 127 132 134 135 136 141 144 145
MySQL error code 126 = Index file is crashed
MySQL error code 127 = Record-file is crashed
MySQL error code 132 = Old database file
MySQL error code 134 = Record was already deleted (or record file crashed)
MySQL error code 135 = No more room in record file
MySQL error code 136 = No more room in index file
MySQL error code 141 = Duplicate unique key or constraint on write or update
MySQL error code 144 = Table is crashed and last repair failed
MySQL error code 145 = Table was marked as crashed and should be repaired
1、在导入大量的数据时候,报这个错误。此时检查一下 分配的内存情况。
ERROR 1114 (HY000) at line 191: The table 'cairh_day_ap_log' is full
ndb_mgm> all report memory
Connected to Management Server at: localhost:1186
Node 2: Data usage is 90%(2317 32K pages of total 2560)
Node 2: Index usage is 40%(952 8K pages of total 2336)
Node 3: Data usage is 90%(2315 32K pages of total 2560)
Node 3: Index usage is 40%(952 8K pages of total 2336)
解决方案: 扩大分配内存。
2、
ERROR 1297 (HY000) at line 538: Got temporary error 410 'REDO log files overloaded (decrease TimeBetweenLocalCheckpoints or increase NoOfFragmentLogFiles)' from NDBCLUSTER
FragmentLogFileSize 参数:
Default value = 16M
Changed it to FragmentLogFileSize=256M
2012-08-12 14:18:09 [MgmtSrvr] ERROR -- at line 53: Nodegroup 1 has 1 members, NoOfReplicas=2
2012-08-12 14:18:09 [MgmtSrvr] ERROR -- Could not load configuration from '/var/lib/mysql-cluster/config.ini'
六、 官方资料信息
■ MySQL集群评估指南:
http://www.mysql.com/why-mysql/white-papers/mysql_cluster_eval_guide.php
In this whitepaper, learn the fundamentals of how to design and select the proper components for a successful MySQL Cluster evaluation.
■ MySQL集群性能优化指南
http://www.mysql.com/why-mysql/white-papers/mysql_wp_cluster_perfomance.php
In this guide, learn how to tune and optimize the MySQL Cluster database to handle diverse workload requirements.
在该指南中,学习如何对MySQL集群进行性能优化以达到负载均衡的需求。
■ MySQL集群的相关文档及说明
http://dev.mysql.com/doc/index-cluster.html
■ MySQL集群配置器
http://www.severalnines.com/config/index.php
MySQL Cluster Configurator is a community tool which can generate good configuration files based on information you provide about the required deployment.
MySQL集群配置器是一个开源的社区工具,它根据你提供的有关部署信息来生成MySQL集群的配置文件。