一臺主機上配置MySQL Cluster

byfree發表於2010-07-27

一個管理節點 ndb_mgmd(MGM)
兩個資料節點 ndbd(NDB)
兩個SQL節點  mysqld(API)

[root@oel5 tmp]# tar xvfz mysql-cluster-gpl-7.1.4b-linux-x86_64-glibc23.tar.gz
[root@oel5 tmp]# mv mysql-cluster-gpl-7.1.4b-linux-x86_64-glibc23 mysqlc

建立資料檔案目錄:
[root@oel5 /]# cd /mysqlc
[root@oel5 mysqlc]# mkdir data1
[root@oel5 mysqlc]# mkdir data2
[root@oel5 /]# chown -R mysql:dba mysqlc/

建立cluster配置檔案:
[root@oel5 mysqlc]# vi config.ini
-----------------------------------------
[NDBD DEFAULT]
NoOfReplicas: 2
[MGM DEFAULT]
PortNumber: 1186
[NDB_MGMD]
Id: 1
HostName: localhost
ArbitrationRank: 1
[NDBD]
Id: 2
HostName: localhost
[NDBD]
Id: 3
HostName: localhost
[mysqld]
Id: 5
HostName: localhost
[mysqld]
Id: 6
HostName: localhost
-----------------------------------------

初始化管理節點(ndb_mgmd):
[root@oel5 /]# cd /mysqlc
[root@oel5 mysqlc]# bin/ndb_mgmd --initial -f config.ini --configdir=/mysqlc
2010-07-27 09:42:49 [MgmtSrvr] INFO     -- NDB Cluster Management Server. mysql-5.1.44 ndb-7.1.4b
2010-07-27 09:42:49 [MgmtSrvr] INFO     -- Reading cluster configuration from 'config.ini'

初始化資料節點(ndbd):
[root@oel5 mysqlc]# bin/ndbd --initial -c localhost:1186
2010-07-27 09:47:42 [ndbd] INFO     -- Configuration fetched from 'localhost:1186', generation: 1
[root@oel5 mysqlc]# bin/ndbd --initial -c localhost:1186
2010-07-27 09:48:32 [ndbd] INFO     -- Configuration fetched from 'localhost:1186', generation: 1

建立兩個mysqld(API)節點配置檔案:
[root@oel5 mysqlc]# vi my1.cnf
-----------------------------------------
[mysqld]
ndb-nodeid=5
ndbcluster
port            = 9306
datadir = /mysqlc/data1
basedir = /mysqlc
server-id = 1
log-bin
socket = /tmp/mysql5.sock
-----------------------------------------

[root@oel5 mysqlc]# vi my2.cnf
-----------------------------------------
[mysqld]
ndb-nodeid=6
ndbcluster
port            = 9307
datadir = /mysqlc/data2
basedir = /mysqlc
server-id = 2
log-bin
socket = /tmp/mysql6.sock
-----------------------------------------

初始化mysqld(API)節點:
[root@oel5 mysqlc]# scripts/mysql_install_db --basedir=/mysqlc --datadir=/mysqlc/data1
[root@oel5 mysqlc]# scripts/mysql_install_db --basedir=/mysqlc --datadir=/mysqlc/data2

啟動mysqld(API)節點:
su - mysql
[mysql@oel5 mysqlc]$ bin/mysqld --defaults-file=my1.cnf &
[1] 8040
[mysql@oel5 mysqlc]$ 100727 10:31:53 [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=oel5-bin' to avoid this problem.
100727 10:31:53 [Note] Plugin 'FEDERATED' is disabled.
100727 10:31:53  InnoDB: Started; log sequence number 0 44233
100727 10:31:53 [Note] NDB: NodeID is 5, management server 'localhost:1186'
100727 10:31:53 [Note] NDB[0]: NodeID: 5, all storage nodes connected
100727 10:31:53 [Note] Starting Cluster Binlog Thread
100727 10:31:53 [Note] Event Scheduler: Loaded 0 events
100727 10:31:54 [Note] NDB Binlog: Ndb tables initially read only.
100727 10:31:54 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$mysql/ndb_schema
100727 10:31:54 [Note] NDB Binlog: logging ./mysql/ndb_schema (UPDATED,USE_WRITE)
100727 10:31:54 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$mysql/ndb_apply_status
100727 10:31:54 [Note] NDB Binlog: logging ./mysql/ndb_apply_status (UPDATED,USE_WRITE)
100727 10:31:54 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$test/t_ndb
100727 10:31:54 [Note] NDB Binlog: logging ./test/t_ndb (UPDATED,USE_WRITE)
2010-07-27 10:31:55 [NdbApi] INFO     -- Flushing incomplete GCI:s < 1264/7
2010-07-27 10:31:55 [NdbApi] INFO     -- Flushing incomplete GCI:s < 1264/7
100727 10:31:55 [Note] NDB Binlog: starting log at epoch 1264/7
100727 10:31:55 [Note] NDB Binlog: ndb tables writable
100727 10:31:55 [Note] bin/mysqld: ready for connections.
Version: '5.1.44-ndb-7.1.4b-cluster-gpl-log'  socket: '/tmp/mysql5.sock'  port: 9306  MySQL Cluster Server (GPL)

[mysql@oel5 mysqlc]$ bin/mysqld --defaults-file=my2.cnf &
[2] 8060
[mysql@oel5 mysqlc]$ 100727 10:31:58 [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=oel5-bin' to avoid this problem.
100727 10:31:58 [Note] Plugin 'FEDERATED' is disabled.
100727 10:31:59  InnoDB: Started; log sequence number 0 44233
100727 10:31:59 [Note] NDB: NodeID is 6, management server 'localhost:1186'
100727 10:31:59 [Note] NDB[0]: NodeID: 6, all storage nodes connected
100727 10:31:59 [Note] Starting Cluster Binlog Thread
100727 10:31:59 [Note] Event Scheduler: Loaded 0 events
100727 10:32:00 [Note] NDB Binlog: Ndb tables initially read only.
100727 10:32:00 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$mysql/ndb_schema
100727 10:32:00 [Note] NDB Binlog: logging ./mysql/ndb_schema (UPDATED,USE_WRITE)
100727 10:32:00 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$mysql/ndb_apply_status
100727 10:32:00 [Note] NDB Binlog: logging ./mysql/ndb_apply_status (UPDATED,USE_WRITE)
100727 10:32:00 [Note] NDB Binlog: Node: 2, subscribe from node 6, Subscriber bitmask 040
100727 10:32:00 [Note] NDB Binlog: Node: 3, subscribe from node 6, Subscriber bitmask 040
100727 10:32:00 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$test/t_ndb
100727 10:32:00 [Note] NDB Binlog: logging ./test/t_ndb (UPDATED,USE_WRITE)
2010-07-27 10:32:00 [NdbApi] INFO     -- Flushing incomplete GCI:s < 1267/2
2010-07-27 10:32:00 [NdbApi] INFO     -- Flushing incomplete GCI:s < 1267/2
100727 10:32:00 [Note] NDB Binlog: starting log at epoch 1267/2
100727 10:32:00 [Note] NDB Binlog: ndb tables writable
100727 10:32:00 [Note] bin/mysqld: ready for connections.
Version: '5.1.44-ndb-7.1.4b-cluster-gpl-log'  socket: '/tmp/mysql6.sock'  port: 9307  MySQL Cluster Server (GPL)

檢視cluster狀態:
[mysql@oel5 mysqlc]$ 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.44 ndb-7.1.4, Nodegroup: 0, Master)
id=3    @127.0.0.1  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @127.0.0.1  (mysql-5.1.44 ndb-7.1.4)

[mysqld(API)]   2 node(s)
id=5    @127.0.0.1  (mysql-5.1.44 ndb-7.1.4)
id=6    @127.0.0.1  (mysql-5.1.44 ndb-7.1.4)

建表測試:
[mysql@oel5 ~]$ mysql -S /tmp/mysql5.sock
mysql> use test;
mysql> create table t5 (id int);
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t5             |
+----------------+
mysql> create table t_ndb (id int) engine=ndb;
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t5             |
| t_ndb          |
+----------------+

[mysql@oel5 ~]$ mysql -S /tmp/mysql6.sock
mysql> use test;
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t_ndb          |
+----------------+
mysql> create table t6 (id int);
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t6             |
| t_ndb          |
+----------------+

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17997/viewspace-669579/,如需轉載,請註明出處,否則將追究法律責任。

相關文章