ITPub博客

首页 > 数据库 > MySQL > 源码方式安装mysql cluster 7.3.3

源码方式安装mysql cluster 7.3.3

原创 MySQL 作者:denglt 时间:2014-02-12 16:57:25 0 删除 编辑

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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-11-04

  • 博文量
    118
  • 访问量
    704014