MySQL cluster是share nothing的集群,采用ndb存储引擎,和Oracle的RAC采用集中存储不同,是一种分布式的架构,所以可以很轻松的实现在同一台主机上配置MySQL Cluster,相对RAC来说要简单得多。
在MySQL Cluster中,有三种不同的节点:
- 管理节点:守护进程为ndb_mgmd,用于管理cluster。
- 数据节点: 守护进程为ndbd,用于存放数据
- SQL节点:守护进程为mysqld,就是一个MySQL实例,对外供客户端连接访问数据。
本文将在一台64位linux主机上同时配置上述三种节点。在实际生产环境中,根据需要,可以在相同或者不同的机器部署节点。本次实例中共包含以下节点:
- 一个管理节点
- 两个数据节点
- 三个SQL节点
下载Mysql cluster,当前版本7.0.6,http://dev.mysql.com/downloads/cluster/7.0.html
解压,并复制到安装目录
tar zxvf mysql-cluster-gpl-7.0.6-linux-x86_64-glibc23.tar.gz cp mysql-cluster-gpl-7.0.6-linux-x86_64-glibc23 /u01/mysql-cluster cd /u01/mysql-cluster
创建三个MySQL实例的数据目录
mkdir data/data1 mkdir data/data2 mkdir data/data3 mkdir data/data1/mysql mkdir data/data1/test mkdir data/data2/mysql mkdir data/data2/test mkdir data/data3/mysql mkdir data/data3/test
Cluster配置文件如下
$ more conf/config.ini [ndbd default] noofreplicas=2 [ndbd] hostname=localhost id=2 [ndbd] hostname=localhost id=3 [ndb_mgmd] id = 1 hostname=localhost [mysqld] id=4 hostname=localhost [mysqld] id=5 hostname=localhost [mysqld] id=6 hostname=localhost
三个MySQL实例配置文件如下
$ more conf/my1.cnf [mysqld] ndb-nodeid=4 ndbcluster=true datadir=/u01/mysql-cluster/data/data1 basedir=/u01/mysql-cluster port=9306 server-id=1 log-bin $ more conf/my2.cnf [mysqld] ndb-nodeid=5 ndbcluster=true datadir=/u01/mysql-cluster/data/data2 basedir=/u01/mysql-cluster port=9307 server-id=2 log-bin $ more conf/my3.cnf [mysqld] ndb-nodeid=6 ndbcluster=true datadir=/u01/mysql-cluster/data/data3 basedir=/u01/mysql-cluster port=9308 server-id=3 log-bin
初始化三个MySQL实例
script/mysql_install_db --basedir=/u01/mysql-cluster --datadir=/u01/mysql-cluster/data/data1 script/mysql_install_db --basedir=/u01/mysql-cluster --datadir=/u01/mysql-cluster/data/data2 script/mysql_install_db --basedir=/u01/mysql-cluster --datadir=/u01/mysql-cluster/data/data3
初始化管理节点
bin/ndb_mgmd --initial -f conf/config.ini --configdir=/u01/mysql-cluster
进入管理节点查看配置
$ bin/ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> help --------------------------------------------------------------------------- NDB Cluster -- Management Client -- Help --------------------------------------------------------------------------- HELP Print help text HELP COMMAND Print detailed help for COMMAND(e.g. SHOW) SHOW Print information about cluster CREATE NODEGROUP ,... Add a Nodegroup containing nodes DROP NODEGROUP Drop nodegroup with id NG START BACKUP [NOWAIT | WAIT STARTED | WAIT COMPLETED] START BACKUP [] [NOWAIT | WAIT STARTED | WAIT COMPLETED] START BACKUP [] [SNAPSHOTSTART | SNAPSHOTEND] [NOWAIT | WAIT STARTED | WAIT COMPLETED] Start backup (default WAIT COMPLETED,SNAPSHOTEND) ABORT BACKUP Abort backup SHUTDOWN Shutdown all processes in cluster CLUSTERLOG ON [] ... Enable Clus = ALERT | CRITICAL | ERROR | WARNING | INFO | DEBUG = STARTUP | SHUTDOWN | STATISTICS | CHECKPOINT | NODERESTART | CONNECTION | INFO | ERROR | CONGESTION | DEBUG | BACKUP = 0 - 15 = ALL | Any database node id For detailed help on COMMAND, use HELP COMMAND. ndb_mgm> show Connected to Management Server at: localhost:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 (not connected, accepting connect from localhost) id=3 (not connected, accepting connect from localhost) [ndb_mgmd(MGM)] 1 node(s) id=1 @localhost (mysql-5.1.34 ndb-7.0.6) [mysqld(API)] 3 node(s) id=4 (not connected, accepting connect from localhost) id=5 (not connected, accepting connect from localhost) id=6 (not connected, accepting connect from localhost)
初始化数据节点
bin/ndbd --initial -c localhost:1186 2009-06-21 23:13:19 [ndbd] INFO -- Configuration fetched from 'localhost:1186', generation: 1 bin/ndbd --initial -c localhost:1186 2009-06-21 23:13:50 [ndbd] INFO -- Configuration fetched from 'localhost:1186', generation: 1
启动SQL节点
bin/mysqld --defaults-file=conf/my1.cnf& [1] 17843 090621 23:14:36 [Warning] No argument was provided to --log-bin, and --log-bin-index was not used; so replication may break when this MySQL server acts as a master and has his hostname changed!! Please use '--log-bin=test-bin' to avoid this problem. InnoDB: The first specified data file ./ibdata1 did not exist: InnoDB: a new database to be created! 090621 23:14:36 InnoDB: Setting file ./ibdata1 size to 10 MB InnoDB: Database physically writes the file full: wait... 090621 23:14:36 InnoDB: Log file ./ib_logfile0 did not exist: new to be created InnoDB: Setting log file ./ib_logfile0 size to 5 MB InnoDB: Database physically writes the file full: wait... 090621 23:14:36 InnoDB: Log file ./ib_logfile1 did not exist: new to be created InnoDB: Setting log file ./ib_logfile1 size to 5 MB InnoDB: Database physically writes the file full: wait... InnoDB: Doublewrite buffer not found: creating new InnoDB: Doublewrite buffer created InnoDB: Creating foreign key constraint system tables InnoDB: Foreign key constraint system tables created 090621 23:14:36 InnoDB: Started; log sequence number 0 0 090621 23:14:36 [Note] NDB: NodeID is 4, management server 'localhost:1186' 090621 23:14:37 [Note] NDB[0]: NodeID: 4, all storage nodes connected 090621 23:14:37 [Note] Starting Cluster Binlog Thread 090621 23:14:37 [Note] Event Scheduler: Loaded 0 events 090621 23:14:37 [Note] bin/mysqld: ready for connections. Version: '5.1.34-ndb-7.0.6-cluster-gpl-log' socket: '/tmp/mysql.sock' port: 9306 MySQL Cluster Server (GPL) 090621 23:14:38 [Note] NDB Binlog: Ndb tables initially read only. 090621 23:14:38 [Note] NDB: Creating mysql.ndb_schema 090621 23:14:38 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_schema 090621 23:14:38 [Note] NDB Binlog: logging ./mysql/ndb_schema (UPDATED,USE_WRITE) 090621 23:14:38 [Note] NDB: Creating mysql.ndb_apply_status 090621 23:14:39 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_apply_status 090621 23:14:39 [Note] NDB Binlog: logging ./mysql/ndb_apply_status (UPDATED,USE_WRITE) 2009-06-21 23:14:39 [NdbApi] INFO -- Flushing incomplete GCI:s < 20/3 2009-06-21 23:14:39 [NdbApi] INFO -- Flushing incomplete GCI:s < 20/3 090621 23:14:39 [Note] NDB Binlog: starting log at epoch 20/3 090621 23:14:39 [Note] NDB Binlog: ndb tables writable
bin/mysqld --defaults-file=conf/my2.cnf& bin/mysqld --defaults-file=conf/my3.cnf&
查看cluster
bin/ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> show Connected to Management Server at: localhost:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6, Nodegroup: 0, Master) id=3 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6) [mysqld(API)] 3 node(s) id=4 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6) id=5 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6) id=6 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6)
创建测试表
bin/mysql -uroot -h localhost -P 9306 --socket=/tmp/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.34-ndb-7.0.6-cluster-gpl-log MySQL Cluster Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. root@(none) 11:21:24>use test Database changed root@test 11:21:26>create table test_ndb(i int,a varchar(20),primary key(i)) engine=ndb; 090621 23:22:32 [Note] NDB Binlog: CREATE TABLE Event: REPL$test/test_ndb 090621 23:22:32 [Note] NDB Binlog: logging ./test/test_ndb (UPDATED,USE_WRITE) 090621 23:22:32 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$test/test_ndb 090621 23:22:32 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$test/test_ndb 090621 23:22:32 [Note] NDB Binlog: logging ./test/test_ndb (UPDATED,USE_WRITE) 090621 23:22:32 [Note] NDB Binlog: logging ./test/test_ndb (UPDATED,USE_WRITE) Query OK, 0 rows affected (1.10 sec) root@test 11:22:32>insert into test_ndb values(1,'NinGoo'); Query OK, 1 row affected (0.02 sec) [mysql@dbconsole mysql-cluster]$ ls -l data/data1/test total 12 -rw-rw---- 1 mysql dba 8578 Jun 21 23:22 test_ndb.frm -rw-rw---- 1 mysql dba 0 Jun 21 23:22 test_ndb.ndb [mysql@dbconsole mysql-cluster]$ ls -l data/data2/test total 12 -rw-rw---- 1 mysql dba 8578 Jun 21 23:22 test_ndb.frm -rw-rw---- 1 mysql dba 0 Jun 21 23:22 test_ndb.ndb [mysql@dbconsole mysql-cluster]$ ls -l data/data3/test total 12 -rw-rw---- 1 mysql dba 8578 Jun 21 23:22 test_ndb.frm -rw-rw---- 1 mysql dba 0 Jun 21 23:22 test_ndb.ndb $ bin/mysql -uroot -P 9307 --socket=/tmp/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.34-ndb-7.0.6-cluster-gpl-log MySQL Cluster Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. root@(none) 11:24:38>use test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed root@test 11:24:41>select * from test_ndb; +---+--------+ | i | a | +---+--------+ | 1 | NinGoo | +---+--------+ 1 row in set (0.02 sec)
相关推荐
MySQL Cluster的核心优势在于其能够支持多节点之间的数据复制和故障转移,从而确保即使在部分节点发生故障的情况下,整个集群仍能继续提供服务。 **基本概念**: - **NDB (NoData Block)**:NDB是一种内存中的存储...
它基于NDBCluster存储引擎,支持在同一集群中运行多个MySQL服务器实例。 - **集群架构**:MySQL Cluster采用无共享架构,意味着各个节点不共享内存或磁盘资源,这使得系统能够利用低成本硬件构建,并且避免了单点...
MySQL集群使用NDB Cluster存储引擎,允许在无共享架构中运行多个MySQL服务器,确保了系统的可扩展性和容错性。 集群的核心特性包括: 1. **无共享架构**:MySQL集群采用无共享设计,意味着每个组件都有自己的内存...
3. **配置虚拟机**:在Xen Server上创建并配置虚拟机,安装MySQL Cluster。 4. **配置MySQL Cluster**:按照集群设计进行具体配置,包括数据分区、备份策略等。 5. **性能调优**:对集群进行性能调优,确保其在实际...
在这样的背景下,云原生MySQL选择了InnoDB Cluster,它是一个内置高可用性的解决方案,不需要外部工具或脚本。InnoDB Cluster支持单主和多主模式,基于Paxos算法实现数据复制一致性,提供内置的组成员管理、冲突检测...
MySQL动态库指的是MySQL数据库系统中的动态链接库,主要用于在运行时加载和使用特定的数据库功能。在Linux或Unix等类Unix系统中,动态库通常以`.so`(共享对象)文件形式存在,而在Windows系统中则表现为`.dll`...
通常,PMM服务器需要与MySQL服务器在同一网络内,以便能够无阻碍地收集和展示性能数据。 安装PMM的过程大致分为以下几步: 1. 下载PMM的安装包,根据你的操作系统选择对应的版本。 2. 安装PMM服务器,这通常涉及到...
通过命名空间(namespace),可以轻松支持多个不同应用共享同一份配置,同时也允许应用对共享配置进行覆盖。 考虑到民生银行开发、测试、生产环境之间的网络隔离,Apollo部署时仅保留了DEV环境,而测试和生产环境则...
如果有两个事务向在集群中不同的节点向同一行写入并提交,失败的节点将中止。 (7)XA 事务不支持,由于在提交上可能回滚。 (8)整个集群的写入吞吐量是由最弱的节点限制,如果有一个节点变得缓慢,那么整个集群将...
- **跨平台监控**:支持跨平台监控,即在同一工作计算机上可以同时管理不同平台的高可用集群。 ##### 2. 极速切换 - **资源深度开发**:通过对共享存储进行深度开发,优化资源操作。 - **资源有序依赖**:结合资源...
- 网络通信:可以与mysqld不在同一台主机,通过网络通信。 - 内存需求:索引和部分数据需存储在内存,对内存需求较高。 - 应用场景:适用于极高并发需求,查询简单且数据量小,不适合水平分片的场景。 - 最佳...
- **MySQL CLUSTER套件:** 覆盖masterslave、node01至node06以及data01、data02,包含MySQL-bench、MySQL-ndb-management等多个服务包,依赖于perl-DBI-1.32-94。 - **WWW套件:** 部署在node01至node06,服务包...
- **资源池架构**:包括区域(Zone)、提供点(Pod)、群集(Cluster)和主机,以及主存储和辅助存储等层次。 - **网络架构**:涵盖虚拟网络通信模型,实现虚拟机间的通信。 此外,CMP还支持多种虚拟化技术,如VMware、...