MySQL Cluster單機搭建叢集環境
阿新 • • 發佈:2019-02-18
執行環境:
centos6.1
Mysql版本:
2. 切換到mysql使用者許可權下
[plain] view plaincopyprint?
3. 下載mysql cluster
[plain] view plaincopyprint?
4. 安裝mysql cluster
[plain] view plaincopyprint?
5. 執行
6. 測試
7. 停止服務
centos6.1
Mysql版本:
mysql-cluster-gpl-7.2.6-linux2.6-x86_6
對於這第一個MySQL資料庫的叢集,它由1個單一的MySQL服務引擎(mysqlds)、兩個資料節點(ndbd)和一個單一的管理節點(ndb_mgmd)共同組成,所有的節點都執行在同一臺主機上。
為配置檔案和資料檔案建立必要的儲存資料夾,分別要建立如下幾個資料夾:
① /home/mysql/my_cluster
② /home/mysql/my_cluster/ndb_data
③ /home/mysql/my_cluster/mysqld_data
④ /home/mysql/my_cluster/mysqld_data/mysql
⑤ /home/mysql/my_cluster/mysqld_data/ndbinfo
⑥ /home/mysql/my_cluster/conf
具體安裝步驟:
1. 添用加戶與組mysql
- shell> groupadd mysql
- shell> useradd -r -d /home/mysql -g mysql mysql
shell> groupadd mysql
shell> useradd -r -d /home/mysql -g mysql mysql
2. 切換到mysql使用者許可權下
[plain] view plaincopyprint?
- shell> su - mysql
shell> su - mysql
3. 下載mysql cluster
[plain] view plaincopyprint?
- shell> wget http://cdn.mysql.com/Downloads/MySQL-Cluster-7.2/mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz
- shell> tar -zxvf mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz
- shell> ln -s mysql-cluster-gpl-7.2.6-linux2.6-x86_64 mysqlc
shell> wget http://cdn.mysql.com/Downloads/MySQL-Cluster-7.2/mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz shell> tar -zxvf mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz shell> ln -s mysql-cluster-gpl-7.2.6-linux2.6-x86_64 mysqlc
4. 安裝mysql cluster
[plain] view plaincopyprint?
- shell> cd /home/mysql
- shell> mkdir my_cluster my_cluster/ndb_data my_cluster/mysqld_data my_cluster/conf
- 在conf目錄新增以下2個配置檔案(注意:“/home/mysql”需要替換為你自己的使用者目錄)
- my.cnf:
- [mysqld]
- ndbcluster
- datadir=/home/mysql/my_cluster/mysqld_data
- basedir=/home/mysql/mysqlc
- port=5000
- config.ini:
- [ndb_mgmd]
- hostname=localhost
- datadir=/home/mysql/my_cluster/ndb_data
- NodeId=1
- [ndbd default]
- noofreplicas=2
- datadir=/home/mysql/my_cluster/ndb_data
- [ndbd]
- hostname=localhost
- NodeId=3
- [ndbd]
- hostname=localhost
- NodeId=4
- [mysqld]
- NodeId=50
- 安裝
- shell> cd /home/mysql/mysqlc
- shell> scripts/mysql_install_db --no-defaults --datadir=/home/mysql/my_cluster/mysqld_data/
shell> cd /home/mysql
shell> mkdir my_cluster my_cluster/ndb_data my_cluster/mysqld_data my_cluster/conf
在conf目錄新增以下2個配置檔案(注意:“/home/mysql”需要替換為你自己的使用者目錄)
my.cnf:
[mysqld]
ndbcluster
datadir=/home/mysql/my_cluster/mysqld_data
basedir=/home/mysql/mysqlc
port=5000
config.ini:
[ndb_mgmd]
hostname=localhost
datadir=/home/mysql/my_cluster/ndb_data
NodeId=1
[ndbd default]
noofreplicas=2
datadir=/home/mysql/my_cluster/ndb_data
[ndbd]
hostname=localhost
NodeId=3
[ndbd]
hostname=localhost
NodeId=4
[mysqld]
NodeId=50
安裝
shell> cd /home/mysql/mysqlc
shell> scripts/mysql_install_db --no-defaults --datadir=/home/mysql/my_cluster/mysqld_data/
5. 執行
程序需要啟動management node, data nodes 與 MySQL Server
- shell> cd ../my_cluster/
- ① 最先啟動的是管理節點(ndb_mgmd)
- shell> /home/mysql/mysqlc/bin/ndb_mgmd -f conf/config.ini --initial --configdir=/home/mysql/my_cluster/conf/
- ② 啟動第一個資料節點(ndbd)
- shell> /home/mysql/mysqlc/bin/ndbd -c localhost:1186
- ③ 啟動第二個資料節點(ndbd)
- shell> /home/mysql/mysqlc/bin/ndbd -c localhost:1186
- 在啟動MySQL服務引擎(mysqld)之前,一定要等到所有的資料節點全部啟動完畢,然後才能啟動MySQL服務引擎。檢視資料節點是否啟動完畢的命令語句如下:
- shell> /home/mysql/mysqlc/bin/ndb_mgm -e show
- 顯示結果:
- Connected to Management Server at: localhost:1186
- Cluster Configuration
- ---------------------
- [ndbd(NDB)] 2 node(s)
- id=3 @127.0.0.1 (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0, Master)
- id=4 @127.0.0.1 (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0)
- [ndb_mgmd(MGM)] 1 node(s)
- id=1 @127.0.0.1 (mysql-5.5.22 ndb-7.2.6)
- [mysqld(API)] 1 node(s)
- id=50 (not connected, accepting connect from any host)
- ④ 啟動MySQL服務引擎
- shell> /home/mysql/mysqlc/bin/mysqld --defaults-file=conf/my.cnf &
shell> cd ../my_cluster/
① 最先啟動的是管理節點(ndb_mgmd)
shell> /home/mysql/mysqlc/bin/ndb_mgmd -f conf/config.ini --initial --configdir=/home/mysql/my_cluster/conf/
② 啟動第一個資料節點(ndbd)
shell> /home/mysql/mysqlc/bin/ndbd -c localhost:1186
③ 啟動第二個資料節點(ndbd)
shell> /home/mysql/mysqlc/bin/ndbd -c localhost:1186
在啟動MySQL服務引擎(mysqld)之前,一定要等到所有的資料節點全部啟動完畢,然後才能啟動MySQL服務引擎。檢視資料節點是否啟動完畢的命令語句如下:
shell> /home/mysql/mysqlc/bin/ndb_mgm -e show
顯示結果:
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=3 @127.0.0.1 (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0, Master)
id=4 @127.0.0.1 (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @127.0.0.1 (mysql-5.5.22 ndb-7.2.6)
[mysqld(API)] 1 node(s)
id=50 (not connected, accepting connect from any host)
④ 啟動MySQL服務引擎
shell> /home/mysql/mysqlc/bin/mysqld --defaults-file=conf/my.cnf &
啟動成功後的程序如下:
[plain] view plaincopyprint?- mysql 1738 0.1 0.5 575408 5752 ? Ssl 00:58 0:14 /home/mysql/mysqlc/bin/ndb_mgmd -f conf/config.ini --initial --configdir=/home/mysql/my_cluster/conf/
- mysql 1751 0.0 0.0 101116 660 ? Ss 00:58 0:00 /home/mysql/mysqlc/bin/ndbd -c localhost:1186
- mysql 1752 0.3 31.5 1048328 320704 ? Sl 00:58 0:41 /home/mysql/mysqlc/bin/ndbd -c localhost:1186
- mysql 1790 0.0 0.0 101116 708 ? Ss 00:58 0:00 /home/mysql/mysqlc/bin/ndbd -c localhost:1186
- mysql 1791 0.3 40.9 1048328 417228 ? Sl 00:58 0:38 /home/mysql/mysqlc/bin/ndbd -c localhost:1186
- mysql 1835 0.0 5.4 886712 55296 pts/0 Sl 00:59 0:11 /home/mysql/mysqlc/bin/mysqld --defaults-file=conf/my.cnf
- mysql 1897 0.0 0.1 198204 2032 pts/1 S+ 01:00 0:00 /home/mysql/mysqlc/bin/mysql -h 127.0.0.1 -P 5000 -u root
mysql 1738 0.1 0.5 575408 5752 ? Ssl 00:58 0:14 /home/mysql/mysqlc/bin/ndb_mgmd -f conf/config.ini --initial --configdir=/home/mysql/my_cluster/conf/
mysql 1751 0.0 0.0 101116 660 ? Ss 00:58 0:00 /home/mysql/mysqlc/bin/ndbd -c localhost:1186
mysql 1752 0.3 31.5 1048328 320704 ? Sl 00:58 0:41 /home/mysql/mysqlc/bin/ndbd -c localhost:1186
mysql 1790 0.0 0.0 101116 708 ? Ss 00:58 0:00 /home/mysql/mysqlc/bin/ndbd -c localhost:1186
mysql 1791 0.3 40.9 1048328 417228 ? Sl 00:58 0:38 /home/mysql/mysqlc/bin/ndbd -c localhost:1186
mysql 1835 0.0 5.4 886712 55296 pts/0 Sl 00:59 0:11 /home/mysql/mysqlc/bin/mysqld --defaults-file=conf/my.cnf
mysql 1897 0.0 0.1 198204 2032 pts/1 S+ 01:00 0:00 /home/mysql/mysqlc/bin/mysql -h 127.0.0.1 -P 5000 -u root
6. 測試
連線到MySQL伺服器,並確認使用MySQL叢集(NDB)可以建立表① 連線到MySQL伺服器:
[plain] view plaincopyprint?- shell> /home/mysql/mysqlc/bin/mysql -h 127.0.0.1 -P 5000 -u root
- mysql> create database clusterdb;use clusterdb;
- mysql> create table simples (id int not null primary key) engine=ndb;
- mysql> insert into simples values (1),(2),(3),(4);
- mysql> select * from simples;
- +----+
- | id |
- +----+
- | 3 |
- | 1 |
- | 2 |
- | 4 |
- +----+
shell> /home/mysql/mysqlc/bin/mysql -h 127.0.0.1 -P 5000 -u root
mysql> create database clusterdb;use clusterdb;
mysql> create table simples (id int not null primary key) engine=ndb;
mysql> insert into simples values (1),(2),(3),(4);
mysql> select * from simples;
+----+
| id |
+----+
| 3 |
| 1 |
| 2 |
| 4 |
+----+
7. 停止服務
MySQL服務必須手動停止,服務停止後,其他叢集節點的停止可以使用管理節點(ndb_mgm)來
- shell> /home/mysql/mysqlc/bin/mysqladmin -u root -h 127.0.0.1 -P 5000 shutdown
- shell> /home/mysql/mysqlc/bin/ndb_mgm -e shutdown
shell> /home/mysql/mysqlc/bin/mysqladmin -u root -h 127.0.0.1 -P 5000 shutdown
shell> /home/mysql/mysqlc/bin/ndb_mgm -e shutdown