1.從mysql 5.1 以後 mysql安裝包裏就不包含mysql cluster ,而是單獨作爲一個產品發佈,目前mysql網站上最新的版本是mysql cluster 7.2.7。
下載地址:http://www.mysql.com/downloads/cluster/#downloads
2.建立有5個節點的MySQL CLuster體系 ( OS : REDHAT 6.1 )
管理節點(MGM) 192.168.251.141
SQL節點1(SQL1) 192.168.251.141
SQL節點2(SQL2) 192.168.251.141
數據節點1(NDBD1) 192.168.251.141
數據節點2(NDBD2) 192.168.251.141
3.首先去下載文件 mysql-cluster-gpl-7.2.7-linux2.6-x86_64.tar.gz
4.解壓文件到/mysqlData/ 並 重命名爲 mysql-cluster
[root@dbcp-db01 mysqlData]# pwd
/mysqlData
[root@dbcp-db01 mysqlData]# ls
mysql-cluster-gpl-7.2.7-linux2.6-x86_64.tar.gz mysql-cluster
5.建立軟連
ln -s /mysqlData/mysql-cluster/ /usr/local/mysql
6.在/etc/profile 加入 export PATH=$PATH:/usr/local/mysql/bin
echo “export PATH=$PATH:/usr/local/mysql/bin” >> /etc/profile
source /etc/profile
7.配置管理節點
[root@dbcp-db01 config]# vi /data/config/mysqlcluster.ini
[NDBD DEFAULT]
NoOfReplicas=1
[TCP DEFAULT]
portnumber=3388
#
[NDB_MGMD]
NodeId = 1
hostname=192.168.251.141
#
datadir=/mysqlData/clustermgmd-data/
#
[NDBD]
NodeId = 2
hostname=192.168.251.141
datadir=/mysqlData/clusterndb1-data/
#
[NDBD]
NodeId = 3
hostname=192.168.251.141
datadir=/mysqlData/clusterndb2-data/
#
[MYSQLD]
NodeId = 4
hostname=192.168.251.141
#
[MYSQLD]
NodeId = 5
hostname=192.168.251.141
[MYSQLD]
8.配置存儲節點和SQL節點(配置兩個cnf 配置不同的參數路徑)
[root@dbcp-db01 config]# vi /data/config/my-node4.cnf
[mysqld]
ndbcluster
basedir=/mysqlData/mysql-cluster
datadir=/mysqlData/clusterndb1-data/
socket=/data/socket/my-n1.sock
pid-file=/data/socket/n1.pid
log-error = /mysqlLog/n1_err.log
slow_query_log_file = /mysqlLog/n1_slow.log
port = 3399
ndb-connectstring=192.168.251.141
[mysql_cluster]
ndb-connectstring=192.168.251.141
[root@dbcp-db01 config]# vi /data/config/my-node5.cnf
[mysqld]
ndbcluster
basedir=/mysqlData/mysql-cluster
datadir=/mysqlData/clusterndb2-data/
socket=/data/socket/my-n2.sock
pid-file=/data/socket/n2.pid
log-error = /mysqlLog/n2_err.log
slow_query_log_file = /mysqlLog/n2_slow.log
port = 3398
ndb-connectstring=192.168.251.141
[mysql_cluster]
ndb-connectstring=192.168.251.141
9.建立mysql用戶組和mysql用戶
groupadd mysql
useradd -g mysql mysql
10.創建配置文件中所用到的目錄
mkdir -p /mysqlData/clusterndb2-data/
mkdir -p /mysqlData/clusterndb1-data/
mkdir -p /data/socket/
mkdir -p /mysqlLog/
mkdir -p /mysqlData/clustermgmd-data/
11.更改相關目錄的權限
chown -R mysql.mysql /mysqlData/
chown -R mysql.mysql /mysqlLog/
12.初始化SQL節點
[root@dbcp-db01 ~]# cd /usr/local/mysql/scripts/
[root@dbcp-db01 scripts]# ./mysql_install_db --defaults-file=/data/config/my-node4.cnf --datadir=/mysqlData/clusterndb1-data/ --user=mysql --basedir=/mysqlData/mysql-cluster/ &
[1] 24447
[root@dbcp-db01 scripts]# Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/mysqlData/mysql-cluster//bin/mysqladmin -u root password 'new-password'
/mysqlData/mysql-cluster//bin/mysqladmin -u root -h dbcp-db01 password 'new-password'
Alternatively you can run:
/mysqlData/mysql-cluster//bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /mysqlData/mysql-cluster/ ; /mysqlData/mysql-cluster//bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /mysqlData/mysql-cluster//mysql-test ; perl mysql-test-run.pl
Please report any problems with the /mysqlData/mysql-cluster//scripts/mysqlbug script!
[root@dbcp-db01 ~]# cd /usr/local/mysql/scripts/
[root@dbcp-db01 scripts]# ./mysql_install_db --defaults-file=/data/config/my-node5.cnf --datadir=/mysqlData/clusterndb1-data/ --user=mysql --basedir=/mysqlData/mysql-cluster/ &
[1] 24508
[root@dbcp-db01 scripts]# Installing MySQL system tables...
OK
Filling help tables...
OK
.
.
.....
13.啓動mysql-cluster,啓動順序爲 管理節點->存儲節點->SQL節點
A. 啓動管理節點
[root@dbcp-db01 ~]# ndb_mgmd -f /data/config/mysqlcluster.ini
MySQL Cluster Management Server mysql-5.5.25 ndb-7.2.7
[root@dbcp-db01 ~]#
B. 啓動存儲節點
[root@dbcp-db01 scripts]# /usr/local/mysql/bin/ndbd --defaults-file=/data/config/my-node4.cnf --initial
2012-08-10 11:25:13 [ndbd] INFO -- Angel connected to '192.168.251.141:1186'
2012-08-10 11:25:13 [ndbd] INFO -- Angel allocated nodeid: 2
[root@dbcp-db01 scripts]# /usr/local/mysql/bin/ndbd --defaults-file=/data/config/my-node5.cnf --initial
2012-08-10 11:25:25 [ndbd] INFO -- Angel connected to '192.168.251.141:1186'
2012-08-10 11:25:25 [ndbd] INFO -- Angel allocated nodeid: 3
[root@dbcp-db01 scripts]#
C. 啓動SQL節點
[root@dbcp-db01 scripts]# mysqld_safe --defaults-file=/data/config/my-node4.cnf --user=mysql &
[1] 24649
[root@dbcp-db01 scripts]# 120810 11:26:41 mysqld_safe Logging to '/mysqlLog/n1_err.log'.
120810 11:26:41 mysqld_safe Starting mysqld daemon with databases from /mysqlData/clusterndb1-data/
[root@dbcp-db01 scripts]# ps aux | grep mysqld
root 24649 0.1 0.0 106012 1316 pts/1 S 11:26 0:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/config/my-node4.cnf --user=mysql
mysql 24732 1.2 2.2 953944 46772 pts/1 Sl 11:26 0:00 /usr/libexec/mysqld --defaults-file=/data/config/my-node4.cnf --basedir=/mysqlData/mysql-cluster
--datadir=/mysqlData/clusterndb1-data/ --user=mysql --log-error=/mysqlLog/n1_err.log --pid-file=/data/socket/n1.pid --socket=/data/socket/my-n1.sock --port=3399
root 24760 0.0 0.0 103152 796 pts/1 S+ 11:27 0:00 grep mysqld
[root@dbcp-db01 scripts]# mysqld_safe --defaults-file=/data/config/my-node5.cnf --user=mysql &
[2] 24761
[root@dbcp-db01 scripts]# 120810 11:27:18 mysqld_safe Logging to '/mysqlLog/n2_err.log'.
120810 11:27:18 mysqld_safe Starting mysqld daemon with databases from /mysqlData/clusterndb2-data/
[root@dbcp-db01 scripts]# ps aux | grep mysqld
root 24649 0.0 0.0 106012 1316 pts/1 S 11:26 0:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/config/my-node4.cnf --user=mysql
mysql 24732 0.8 2.2 953944 47184 pts/1 Sl 11:26 0:00 /usr/libexec/mysqld --defaults-file=/data/config/my-node4.cnf --basedir=/mysqlData/mysql-cluster
--datadir=/mysqlData/clusterndb1-data/ --user=mysql --log-error=/mysqlLog/n1_err.log --pid-file=/data/socket/n1.pid --socket=/data/socket/my-n1.sock --port=3399
root 24761 0.2 0.0 106012 1320 pts/1 S 11:27 0:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/config/my-node5.cnf --user=mysql
mysql 24844 2.6 2.2 953944 46932 pts/1 Sl 11:27 0:00 /usr/libexec/mysqld --defaults-file=/data/config/my-node5.cnf --basedir=/mysqlData/mysql-cluster
--datadir=/mysqlData/clusterndb2-data/ --user=mysql --log-error=/mysqlLog/n2_err.log --pid-file=/data/socket/n2.pid --socket=/data/socket/my-n2.sock --port=3398
root 24873 0.0 0.0 103152 796 pts/1 S+ 11:27 0:00 grep mysqld
[root@dbcp-db01 scripts]#
14.所有節點都啓動了 用 ndb_mgm 查看
[root@dbcp-db01 ~]# 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 @192.168.251.141 (mysql-5.5.25 ndb-7.2.7, Nodegroup: 0, Master)
id=3 @192.168.251.141 (mysql-5.5.25 ndb-7.2.7, Nodegroup: 1)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.251.141 (mysql-5.5.25 ndb-7.2.7)
[mysqld(API)] 2 node(s)
id=4 @192.168.251.141 (mysql-5.5.25 ndb-7.2.7)
id=5 @192.168.251.141 (mysql-5.5.25 ndb-7.2.7)
ndb_mgm>
15.在SQL節點端口3399上 創建數據庫,表,插入數據
[root@dbcp-db01 config]# mysql -uroot -p -S /data/socket/my-n1.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.25a-ndb-7.2.7-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database cluster_one;
Query OK, 1 row affected (0.12 sec)
mysql> use cluster_one
Database changed
mysql> create table c_tb_a (id int ,tname varchar(10)) engine = ndbcluster default charset utf8;
Query OK, 0 rows affected (0.25 sec)
mysql> insert into c_tb_a values (1,'qqqqqq');
Query OK, 1 row affected (0.01 sec)
mysql> insert into c_tb_a values (2,'dddddd');
Query OK, 1 row affected (0.00 sec)
mysql>
16.在SQL節點端口3398 上查詢數據
[root@dbcp-db01 config]# mysql -uroot -p -S /data/socket/my-n2.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.25a-ndb-7.2.7-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cluster_one |
| mysql |
| ndb_3_fs |
| ndbinfo |
| performance_schema |
| test |
+--------------------+
7 rows in set (0.04 sec)
mysql> use cluster_one
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_cluster_one |
+-----------------------+
| c_tb_a |
+-----------------------+
1 row in set (0.00 sec)
mysql> select * from c_tb_a;
+------+--------+
| id | tname |
+------+--------+
| 1 | qqqqqq |
| 2 | dddddd |
+------+--------+
2 rows in set (0.00 sec)
mysql>
以上就是在一臺計算機上安裝配置mysql cluster 的過程,其實跟在多臺機器上配置差不多,只是在配置cnf的時候要用不同的路徑,要注意的是在初始化的時候把--defaults-file --datadir --basedir 幾個參數加上。
請多多關照。
配置mysql cluster
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.