搭建sql節點(4個),data節點(4個),manage節點(1個)---源代碼版本node
mysql cluter啓動順序:
management node ---> data node ---> sql nodemysql
############
源代碼安裝mysql-cluster-gpl-7.2.15
[root@Cent67 local]# mv mysql/* ndbbin/
1.下載最新版本cmake
yum remove cmake
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
tar xvf cmake-2.8.12.2.tar.gz
cd cmake-2.8.12.2
編譯:./configure
make && make install
2.安裝mysql-cluster-gpl-7.2.15.tar.gz
##解壓縮文件
[root@Cent67 soft]# tar xvf mysql-cluster-gpl-7.2.15.tar.gz
##切換目錄
cd mysql-cluster-gpl-7.2.15
##編譯
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/tmp/mysql-cluster.sock
-DMYSQL_DATADIR=/data/ndbdata
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DEXTRA_CHARSETS=all
-DWITH_EMBEDDED_SERVER=0
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DWITH_NDBCLUSTER_STORAGE_ENGINE=1
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DMYSQL_USER=mysql
-DWITH_DEBUG=0
-DWITH_SSL=yes
-DWITH_NDB_JAVA=OFF
編譯錯誤後:
清除緩存:rm CMakeCache.txt
從新編譯
安裝 make && make install
3.建立MYSQL用戶
有:
[root@tech2 mysql-5.1.70]# cat /etc/passwd|grep mysql
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
沒有時:
[root@gyf mysql-5.5.30]# groupadd mysql
[root@gyf mysql-5.5.30]# useradd -g mysql mysql
4.複製mysql配置文件my.cnf
cp /soft/mysql-cluster-gpl-7.2.15/support-files/my-large.cnf /etc/my.cnf
5.複製啓動腳本
cp /soft/mysql-cluster-gpl-7.2.15/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
6.配置管理節點
10.10.54.64
//把命令複製到/usr/local/bin/ 的path下
[root@Cent64 mysql]# cd mysql-cluster-gpl-7.2.15-linux2.6-x86_64/bin/
[root@Cent64 bin]# cp ndb_mgm* /usr/local/bin/
//管理節點配置
10.10.54.64
[root@tech03 ndb]# vim /etc/ndb/config.ini
#####################
[NDBD DEFAULT]
NoOfReplicas=2
DataMemory=200M
IndexMemory=20M
[NDB_MGMD]
nodeid=1
hostname=10.10.54.64
datadir=/data/ndb
#數據節點配置
[NDBD]
nodeid=2
hostname=10.10.54.67
datadir=/data/ndb
BackupDataDir=/data/backup
[NDBD]
nodeid=3
hostname=10.10.54.63
datadir=/data/ndb
BackupDataDir=/data/backup
[NDBD]
nodeid=4
hostname=10.10.54.57
datadir=/data/ndb
BackupDataDir=/data/backup
[NDBD]
nodeid=5
hostname=10.10.54.115
datadir=/data/ndb
BackupDataDir=/data/backup
#sql節點配置
[MYSQLD]
nodeid=10
hostname=10.10.54.67
[MYSQLD]
nodeid=11
hostname=10.10.54.63
[MYSQLD]
nodeid=12
hostname=10.10.54.57
[MYSQLD]
nodeid=13
hostname=10.10.54.115
[MYSQLD]
[MYSQLD]
[MYSQLD]
################
7.建立目錄
10.10.54.64/67/63/57/115
//級聯建立數據目錄
mkdir -p /data/ndbdata
chown -R mysql.mysql /data/ndbdata
//建立安裝目錄
mkdir -p /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
//建立備份節點目錄
[root@Cent64 data]# mkdir -p /data/backup
8.修該管理節點配置文件
10.10.54.64
[root@Cent64 data]# vim /etc/my.cnf
datadir = /data/ndb
9.SQL節點配置
10.10.54.67/63/57/115
vim /etc/my.cnf添加:
#在[client]與[mysqld]
[mysql_cluster]
ndb-connectstring=10.10.54.64
[mysqld]
datadir = /data/ndbdata
ndbcluster
ndb-connectstring=10.10.54.64
10.//初始化數據庫
10.10.54.64/67/63/57/115
初始化
[root@CentOS63 mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql
Installing MySQL system tables...
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@CentOS63 mysql]# yum install libaio.x86_64
11.啓動管理節點10.10.54.64
[root@Cent64 ndb]# ndb_mgmd -f /etc/ndb/config.ini --initial
MySQL Cluster Management Server mysql-5.5.35 ndb-7.2.15
12.啓動data節點
10.10.54.67/63/57/115
[root@CentOS63 mysql]# ndbd --initial --ndb-connectstring=10.10.54.64
2014-02-26 11:37:45 [ndbd] INFO -- Angel connected to '10.10.54.64:1186'
2014-02-26 11:37:45 [ndbd] INFO -- Angel allocated nodeid: 3
13.啓動sql節點
/etc/init.d/mysqld start
[root@Cent67 mysql]# ps -ef |grep mysql
[root@Cent67 mysql]# kill -9 2205 2595
14.察看鏈接狀態
[root@Cent64 ndb]# 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 @10.10.54.67 (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0, *)
id=3 @10.10.54.63 (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @10.10.54.64 (mysql-5.5.35 ndb-7.2.15)
[mysqld(API)] 6 node(s)
id=10 @10.10.54.67 (mysql-5.5.35 ndb-7.2.15)
id=11 @10.10.54.63 (mysql-5.5.35 ndb-7.2.15)
//修改密碼
[root@Cent64 ndb]# /usr/local/mysql/bin/mysqladmin -u root password 'aaa12345'
#####驗證NDB集羣
在10.10.54.67上
root@test 19:28>create table aa(a int)engine=ndbcluster;
root@test 19:33>show tables;
+----------------+
| Tables_in_test |
+----------------+
| aa |
+----------------+
在10.10.54.63自動有
root@test 19:34>show tables;
+----------------+
| Tables_in_test |
+----------------+
| aa |
+----------------+linux