mysql cluster 7.1搭建
简单步骤,分享下: hostnameIP应用 db1192.168.50.10MGM db2192.168.50.20NDBD db3192.168.50.30NDBD2 db4192.168.50.40MYSQLD db5192.168.50.50MYSQLD ***************************** 1.安装配置管理节点(DB1)MGM ***************************** # groupad
简单步骤,分享下:
hostname IP 应用
db1 192.168.50.10 MGM
db2 192.168.50.20 NDBD
db3 192.168.50.30 NDBD2
db4 192.168.50.40 MYSQLD
db5 192.168.50.50 MYSQLD
*****************************
1.安装配置管理节点(DB1)MGM
*****************************
# groupadd mysql
# useradd -g mysql -d /usr/local/mysql/var -M mysql
# tar zxvf mysql-cluster-gpl-7.1.8.tar.gz
# cd mysql-cluster-gpl-7.1.8
# ./configure --prefix=/usr/local/mysql/ --with-charset=utf8 --with-collation=utf8_general_ci \
--with-client-ldflags=-all-static -with-mysqld-ldflags=-all-static --enable-assembler \
--with-extra-charsets=complex --enable-thread-safe-client --with-big-tables \
--with-readline --with-ssl --with-embedded-server --enable-local-infile \
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \
--sysconfdir=/usr/local/mysql/etc --without-debug --with-mysqld-user=mysql --with-plugins=max
# make
# make install
# cd /usr/local/mysql
# mkdir mysql-cluster
# cd mysql-cluster
# vi config.ini
[NDBD DEFAULT]
NoOfReplicas= 2
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
DataDir= /usr/local/mysql/mysql-cluster
[NDB_MGMD]
HostName= 192.168.50.10
[NDBD]
HostName= 192.168.50.20
DataDir= /usr/local/mysql/mysql-cluster
[NDBD]
HostName= 192.168.50.30
DataDir= /usr/local/mysql/mysql-cluster
[MYSQLD]
HostName= 192.168.50.40
[MYSQLD]
HostName= 192.168.50.50
----------启动cluster管理节点
在管理节点服务器上,执行以下命令启动MGM节点进程:
root# /usr/local/mysql/ndb_mgmd -f /usr/local/mysql/config.ini
必须用参数“-f”或“--config-file”告诉 ndb_mgm 配置文件所在位置,默认是在ndb_mgmd相同目录下。
------------------
# /usr/local/mysql/libexec/ndb_mgmd -f /usr/local/mysql/mysql-cluster/config.ini
# /usr/local/mysql/bin/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 192.168.50.20)
id=3 (not connected, accepting connect from 192.168.50.30)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.50.10 (mysql-5.1.47 ndb-7.1.8)
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from 192.168.50.40)
id=5 (not connected, accepting connect from 192.168.50.50)
可以看到ndb_mgmd 是 连上的,nbd 和 mysqld 还没有连上~
****************************************
2.安装配置在两个数据节点(DB2,DB3)ndbd
****************************************
# groupadd mysql
# useradd -g mysql -d /usr/local/mysql/var -M mysql
# tar xvzf mysql-cluster-gpl-7.1.8.tar.gz
# cd mysql-cluster-gpl-7.1.8
# ./configure --prefix=/usr/local/mysql/ --with-charset=utf8 --with-collation=utf8_general_ci \
--with-client-ldflags=-all-static -with-mysqld-ldflags=-all-static --enable-assembler \
--with-extra-charsets=complex --enable-thread-safe-client --with-big-tables \
--with-readline --with-ssl --with-embedded-server --enable-local-infile \
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \
--sysconfdir=/usr/local/mysql/etc --without-debug --with-mysqld-user=mysql --with-plugins=max
# make
# make install
# cd /usr/local/mysql
# mkdir mysql-cluster etc
# chown root:mysql . -R
# vi /usr/local/mysql/etc/my.cnf
[mysqld]
ndbcluster
ndb-connectstring=192.168.50.10
[mysql_cluster]
ndb-connectstring=192.168.50.10
#./libexec/ndbd --initial ### 第一次启动需要 --initial 以后在启动不需要加
2010-06-21 14:09:38 [ndbd] INFO -- Configuration fetched from '192.168.5.10:1186', generation: 1
--------------------------启动说明
--------------------------启动存储节点
在每台存储节点服务器上,如果是第一次启动ndbd进程的话,必须先执行以下命令:
root# /usr/local/mysql/libexec/ndbd --initial
注意,仅应在首次启动ndbd时,或在备份/恢复数据或配置文件发生变化后重启ndbd时使用“--initial”参数
。因为该参数会使节点删除由早期ndbd实例创建的、用于恢复的任何文件,包括用于恢复的日志文件。
如果不是第一次启动,直接运行如下命令即可:
root# /usr/local/mysql/libexec/ndbd
--------------------------
然后在 MGM 服务器上查看
[root@db1 ~]# /usr/local/mysql/bin/ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.50.20 (mysql-5.1.47 ndb-7.1.8, Nodegroup: 0, Master)
id=3 @192.168.50.30 (mysql-5.1.47 ndb-7.1.8, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.50.10 (mysql-5.1.47 ndb-7.1.8)
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from 192.168.50.40)
id=5 (not connected, accepting connect from 192.168.50.50)
从上面可以看出 两个 ndbd 节点 和 ndbd 上存储都已经连接上了。
****************************************
3、安装配置SQL节点(DB4、DB5)
****************************************
# groupadd mysql
# useradd -g mysql -d /usr/local/mysql/var -M mysql
# tar xvzf mysql-cluster-gpl-7.1.8.tar.gz
# cd mysql-cluster-gpl-7.1.8
# ./configure --prefix=/usr/local/mysql/ --with-charset=utf8 --with-collation=utf8_general_ci \
--with-client-ldflags=-all-static -with-mysqld-ldflags=-all-static --enable-assembler \
--with-extra-charsets=complex --enable-thread-safe-client --with-big-tables \
--with-readline --with-ssl --with-embedded-server --enable-local-infile \
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \
--sysconfdir=/usr/local/mysql/etc --without-debug --with-mysqld-user=mysql --with-plugins=max
# make
# make install
# cd /usr/local/mysql
# mkdir mysql-cluster etc
# chown root:mysql . -R
# ./bin/mysql_install_db --user=mysql
# vi ./etc/my.cnf
[mysqld]
basedir = /usr/local/mysql/
datadir = /usr/local/mysql/var
user = mysql
port = 3306
socket = /usr/local/mysql/tmp/mysql.sock
ndbcluster
ndb-connectstring=192.168.50.10
[mysql_cluster]
ndb-connectstring=192.168.50.10
启动 mysql 服务
# ./bin/mysqld_safe --user=mysql &
--------------启动mysqld服务
最后,运行以下命令启动SQL节点服务器:
root# /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
--------------
回到 MGM 上查看是否正常
./bin/ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.50.20 (mysql-5.1.47 ndb-7.1.8, Nodegroup: 0, Master)
id=3 @192.168.50.30 (mysql-5.1.47 ndb-7.1.8, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.50.10 (mysql-5.1.47 ndb-7.1.8)
[mysqld(API)] 2 node(s)
id=4 @192.168.50.40 (mysql-5.1.47 ndb-7.1.8)
id=5 @192.168.50.50 (mysql-5.1.47 ndb-7.1.8)
好了,一切正常了,现在回到 mysql 节点上 创建和删除数据看是否同步。
****************************************
4.新建数据库测试
****************************************
那么就登录 DB4 的 mysql
DB4 # > /usr/local/mysql/bin/mysql -uroot -p
mysql > show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| ndbinfo |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql > create database accp;
Query OK, 1 row affected (0.39 sec)
mysql > show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| accp |
| mysql |
| ndbinfo |
| test |
+--------------------+
5 rows in set (0.00 sec)
看 DB5 上是否同步
DB5 # > /usr/local/mysql/bin/mysql -uroot -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| accp |
| mysql |
| ndbinfo |
| test |
+--------------------+
5 rows in set (0.00 sec)
DB5 # > /usr/local/mysql/bin/mysql -uroot -p
mysql > show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| accp |
| mysql |
| ndbinfo |
| test |
+--------------------+
5 rows in set (0.00 sec)
都看到了 accp 数据库 安装配置完成。
****************************************
5.新建表测试
****************************************
DB5上新建测试表t1
mysql> use accp;
Database changed
mysql> create table t1
-> (
-> sid int not null primary key,
-> sno int
-> ) engine=ndbcluster;
Query OK, 0 rows affected (0.37 sec)
mysql> insert into t1 values (101,201);
Query OK, 1 row affected (0.01 sec)
mysql> select * from t1;
+-----+------+
| sid | sno |
+-----+------+
| 101 | 201 |
+-----+------+
1 row in set (0.00 sec)
DB4上查看是否同步:
mysql> use accp;
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_accp |
+----------------+
| t1 |
+----------------+
1 row in set (0.02 sec)
mysql> select * from t1;
+-----+------+
| sid | sno |
+-----+------+
| 101 | 201 |
+-----+------+
1 row in set (0.01 sec)
上一篇: 管理权限,该如何解决
下一篇: Nginx PATH_INFO配置
推荐阅读
-
Galera 3.5 for Percona XtraDB Cluster 5.6 is now available_MySQL
-
详细介绍MySQL Group Replication[Single-Primary Mode]的搭建部署过程
-
Linux下搭建MySQL多实例环境_MySQL
-
怎么搭建php mysql坏境
-
Ubuntu10下如何搭建MySQL Proxy读写分离探讨
-
MySQL Cluster如何创建磁盘表方法解读
-
详解MySQL高可用MMM搭建方案及架构原理
-
mysql 5.7 docker 主从复制架构搭建教程
-
在CentOS上安装搭建PHP+Apache+Mysql的服务器环境
-
redhat7.1 安装mysql 5.7.10步骤详解(图文详解)