mysql-cluster搭建

参考:http://blog.csdn.net/zklth/article/details/7522677

一、环境准备:

注:所有节点需要将其防墙关闭

/etc/init.d/iptables status #查看防火墙状态
/etc/init.d/iptables stop #关闭防火墙
1. 软件下载:
ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-Cluster-7.1/

选择 mysql-cluster-gpl-7.1.19.tar.gz 下载

2.硬件需要五台物理节点(虚拟机上试过不行)

3.软件安装:在所有节点上做如下操作

######################################################################################################

groupadd mysql #创建mysql组

useradd -g mysql mysql #创建mysql用户

#创建目录

mkdir -p opt/mysql-cluster

mkdir -p opt/mysql-cluster/etc

mkdir -p opt/mysql-cluster/tmp

mkdir -p opt/mysql-cluster/data

#解压软件包

tar zxvf mysql-cluster-gpl-7.1.19.tar.gz

#配置安装项

cd mydql-cluster-gpl-7.1.19

./configure --prefix=/opt/mysql-cluster --with-charset=gbk --with-collation=gbk_chinese_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=/opt/mysql-cluster/tmp/mysql.sock --sysconfdir=/opt/mysql-cluster/etc --without-debug --with-mysqld-user=mysql --with-plugins=max

#安装

make && make install

######################################################################################################

二、管理节点配置

1.创建管理节点的集群配置文件config.ini

[root@sg204 mysql-cluster]# vi etc/config.ini

[NDBD DEFAULT]
NoOfReplicas= 2
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
DataDir=/opt/mysql-cluster/data #数据存放目录
[NDB_MGMD]
HostName= 10.30.9.204
[NDBD]
HostName= 10.30.9.206
DataDir=/opt/mysql-cluster/data
[NDBD]
HostName= 10.30.9.207
Datadir=/opt/mysql-cluster/data
[MYSQLD]
HostName= 10.30.9.208
[MYSQLD]
HostName= 10.30.9.211

2.在管理节点上启动ndb_mgmd服务

[root@sg204 mysql-cluster]# libexec/ndb_mgmd -f etc/config.ini
MySQL Cluster Management Server mysql-5.1.56 ndb-7.1.19

这时ndb_mgmd服务已经启动了,可以 用ps命令查看其进程:

[root@sg204 mysql-cluster]# ps -ef | grep ndb
root 23505 1 0 May11 ? 00:00:00 libexec/ndb_mgmd -f etc/config.ini
root 24692 24238 0 01:29 pts/1 00:00:00 grep ndb

用ndb_mgm>show 命令查看其状态:

[root@sg204 mysql-cluster]# 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 10.30.9.206)
id=3 (not connected, accepting connect from 10.30.9.207)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @10.30.9.204 (mysql-5.1.56 ndb-7.1.19)

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


从显示信息可以 看出两个数据节点和两个SQL节点都未启动。

ndb_mgm> exit #退出



三、数据节点配置

在两个数据节点上执行以下的1 2 3 4 步操作

1.创建数据字典

指定数据目录和用户

[root@sg206 mysql-cluster]# bin/mysql_install_db --user=mysql --datadir=/opt/mysql-cluster/data --basedir=/opt/mysql-cluster
WARNING: The host 'sg206' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
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:

/opt/mysql-cluster/bin/mysqladmin -u root password 'new-password'
/opt/mysql-cluster/bin/mysqladmin -u root -h sg206 password 'new-password'

Alternatively you can run:
/opt/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 /opt/mysql-cluster ; /opt/mysql-cluster/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /opt/mysql-cluster/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/mysql-cluster/scripts/mysqlbug script!

2.创建my.cnf配置文件

[root@sg207 mysql-cluster]# vim etc/my.cnf


[mysqld]
basedir= /opt/mysql-cluster
datadir= /opt/mysql-cluster/data
user= mysql
port= 3306
socket= /opt/mysql-cluster/tmp/mysql.sock
ndbcluster
#管理节点IP
ndb-connectstring=10.30.9.204
[mysql_cluster]
#管理节点IP
ndb-connectstring=10.30.9.204

3.启动nbdb服务

ndbd服务第一次启动时需要加上--initial选项,以后不需要

[root@sg207 mysql-cluster]# libexec/ndbd --initial

2012-05-12 03:53:15 [ndbd] INFO -- Angel connected to '10.30.9.204:1186'

2012-05-12 03:53:15 [ndbd] INFO -- Angel allocated nodeid: 2

4.将mysql-cluster目录下的所有内容的拥有者更换为mysql用户,mysql组

[root@sg207 mysql-cluster]# chown -R mysql:mysql *



这时两个数据结点nbdb服务都启动后,再在管理节点或者数据节点均可查看集群状态,

可以看出两个数据节点上的ndbd服务都启动了
################################################
[root@sg204 mysql-cluster]# 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 @10.30.9.206 (mysql-5.1.56 ndb-7.1.19, Nodegroup: 0, Master)
id=3 @10.30.9.207 (mysql-5.1.56 ndb-7.1.19, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @10.30.9.204 (mysql-5.1.56 ndb-7.1.19)

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

###############################################

四,SQL节点配置

对两个SQL节点执行三中的1 2 4 步及下面的 1步

1.启动mysqld进程

[root@sg208 mysql-cluster]# bin/mysqld_safe --defaults-file=/opt/mysql-cluster/etc/my.cnf --basedir=/opt/mysql-cluster --datadir=/opt/mysql-cluster/data --user=mysql &

若启动失败,则查看错误日志/opt/mysql-cluster/data/sg208.err

再在管理节点或者数据节点均可查看集群状态

################################################

[root@sg204 mysql-cluster]# 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 @10.30.9.206 (mysql-5.1.56 ndb-7.1.19, Nodegroup: 0, Master)
id=3 @10.30.9.207 (mysql-5.1.56 ndb-7.1.19, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @10.30.9.204 (mysql-5.1.56 ndb-7.1.19)

[mysqld(API)] 2 node(s)
id=4 @10.30.9.208 (mysql-5.1.56 ndb-7.1.19)
id=5 @10.30.9.211 (mysql-5.1.56 ndb-7.1.19)

################################################

可以 看到所有结点全部正常。

五、在两个SQL结点上测试数据同步

在10.30.9.208SQL节点上登录数据库

[root@sg208 mysql-cluster]#bin/mysqladmin -uroot password '111111' #修改root用户的密码为111111

[root@sg208 mysql-cluster]#bin/mysql -uroot -p #连接mysql cluster
Enter password: #输入密码111111

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.56-ndb-7.1.19 Source distribution

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 orcl #创建orcl 数据库

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| ndbinfo |
| orcl |
| test |
+--------------------+
5 rows in set (0.00 sec)

10.30.9.208上orcl已经创建好

再在10.30.9.211上以同样方法登录数据库

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| ndbinfo |
| orcl |
| test |
+--------------------+
5 rows in set (0.00 sec)

可以 看到10.30.9.211上也有orcl库



在10.30.9.208上创建表并插入数据

use orcl;

create table name(

id int(4) auto_increment not null primary key,

xm char(8),

xb char(2),

csny date) engine=ndbcluster ; # engine=ndbcluster很重要,不加的话表数据不能同步。

insert into name values('','jack','m','1900-01-01');

insert into name values('','rose','f','1904-01-01');

这时在10.30.9.211上

mysql> use orcl
Database changed
mysql> select * from name;
+----+------+------+------------+
| id | xm | xb | csny |
+----+------+------+------------+
| 1 | jack | m | 1900-01-01 |
| 2 | rose | f | 1903-01-01 |
+----+------+------+------------+
2 rows in set (0.00 sec)

可以看出数据同步了。



附:

#scp -P 4400 -r root@10.0.24.103:/home2/backup/ /home/mover00/shadow_bak/sites/
拷贝远程(10.0.24.103)的/home2/backup/ 到本地的 /home/mover00/shadow_bak/sites/

#scp -P 4400 -r /home2/backup/ root@10.0.24.99:/home/mover00/shadow_bak/sites/
拷贝本地的/home2/backup/ 到远程(10.0.24.99)的 /home/mover00/shadow_bak/sites/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值