MySQL的cluster主要分為3種node
mgm node 沒錯,照字面上看起來就是管理用的node
sql node 未來查詢都會透過這個node來做增刪改查
data node 存放資料的地方

首先準備4台機器,裝好Linux作業系統,其他套件都不要選
10.0.0.101 (mgm node)
10.0.0.102 (sql node)
10.0.0.103 (data node)
10.0.0.104 (data node)

編輯四台node的/etc/hosts (非必要,只是我的怪僻XD)
10.0.0.101    node1
10.0.0.102    node2
10.0.0.103    node3
10.0.0.104    node4

安裝MySQL Cluster前把iptables / SELinux 都關掉先,會少很多麻煩
如果要關掉SELinux,必須要reboot
chkconfig iptables off
vi /etc/sysconfig/selinux
SELINUX=enforcing 修改為 SELINUX=disabled
reboot

下載需要的套件回來,以下是前幾天下載的7.1.4b,現在最新的版本是7.1.5
http://dev.mysql.com/downloads/cluster/

MySQL-Cluster-gpl-client-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-clusterj-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-debuginfo-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-devel-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-embedded-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-extra-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-management-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-server-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-shared-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-storage-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-test-7.1.4b-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-tools-7.1.4b-1.rhel5.x86_64.rpm

如果不想安裝全部,各Node基本需要的套件如下
mgm node
rpm -ihv MySQL-Cluster-gpl-management*.rpm
rpm -ihv MySQL-Cluster-gpl-tools*.rpm
sql node
rpm -ivh MySQL-Cluster-gpl-server*.rpm
rpm -ivh MySQL-Cluster-gpl-client*.rpm
data node
rpm -ihv MySQL-Cluster-gpl-storage*.rpm

省得麻煩的話,就全裝唄XD

開始設定了,在mgm node
如果沒有/var/lib/mysql-cluster的話就自己建一個目錄
[root@node1 ~]# mkdir -p /var/lib/mysql-cluster
[root@node1 ~]# vi /var/lib/mysql-cluster/config.ini

[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[tcp default]
portnumber=2202
[ndb_mgmd]
hostname=10.0.0.101
id=1
datadir=/var/lib/mysql-cluster
[ndbd]
hostname=10.0.0.104
datadir=/var/lib/mysql-cluster
id=4
[ndbd]
hostname=10.0.0.103
datadir=/var/lib/mysql-cluster
id=3
[mysqld]
hostname=10.0.0.102
id=2

編輯sql node的/etc/my.cnf

[mysqld]
ndbcluster # run NDB storage engine
ndb-connectstring=node1   ##這邊要寫mgm node的位址
[mysql_cluster]
ndb-connectstring=node1   ##這邊要寫mgm node的位址


啟動服務
順序: mgm node -> data node -> sql node
mgm node:
[root@node1 ~]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial (第一次執行要加-f /var/lib/mysql-cluster/config.ini
--initial , 第二次以後就不用了)
觀察一下mysql cluster的狀態,我們可以用以下的指令
[root@node1 ~]# ndb_mgm -e show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=3 (not connected, accepting connect from 10.0.0.103)
id=4 (not connected, accepting connect from 10.0.0.104)

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

[mysqld(API)]   1 node(s)
id=2 (not connected, accepting connect from 10.0.0.102)


data node:
ndbd --initial (第一次執行要加 --initial , 第二次以後就不用了)
如果無法啟動的話,可以直接指定他mgm node在哪邊
[root@node3 ~]# ndbd -c node1
[root@node1 ~]# ndb_mgm -e show
Connected to Management Server at: 10.0.0.101:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=3    @10.0.0.103  (mysql-5.1.44 ndb-7.1.4, starting, Nodegroup: 0, Master)
id=4    @10.0.0.104  (mysql-5.1.44 ndb-7.1.4, starting, Nodegroup: 0)

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

[mysqld(API)]   1 node(s)
id=2 (not connected, accepting connect from 10.0.0.102)

sql node:
service mysql start (注意!!不是mysqld喔)
最後看看狀態,是不是所有的node都起來了
Connected to Management Server at: node1:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=3    @10.0.0.103  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0, Master)
id=4    @10.0.0.104  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0)

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

[mysqld(API)]   1 node(s)
id=2    @10.0.0.102  (mysql-5.1.44 ndb-7.1.4)

嗯..看來 data node要的記憶體要大一點.. (筆記)

參考資料:
http://forum.icst.org.tw/phpbb/viewtopic.php?f=10&t=17903
http://twpug.net/docs/mysql-5.1/ndbcluster.html
http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster.html
http://www.codecharge.com.tw/phpBB3/viewtopic.php?f=11&t=540



helloworld 發表在 痞客邦 PIXNET 留言(0) 人氣()