原始碼方式安裝mysql cluster 7.3.3

denglt發表於2014-02-12

MySql叢集安裝
1 環境介紹
IP地址              節點型別        描述                         備註
172.16.110.136 Mgmt Node     Master管理節點 
172.16.110.133 SQL Node       SQL節點                   一號SQL Node
172.16.110.134 SQL Node      SQL節點                    二號SQL Node
172.16.110.131 Data Node     資料節點 
172.16.110.132 Data Node     資料節點 


2 安裝軟體
採用原始碼安裝方式
1. mysql安裝包:mysql-cluster-gpl-7.3.3.tar.gz
Mysql 下載地址:http://dev.mysql.com/downloads/
2.  Cmake安裝包
mysql5.5以後是通過cmake來編譯的
wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
 
3.  Jdk安裝包:
jdk-6u45-linux-x64-rpm.bin
編譯msyql custer開啟WITH_NDB_JAVA,需要安裝jdk1.6以上版本

3 安裝一號SQL Node

在SQL Node節點172.16.110.133執行如下步驟
3.1 安裝cmake
[root@study1 software]# tar -zxvf cmake-2.8.4.tar.gz
[root@study1 software]# cd cmake-2.8.4
[root@study1 cmake-2.8.4]# ./configure
[root@study1 cmake-2.8.4]# make
[root@study1 cmake-2.8.4]# make install
3.2 安裝jdk
刪除舊的jdk
[root@laodeng3 software]# rpm -qa| grep gcj
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
libgcj-devel-4.1.2-50.el5
libgcj-devel-4.1.2-50.el5
java-1.4.2-gcj-compat-devel-1.4.2.0-40jpp.115
libgcj-4.1.2-50.el5
libgcj-src-4.1.2-50.el5
java-1.4.2-gcj-compat-src-1.4.2.0-40jpp.115
libgcj-4.1.2-50.el5
java-1.4.2-gcj-compat-devel-1.4.2.0-40jpp.115
[root@laodeng3 software]# rpm -e –nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
[root@laodeng3 software]# rpm -e --nodeps --allmatches java-1.4.2-gcj-compat-devel-1.4.2.0-40jpp.115

安裝1.6jdk
[root@laodeng3 software]# chmod +x jdk-6u45-linux-x64-rpm.bin
[root@laodeng3 software]# ./jdk-6u45-linux-x64-rpm.bin
[root@laodeng3 software]# rpm -ivh jdk-6u45-linux-amd64.rpm
[root@laodeng3 software]# ln -s  /usr/java/jdk1.6.0_45/bin/java  /usr/bin/java


3.3 建立mysql軟體存放目錄
[root@laodeng3 software]# mkdir /opt/mysql

3.4 編譯安裝mysql
[root@laodeng3 software]# tar -xzvf mysql-cluster-gpl-7.3.3.tar.gz
[root@laodeng3 software]# cd mysql-cluster-gpl-7.3.3
[root@laodeng3 software]# JAVA_HOME=/usr/java/jdk1.6.0_45
[root@laodeng3 software]# export JAVA_HOME
[root@laodeng3 software]# cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql \
 -DSYSCONFDIR=/opt/mysql/etc \
 -DMYSQL_DATADIR=/opt/mysql/data \
 -DMYSQL_TCP_PORT=3306 \
 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
 -DWITH_EXTRA_CHARSETS=all \
 -DWITH_SSL=bundled  \
 -DWITH_EMBEDDED_SERVER=1  \
 -DENABLED_LOCAL_INFILE=1  \
 -DWITH_INNOBASE_STORAGE_ENGINE=1  \
 -DDEFAULT_CHARSET=utf8  \
 -DDEFAULT_COLLATION=utf8_general_ci  \
 -DWITH_NDB_JAVA=1  \
 -DWITH_NDBCLUSTER_STORAGE_ENGINE=1  \
 -DWITH_CLASSPATH=/usr/java/jdk1.6.0_45/lib

[root@laodeng3 software]# make
[root@laodeng3 software]# make install


3.5 建立使用者修改檔案屬性
groupadd mysql
useradd -m -r -g mysql mysql
[root@laodeng3 /]# cd /opt/mysql
[root@laodeng3 mysql]# mkdir etc
[root@laodeng3 mysql]# chown -R mysql .
[root@laodeng3 mysql]# chgrp -R mysql .

3.6 初始化資料庫
[root@laodeng3 mysql]# scripts/mysql_install_db --user=mysql --basedir=/opt/mysql/ --datadir=/opt/mysql/data/
[root@laodeng3 mysql]# chown -R root .
[root@laodeng3 mysql]# chown -R mysql data

3.7 配置資料庫
修改密碼:
[root@laodeng3 mysql]# bin/mysqladmin -u root password 'mysql'


[root@laodeng3 mysql]# cp support-files/mysql.server /etc/init.d/
[root@laodeng3 mysql]# cp support-files/my-default.cnf  etc/my.cnf

編輯etc/my.cnf,zai [mysqld]下增加lower_case_table_names=1
設定環境變數:
在/etc/profile檔案最後增加:
PATH=/opt/mysql/bin:/opt/mysql/lib:$PATH
export PATH


3.8 檢視ndb資料引擎
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ndbcluster         | NO      | Clustered, fault-tolerant tables                               | NULL         | NULL | NULL       |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| ndbinfo            | YES     | MySQL Cluster system information storage engine                | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------
4 安裝二號SQL Node

4.1 打包一號SQL Node
先關閉mysql
[root@laodeng3 /]# service mysql.server stop
Shutting down MySQL..... SUCCESS!

是同tar命令打包
[root@laodeng3 /]# cd /opt
[root@laodeng3 opt]# tar -czvf mysql.tar mysql/

4.2 建立使用者
groupadd mysql
useradd -m -r -g mysql mysql

4.3 解壓mysql.tar包

[root@laodeng4 opt]# tar -xzvf mysql.tar

4.4 配置資料庫
[root@laodeng4 mysql]# cp support-files/mysql.server /etc/init.d/

設定環境變數:
在/etc/profile檔案最後增加:
PATH=/opt/mysql/bin:/opt/mysql/lib:$PATH
export PATH

5 Mgmt Node安裝

5.1 建立目錄
[root@laodeng5 ~]# mkdir /opt/mysql
[root@laodeng5 ~]# mkdir /opt/mysql/bin
[root@laodeng5 ~]# mkdir /opt/mysql/etc
[root@laodeng5 ~]# mkdir /opt/mysql/mysql-cluster
[root@laodeng5 ~]# mkdir /opt/mysql/log

/opt/mysql/etc為配置檔案目錄
/opt/mysql/mysql-cluster為預設存放Configuration cache files的目錄,可以使用 --configdir引數在啟動時指定其他目錄
5.2 拷貝ndb_mgmd和ndb_mgm檔案
拷貝一號SQL Node的/opt/mysql/bin/ndb_mgmd和ndb_mgm檔案到/opt/mysql/bin

5.3 設定環境變數:
在/etc/profile檔案最後增加:
PATH=/opt/mysql/bin:/opt/mysql/lib:$PATH
export PATH

6 Data Node安裝

在兩個資料節點分別執行下面的步驟
6.1 建立目錄
[root@laodeng2 ~]# mkdir /opt/mysql
[root@laodeng2 ~]# mkdir /opt/mysql/bin
[root@laodeng2 ~]# mkdir /opt/mysql/etc
6.2 拷貝ndbd和ndbmtd檔案
拷貝一號SQL Node的/opt/mysql/bin/ndbd和ndbmtd檔案到/opt/mysql/bin

6.3 設定環境變數:
在/etc/profile檔案最後增加:
PATH=/opt/mysql/bin:/opt/mysql/lib:$PATH
export PATH
7 MySQL Cluster初始化配置
7.1 配置Data Node和SQL Node
在Data Node 和SQL Node分別進行如下配置:
vi /opt/mysql/ect/my.cnf
增加如下配置:
[mysqld]
ndbcluster  #run NDB storage engine

[mysql_cluster]
ndb-connectstring=172.16.110.136  #location of management server

7.2 配置管理節點
vi /opt/mysql/etc/config.cnf
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=1    # Number of replicas
DataMemory=80M    # How much memory to allocate for data storage
IndexMemory=18M   # How much memory to allocate for index storage
                  # For DataMemory and IndexMemory, we have used the
                  # default values. Since the "world" database takes up
                  # only about 500KB, this should be more than enough for
                  # this example Cluster setup.

[tcp default]
# TCP/IP options:
portnumber=2202   # This the default; however, you can use any
                  # port that is free for all the hosts in the cluster
                  # Note: It is recommended that you do not specify the port
                  # number at all and simply allow the default value to be used
                  # instead

[ndb_mgmd]
# Management process options:
Nodeid=1
hostname=172.16.110.136           # Hostname or IP address of MGM node
datadir=/opt/mysql/log            # Directory for MGM node log files

[ndbd]
# Options for data node "A":
                                  # (one [ndbd] section per data node)
hostname=172.16.110.131           # Hostname or IP address
datadir=/data/mysql_ndb           # Directory for this data node's data files

[ndbd]
# Options for data node "B":
hostname=172.16.110.132           # Hostname or IP address
datadir=/data/mysql_ndb     # Directory for this data node's data files

[mysqld]
# SQL node options:
hostname=172.16.110.133         # Hostname or IP address
                                # (additional mysqld connections can be
                                # specified for this node for various
                                # purposes such as running ndb_restore)
                               
[mysqld]      
hostname=172.16.110.134   


8 MySQL Cluster啟動
 Each cluster node process must be started separately, and on the host where it resides. The management node should be started first, followed by the data nodes, and then finally by any SQL nodes:

8.1 啟動管理節點
[root@laodeng5 /]# ndb_mgmd -f /opt/mysql/etc/config.ini
MySQL Cluster Management Server mysql-5.6.14 ndb-7.3.3
2014-02-12 11:05:37 [MgmtSrvr] WARNING  -- at line 13: [tcp] portnumber is deprecated

注意:在ndb_mgmd命令帶如下引數: --initial、 --reload 、 --config-cache和沒有找到如何快取的配置時,會重新讀取全域性配置檔案config.ini,否則使用快取的配置資料,快取的配置資料儲存在/opt/mysql/ /mysql-cluster目錄下。

使用ndb_mgm工具(ndb_mgmd(MySQL Cluster Server)的客戶端管理工具)管理ndb_mgmd。
[root@laodeng5 /]# 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 (not connected, accepting connect from 172.16.110.131)
id=3 (not connected, accepting connect from 172.16.110.132)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.16.110.136  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 172.16.110.133)
id=5 (not connected, accepting connect from 172.16.110.134)


8.2 啟動Data Node
在每個Data Node的主機,執行如下命令啟動ndbd程式:
[root@laodeng1 ~]# ndbd
2014-02-12 14:45:16 [ndbd] INFO     -- Angel connected to '172.16.110.136:1186'
2014-02-12 14:45:16 [ndbd] INFO     -- Angel allocated nodeid: 2

[root@laodeng2 ~]# ndbd
2014-02-12 14:45:46 [ndbd] INFO     -- Angel connected to '172.16.110.136:1186'
2014-02-12 14:45:46 [ndbd] INFO     -- Angel allocated nodeid: 3

8.3 啟動SQL Node
在每個SQL Node的主機,執行service mysql.server start啟動mysql資料庫。


8.4 驗證MySQL Cluster
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @172.16.110.131  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)
id=3    @172.16.110.132  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 1)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.16.110.136  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @172.16.110.133  (mysql-5.6.14 ndb-7.3.3)
id=5    @172.16.110.134  (mysql-5.6.14 ndb-7.3.3)

9 MySQL Cluster測試
在一號SQL Node節點執行如下操作:
[root@laodeng3 ~]# mysql -uroot –p
mysql> create database ndb;
Query OK, 1 row affected (0.07 sec)

mysql> use ndb;
Database changed

mysql>  create table t1 (id int not null primary key ,name varchar(100)) engine=ndb;
Query OK, 0 rows affected (0.16 sec)


mysql> insert into t1 values(1,'denglt');
Query OK, 1 row affected (0.01 sec)

mysql> insert into t1 values(2,'denglt');
Query OK, 1 row affected (0.00 sec)

在二號SQL Node節點進行資料查詢:
[root@laodeng4 ndb]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.6.14-ndb-7.3.3 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select * from ndb.t1;
+----+--------+
| id | name   |
+----+--------+
|  1 | denglt |
|  2 | denglt |
+----+--------+
2 rows in set (0.00 sec)

Ok.測試正常,MySQL Cluster搭建成功。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/195110/viewspace-1080360/,如需轉載,請註明出處,否則將追究法律責任。

相關文章