mysql雙機叢集測試
術語介紹:
管理(MGM)節點:這類節點的作用是管理MySQL簇内的其他節點,如提供配置資料、啟動并停止節點、運作備份等。由于這類節點負責管理其他節點的配置,應在啟動其他節點之前首先啟動這類節點。MGM節點是用指令ndb_mgmd啟動的。
資料節點(ndbd):這類節點用于儲存簇的資料。資料節點的數目與副本的數目相關,是片段的倍數。例如,對于兩個副本,每個副本有兩個片段,那麼就有4個資料節點。沒有必要有一個以上的副本。資料節點是用指令ndbd啟動的。
SQL節點(mysqld):這是用來通路簇資料的節點。對于MySQL簇,用戶端節點是使用NDB簇存儲引擎的傳統MySQL伺服器。典型情況下,SQL節點是使用指令mysqld –ndbcluster啟動的,或将ndbcluster添加到my.cnf後使用mysqld啟動。
db1:192.168.1.188
db2:192.168.1.171
一、安裝叢集所需軟體
db1,db2上分别執行一下指令:
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
rpm -Uvh MySQL-Cluster-gpl-server-6.3.20-0.rhel5.i386.rpm
rpm -Uvh MySQL-Cluster-gpl-client-6.3.20-0.rhel5.i386.rpm
rpm -Uvh MySQL-Cluster-gpl-storage-6.3.20-0.rhel5.i386.rpm
rpm -Uvh MySQL-Cluster-gpl-management-6.3.20-0.rhel5.i386.rpm
rpm -Uvh MySQL-Cluster-gpl-tools-6.3.20-0.rhel5.i386.rpm
rpm -Uvh MySQL-Cluster-gpl-extra-6.3.20-0.rhel5.i386.rpm
二、配置節點
(db1,db2上分别執行)
1.config.ini檔案配置
cd /var/lib/mysql-cluster
vi config.ini
在config.ini中添加如下内容:
[ndbd default]
NoOfReplicas= 2
MaxNoOfConcurrentOperations= 10000
DataMemory= 80M
IndexMemory= 24M
TimeBetweenWatchDogCheck= 30000
DataDir= /var/lib/mysql-cluster
MaxNoOfOrderedIndexes= 512
StartPartialTimeout=100
StartPartitionedTimeout=100
ArbitrationTimeout=5000
TransactionDeadlockDetectionTimeout=5000
HeartbeatIntervalDbDb=5000
StopOnError=0
[ndb_mgmd default]
[ndb_mgmd]
Id=1
HostName= 192.168.1.188
Id=2
HostName= 192.168.1.171
[ndbd]
Id= 3
Id= 4
[mysqld]
ArbitrationRank=2
[tcp default]
PortNumber= 63132
2.my.cnf檔案配置
vi /etc/my.cnf
在my.cnf中添加如下内容:
default-storage-engine=ndbcluster
ndbcluster
ndb-connectstring=192.168.1.188,192.168.1.171
connect-string=192.168.1.188,192.168.1.171
[ndb_mgm]
config-file=/var/lib/mysql-cluster/config.ini
[mysql_cluster]
ndb-connectstring= 192.168.1.188,192.168.1.171
三、啟動管理節點
方法一(推薦):
Server1為:
# ndb_mgmd --ndb_nodeid=1
Server2為:
# ndb_mgmd --ndb_nodeid=2
方法二:
# ndb_mgmd -f /var/lib/mysql-cluster/config.ini
注:不同的伺服器用不同的啟動指令
在啟動時有一個警告提示
Cluster configuration warning:
arbitrator with id 1 and db node with id 3 on same host 192.168.1.188
arbitrator with id 2 and db node with id 4 on same host 192.168.1.171
Running arbitrator on the same host as a database node may
cause complete cluster shutdown in case of host failure.
說節點1和3,2和4的arbitrator一樣,可能引起整個叢集失敗。(可以不用放在心上)
四、啟動資料節點
方法一:初始化叢集,--initial參數隻有在第一次啟動是使用.
在Server1中
# ndbd --nodeid=3 --initial
在Server2中
# ndbd --nodeid=4 --iniitial
# ndbd --connect-string="nodeid=3;host=192.168.1.188:1186"
# ndbd --connect-string="nodeid=4;host=192.168.1.111:1186"
啟動sql節點:
# mysqld_safe --ndb_nodeid=5 --user=mysql &
# mysqld_safe --ndb_nodeid=6 --user=mysql &
五、檢查工作狀态
在任意一台機子上啟動管理終端:
# ndb_mgm
鍵入show指令檢視目前工作狀态:
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=3 @192.168.1.188 (Version: 6.0.0, Nodegroup: 0, Master)
id=4 @192.168.1.171 (Version: 6.0.0, Nodegroup: 0)
[ndb_mgmd(MGM)] 2 node(s)
id=1 @192.168.1.188 (Version: 6.0.0)
id=2 @192.168.1.171 (Version: 6.0.0)
[mysqld(API)] 2 node(s)
id=5 (not connected, accepting connect from any host)
id=6 (not connected, accepting connect from any host)
六、檢查資料是否同步
七、破壞性測試
八、叢集的關閉
#ndb_mgm -e shutdown