主要內容
1. 獲取; 2. 安裝; 3. 配置; 4. 運行; 5. 測試; 6. 停止; 7. 總結
1. 獲取
這個不必多言吧,到 MySQL 網站上面下載就是了。MySQL Cluster 的英文部署測試手冊很簡明,這裡和其內容基本一樣。喜歡讀英文版的朋友可以直接下載,略過本文。
2. 安裝
先解壓,然後創建一個 symbolic link:
- michael@linux:~$ tar xvf mysql-cluster-gpl-7.2.4-linux2.6-x86_64.tar
- michael@linux:~$ ln -s mysql-cluster-gpl-7.2.4-linux2.6-x86_64 mysqlc
如果你願意,可以將~/mysqlc/bin
加入到你的 path 裡,方便使用。
3. 配置
作為在開發環境上第一次部署,還是以測試為主要目的。一個完整的 MySQL Cluster 由 MySQL Server,Data Nodes,Management Node 三部分組成。首先我們為它們創建一些必須的目錄:
- michael@linux:~$ mkdir mysql-cluster
- michael@linux:~$ cd mysql-cluster
- michael@linux:~$ mkdir conf ndb_data mysqld_data
然後在conf
目錄下創建如下兩個文件,分別是config.ini
和my.cnf
,內容如下:
config.ini
用於 MySQL Server 的配置,端口號port
根據你自己的情況設定。
- [mysqld]
- ndbcluster
- datadir=/home/user1/my_cluster/mysqld_data
- basedir=/home/user1/mysqlc
- port=5050
my.cnf
該文件用於配置各結點的 NodeId 和 Data Nodes 與 Management Node 的數據目錄。
- [ndb_mgmd]
- hostname=localhost
- datadir=/home/user1/my_cluster/ndb_data
- NodeId=1
- [ndbd default]
- noofreplicas=2
- datadir=/home/user1/my_cluster/ndb_data
- [ndbd]
- hostname=localhost
- NodeId=3
- [ndbd]
- hostname=localhost
- NodeId=4
- [mysqld]
- NodeId=50
這時你的目錄結構應該如下:
- ~
- +-- /mysql-cluster-gpl-7.2.4-linux2.6-x86_64
- +-- /mysqlc -> mysql-cluster-gpl-7.2.4-linux2.6-x86_64
- +-- /mysql-cluster
- +-- /conf
- +-- /ndb_data
- +-- /mysqld_data
4. 運行
MySQL Cluster 的啟動順序是有要求的,如下:
Management Node
Data Nodes
MySQL Server
命令如下:
- michael@linux:~$ cd ../mysql-cluster
- michael@linux:~/mysql-cluster$ $HOME/mysqlc/bin/ndb_mgmd -f conf/config.ini --initial --configdir=$HOME/mysql-cluster/conf/
- michael@linux:~/mysql-cluster$ $HOME/mysqlc/bin/ndbd -c localhost:1186
- michael@linux:~/mysql-cluster$ $HOME/mysqlc/bin/ndbd -c localhost:1186
檢查已經啟動的結點的狀態,命令為:
- poecahnt@linux:~$ $HOME/mysqlc/bin/ndb_mgm -e show
輸出如下:
- Connected to Management Server at: localhost:1186
- Cluster Configuration
- ---------------------
- [ndbd(NDB)] 2 node(s)
- id=3 @127.0.0.1 (mysql-5.5.19 ndb-7.2.4, Nodegroup: 0, Master)
- id=4 @127.0.0.1 (mysql-5.5.19 ndb-7.2.4, Nodegroup: 0)
- [ndb_mgmd(MGM)] 1 node(s)
- id=1 @127.0.0.1 (mysql-5.5.19 ndb-7.2.4)
- [mysqld(API)] 1 node(s)
- id=50 @127.0.0.1 (mysql-5.5.19 ndb-7.2.4)
表示已經可以啟動 MySQL Server 了。最後啟動 MySQL Server,命令為:
- michael@linux:~/mysql-cluseter$ $HOME/mysqlc/bin/mysqld --defaults-file=conf/my.cnf &
輸出信息如下:
- 120223 15:29:02 InnoDB: The InnoDB memory heap is disabled
- 120223 15:29:02 InnoDB: Mutexes and rw_locks use GCC atomic builtins
- 120223 15:29:02 InnoDB: Compressed tables use zlib 1.2.3
- 120223 15:29:02 InnoDB: Using Linux native AIO
- 120223 15:29:02 InnoDB: Initializing buffer pool, size = 128.0M
- 120223 15:29:02 InnoDB: Completed initialization of buffer pool
- 120223 15:29:02 InnoDB: highest supported file format is Barracuda.
- 120223 15:29:02 InnoDB: Waiting for the background threads to start
- 120223 15:29:03 InnoDB: 1.1.8 started; log sequence number 1595675
- 120223 15:29:04 [Note] NDB: NodeID is 50, management server 'localhost:1186'
- 120223 15:29:04 [Note] NDB[0]: NodeID: 50, all storage nodes connected
- 120223 15:29:04 [Warning] NDB: server id set to zero - changes logged to bin log with server id zero will be logged with another server id by slave mysqlds
- 120223 15:29:04 [Note] Starting Cluster Binlog Thread
- 120223 15:29:04 [Note] Event Scheduler: Loaded 0 events
- 120223 15:29:04 [Note] $HOME/mysqlc/bin/mysqld: ready for connections.
- Version: '5.5.19-ndb-7.2.4-gpl' socket: '/tmp/mysql.sock' port: 5050 MySQL Cluster Community Server (GPL)
- 120223 15:29:05 [Note] NDB: Creating mysql.ndb_schema
- 120223 15:29:08 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_schema
- 120223 15:29:09 [Note] NDB Binlog: logging ./mysql/ndb_schema (UPDATED,USE_WRITE)
- 120223 15:29:09 [Note] NDB: Creating mysql.ndb_apply_status
- 120223 15:29:09 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_apply_status
- 120223 15:29:09 [Note] NDB Binlog: logging ./mysql/ndb_apply_status (UPDATED,USE_WRITE)
- 120223 15:29:09 [Note] NDB: missing frm for mysql.ndb_index_stat_sample, discovering...
- 120223 15:29:09 [Note] NDB: missing frm for mysql.ndb_index_stat_head, discovering...
- 2012-02-23 15:29:10 [NdbApi] INFO -- Flushing incomplete GCI:s < 579/14
- 2012-02-23 15:29:10 [NdbApi] INFO -- Flushing incomplete GCI:s < 579/14
- 120223 15:29:10 [Note] NDB Binlog: starting log at epoch 579/14
- 120223 15:29:10 [Note] NDB Binlog: ndb tables writable
5. 測試
連接 MySQL Server 進行測試,確認可以用ndb
存儲引擎來創建數據庫中的表,如下:
- michael@linux:~$ $HOME/mysqlc/bin/mysql -h 127.0.0.1 -P 5050
- mysql> create database clusterdb;
- mysql> use clusterdb;
- mysql> insert into simples values (1),(2),(3),(4);
- mysql> select * from simples;
- +----+
- | id |
- +----+
- | 3 |
- | 1 |
- | 2 |
- | 4 |
- +----+
6. 停止
MySQL Cluster 必須手動停止,Data Nodes 可以用 ndb_mgm 來停止:
- michael@linux:~$ $HOME/mysqlc/bin/mysqladmin -h 127.0.0.1 -P 5050 shutdown
如果提示:
- /home/michael/mysqlc/bin/mysqladmin: shutdown failed; error: 'Access denied; you need (at least one of) the SHUTDOWN privilege(s) for this operation'
則在shutdown
命令前加上sudo
。
- michael@linux:~$ $HOME/mysqlc/bin/ndb_mgm -e shutdown
正常停止的信息類似如下:
- 120223 16:44:11 [Note] /home/michael/mysqlc/bin/mysqld: Normal shutdown
- michael@linux:~/mysql-cluster$ 120223 16:44:11 [Note] Event Scheduler: Purging the queue. 0 events
- 120223 16:44:13 [Warning] /home/michael/mysqlc/bin/mysqld: Forcing close of thread 2 user: 'michael'
- 120223 16:44:13 [Note] Stopping Cluster Utility thread
- 120223 16:44:13 [Note] Stopping Cluster Index Stats thread
- 120223 16:44:13 [Note] Stopping Cluster Binlog
- 120223 16:44:13 [Note] Stopping Cluster Index Statistics thread
- 120223 16:44:14 InnoDB: Starting shutdown...
- 120223 16:44:15 InnoDB: Shutdown completed; log sequence number 1595675
- 120223 16:44:15 [Note] /home/michael/mysqlc/bin/mysqld: Shutdown complete
7. 總結
有序啟動:Management Node,Data Nodes,MySQL Server
配置項與各節點的對應
每個結點都單獨啟動
Management Node 提供狀態查看等多種功能