安裝環境及軟件包:2台PCMySQL-6.0.0-alpha.tar.gzCentos5SerA:192.168.1.50SerB:192.168.1.8
1、在SerA和SerB上安裝MySQL以下步驟需要在SerA和SerB上各做一次
- # mv MySQL-6.0.0-alpha.tar.gz /tmp/package
- # cd /tmp/package
- # groupadd MySQL
- # useradd -g mysql MySQL
- # tar -zxvf MySQL-6.0.0-alpha.tar.gz
- # rm -f MySQL-6.0.0-alpha.tar.gz
- # mv mysql-6.0.0-alpha MySQL
- # cd MySQL
- # ./configure --prefix=/usr/local --with-extra-charsets=complex --with-plugin-ndbcluster
- --with-plugin-partition --with-plugin-innobase --with-unix-socket-path=/usr/local/var/MySQL.sock
- # make && make install
- #ln -s /usr/local/libexec/ndbd /usr/bin
- #ln -s /usr/local/libexec/ndb_mgmd /usr/bin
- #ln -s /usr/local/libexec/ndb_cpcd /usr/bin
- #ln -s /usr/local/libexec/MySQLd /usr/bin
- #ln -s /usr/local/libexec/MySQLmanager /usr/bin
- #MySQL_install_db --user=MySQL
我用的是:MySQL-5.0.85-Linux-i686.tar.gz
二、安裝並配置MySQL節點
以下步驟需要在SerA和SerB上各做一次
1.配置管理MySQL節點配置文件:
- # mkdir /var/lib/MySQL-cluster
- # cd /var/lib/MySQL-cluster
- # vi config.ini
- 在config.ini中添加如下內容:
- [ndbd default]
- NoOfReplicas= 2
- MaxNoOfConcurrentOperations= 10000
- # Amount of memory required=(SizeofDatabase * NumberOfReplicas * 1.1 ) / NumberOfDataNodes
- DataMemory= 128M
- 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]
- DataDir=/var/lib/MySQL-cluster
- [ndb_mgmd]
- Id=1
- HostName= 192.168.1.50
- [ndb_mgmd]
- Id=2
- HostName= 192.168.1.8
- [ndbd]
- Id= 3
- HostName= 192.168.1.50
- [ndbd]
- Id= 4
- HostName= 192.168.1.8
- [MySQLd]
- ArbitrationRank=2 (非常重要,全靠有它,才可以形成仲裁競爭,從而當另一個機子當了時,此機還可以有知道partion完整的節點)
- [MySQLd]
- ArbitrationRank=2
- [MySQLd] (多出的這項是留給恢復時使用的.)
- [MySQLd] (多出的這項是留給恢復時使用的.)
- [tcp default]
- PortNumber= 63132
- [separator]
2.配置通用my.cnf文件,MySQLd及ndbd,ndb_mgmd均使用此文件.
- # vi /etc/my.cnf
- 在my.cnf中添加如下內容:
- [MySQLd]
- datadir=/usr/local/var
- socket=/usr/local/var/MySQL.sock
- # Default to using old passWord format for compatibility with MySQL 3.x
- # clIEnts (those using the MySQLclIEnt10 compatibility package).
- old_passWords=1
- default-storage-engine=ndbcluster
- ndbcluster
- ndb-connectstring=192.168.1.50,192.168.1.8
- [ndbd]
- connect-string=192.168.1.50,192.168.1.8
- [ndb_mgm]
- connect-string=192.168.1.50,192.168.1.8
- [ndb_mgmd]
- config-file=/var/lib/MySQL-cluster/config.ini
- [MySQL_cluster]
- ndb-connectstring=192.168.1.50,192.168.1.8
- [MySQL.server]
- user=MySQL
- basedir=/usr/local/
- [MySQLd_safe]
- log-error=/var/log/MySQLd.log
- #pid-file=/var/run/mysqld/MySQLd.pid
- [MySQL]
- #socket=/usr/local/var/MySQL.sock
- [MySQLadmin]
- #socket=/usr/local/var/MySQL.sock
- [ndb_restore default] 保存退出後.
三.啟動管理MySQL節點SerA為:
- [root@SerA ~]# ndb_mgmd --ndb_nodeid=1
- Cluster configuration warning:
- arbitrator with id 1 and db node with id 3 on same host 192.168.1.50
- arbitrator with id 2 and db node with id 4 on same host 192.168.1.8
- arbitrator with id 5 has no hostname specifIEd
- arbitrator with id 6 has no hostname specifIEd
- Running arbitrator on the same host as a database node may
- cause complete cluster shutdown in case of host failure.
注:在啟動時有一個警告提示說MySql節點1和3,2和4的arbitrator一樣,可能引起整個集群失敗。(可以不用放在心上)啟動管理MySQL節點SerB為:[root@SerB ~]# ndb_mgmd --ndb_nodeid=2.