mysql集群配置详细过程录制

1、准备三台linux服务器(三台机器进行如下配置)
--hostname配置
192.168.9.241    sqltest01   (mysqld及存储节点)
192.168.9.242    sqltest02   (mysqld及存储节点)
192.168.9.243    sqltest03
其中,sqltest01、sqltest02分别是mysql节点及存储节点,sqltest03为管理节点
--同时,把防火墙进行关闭或者把相关的端口打开,如3306,管理节点的1186等
[root@sqltest01 u01]# service iptables status
iptables: Firewall is not running.
如果开启的,请使用service iptables stop
--创建相应的用户及目录
[root@sqltest01 u01]# groupadd mysql
[root@sqltest01 u01]# useradd -r -g mysql mysql
[root@sqltest01 u01]# mkdir -p /usr/local/mysql
[root@sqltest01 u01]# chown -R mysql.mysql

2、mysql cluster
下载网址:dev.mysql.com,然后选择cluster,然后在网页中出现的选择平台中,选择linux generic!在这里选择所需要tar包,我这里用的是mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
下载完成后,使用ftp传送到服务器上面,然后分别在三台机器上解压
[root@sqltest01 u01]# tar -zxvf mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/have_plugin_auth.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/kill_query.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/unsafe_binlog.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/have_multi_ndb.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/ipv6_clients.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/setup_fake_relay_log.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/wait_for_slave_sql_error_and_skip.inc
......................................................................................................

解压后,里面包括了数据库文件以及集群软件

3、配置管理节点(sqltest03)
--将刚才解压的软件拷贝到指定位置/usr/local/mysql
[root@sqltest03 mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64]# pwd
/u01/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64
[root@sqltest03 mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64]# mv * /usr/local/mysql/

--创建集群目录
[root@sqltest03 u01]# cd /usr/local/mysql
[root@sqltest03 mysql]# mkdir mysql-cluster
[root@sqltest03 mysql]# pwd
/usr/local/mysql
[root@sqltest03 mysql]# cp bin/ndb_mgm* /usr/local/bin/
[root@sqltest03 mysql]# cd /var/lib
[root@sqltest03 mysql]# mkdir mysql-cluster
[root@sqltest03 mysql]# cd mysql-cluster
[root@sqltest03 mysql]# vi config.ini
配置内容如下:
[root@sqltest03 mysql-cluster]# cat config.ini
[ndbd default]
NoOfReplicas=1
DataMemory=2048M
IndexMemory=512M

[tcp default]

[ndb_mgmd]
hostname=192.168.9.243
datadir=/var/lib/mysql-cluster
NodeId=1

[ndbd]
hostname=192.168.9.241
datadir=/u01/mysql/data
NodeId=2

[ndbd]
hostname=192.168.9.242
datadir=/u01/mysql/data
NodeId=3

[mysqld]
hostname=192.168.9.241
NodeId=4

[mysqld]
hostname=192.168.9.242
NodeId=5

配置说明:
[ndbd default]
这部分是公共部分,对于每一个数据节点都有效,只需要配置一份
NoOfReplicas=1
数据镜像几份(各数据节点之间相互备份)
[tcp default]
针对每个数据节点及管理节点之间使用哪个端口进行通讯,在旧版本的NDB集群软件配置时,这个地方通常配置portnumber=2202但新版的NDB软件这里不需要配置,并且MySQL官方也强烈建议不要配置
[ndb_mgmd]
管理节点的配置部分(通常只有一个)。注意NodeId=1指明管理节点的节点ID为1,如果不指定,在启动集群时,会报错
hostname=192.168.9.243
指明管理节点的IP地址
datadir=/var/lib/mysql-cluster
指明集群管理日志存放的位置
[ndbd]
数据节点配置部分,有几个数据节点就配置几个[ndbd]
hostname=192.168.1.111
指明数据节点的IP地址
datadir=/u01/app/mysql/data
指明数据节点上的数据库文件存放的位置
NodeId=2
指明该数据节点在整个集群中的nodeid号(很重要)
[mysqld]
SQL节点配置部分,有几个SQL节点,就配置几个[mysqld]

到这里,就可以启动集群了
[root@sqltest03 bin]# pwd
/usr/local/bin
[root@sqltest03 bin]# ./ndb_mgmd -f /var/lib/mysql-cluster/config.ini
MySQL Cluster Management Server mysql-5.6.21 ndb-7.3.7
进入执行查看
[root@sqltest03 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.9.241)
id=3 (not connected, accepting connect from 192.168.9.242)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.9.243  (mysql-5.6.21 ndb-7.3.7)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.9.241)
id=5 (not connected, accepting connect from 192.168.9.242)
可以看到有两个节点,节点没有连接上

4、配置mysqld节点及存储节点(sqltest01,sqltest02)
--建立相应目录
[root@sqltest01 mysql]# mkdir -p /usr/local/mysql   --用于存放刚才解压的文件,如mysql的bin目录等
[root@sqltest01 mysql]# mkdir -p /u01/mysql/data  --用于存储数据文件(innodb)
[root@sqltest01 mysql]# chown -R mysql.mysql /u01
--将先前解压的文件拷贝
[root@sqltest01 mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64]# pwd
/u01/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64
[root@sqltest01 mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64]# mv * /usr/local/mysql/
[root@sqltest01 mysql]# chown -R mysql.mysql /usr/local/mysql/
--拷贝mysql.server
[root@sqltest01 support-files]# pwd
/usr/local/mysql/support-files
[root@sqltest01 support-files]# ls -lrt
total 32
-rw-r--r--. 1 mysql mysql   773 Oct  9 21:46 magic
-rwxr-xr-x. 1 mysql mysql 10880 Oct  9 22:42 mysql.server
-rwxr-xr-x. 1 mysql mysql   894 Oct  9 22:42 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql  1061 Oct  9 22:42 mysqld_multi.server
-rw-r--r--. 1 mysql mysql  1126 Oct  9 22:42 my-default.cnf
-rwxr-xr-x. 1 mysql mysql  1153 Oct  9 22:42 binary-configure
[root@sqltest01 support-files]# cp mysql.server /etc/rc.d/init.d/mysqld
--编辑环境变量
[root@sqltest01 tmp]# vi /etc/profile
添加如下:
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
[root@sqltest01 tmp]# source /etc/profile    --使修改生效
--配置my.cnf
[root@sqltest01 support-files]# cp my-default.cnf /etc/my.cnf
并对my.cnf进行配置,具体配置如下
[mysqld]
ndbcluster
basedir=/usr/local/mysql
datadir=/u01/mysql/data
port=3306

[mysql_cluster]
ndb-connectstring=192.168.9.243

--初始化节点数据库
[root@sqltest01 mysql]#  scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/u01/mysql/data
执行完这条命令以后,数据库的数据文件(包括mysql,test , performance_schema等数据库),就安装到相应的位置了,可以使用了
在两个节点都执行上面的步骤即可

5、在两个点启动
root@sqltest01 mysql]# ndbd --initial
2014-12-24 17:55:57 [ndbd] INFO     -- Angel connected to '192.168.9.243:1186'
2014-12-24 17:55:57 [ndbd] INFO     -- Angel allocated nodeid: 2
第一次启动时,需要加--initial来初始化数据节点,第二次启动时,就不需要这个参数了
在管理节点查看,可以看到第一个节点已经连接
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.9.241  (mysql-5.6.21 ndb-7.3.7, starting, Nodegroup: 0)    --表明已经连接上了
id=3 (not connected, accepting connect from 192.168.9.242)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.9.243  (mysql-5.6.21 ndb-7.3.7)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.9.241)
id=5 (not connected, accepting connect from 192.168.9.242)
启动mysqld
[root@sqltest01 mysql]# cd /usr/local/mysql/bin
[root@sqltest01 bin]# ./mysqld_safe --user=mysql
141224 17:59:50 mysqld_safe Logging to '/u01/mysql/data/sqltest01.err'.
141224 17:59:51 mysqld_safe Starting mysqld daemon with databases from /u01/mysql/data

启动数据库时,第一次初始化使用的root,而这次使用mysql,需要对/u01/mysql/data权限进行配置,否则报不可读写
再次在管理节点查看
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.9.241  (mysql-5.6.21 ndb-7.3.7, Nodegroup: 0, *)
id=3 (not connected, accepting connect from 192.168.9.242)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.9.243  (mysql-5.6.21 ndb-7.3.7)

[mysqld(API)]   2 node(s)
id=4    @192.168.9.241  (mysql-5.6.21 ndb-7.3.7)                       --表明已经连接上了
id=5 (not connected, accepting connect from 192.168.9.242)

最后把第二节点也启动,再次从管理节点检查
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.9.241  (mysql-5.6.21 ndb-7.3.7, Nodegroup: 0, *)
id=3    @192.168.9.242  (mysql-5.6.21 ndb-7.3.7, Nodegroup: 1)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.9.243  (mysql-5.6.21 ndb-7.3.7)

[mysqld(API)]   2 node(s)
id=4    @192.168.9.241  (mysql-5.6.21 ndb-7.3.7)
id=5    @192.168.9.242  (mysql-5.6.21 ndb-7.3.7)

6、在两个节点测试
[root@sqltest01 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.21-ndb-7.3.7-cluster-gpl MySQL Cluster Community Server (GPL)

Copyright (c) 2000, 2014, 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> create database mydb1;
Query OK, 1 row affected (0.07 sec)

mysql> use mydb1;
Database changed
mysql> create table mytb1(id int,birthdate datetime,pername char(10)) engine=ndbcluster;
Query OK, 0 rows affected (0.19 sec)


mysql> insert into mytb1(id,birthdate,pername) values(1,'2013-01-23 09:45:10','pengzitong');
Query OK, 1 row affected (0.00 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into mytb1(id,birthdate,pername) values(2,'2007-07-09 09:45:10','pengzixin');
Query OK, 1 row affected (0.00 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

在第二节点检查
[root@sqltest02 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.21-ndb-7.3.7-cluster-gpl MySQL Cluster Community Server (GPL)

Copyright (c) 2000, 2014, 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> use mydb1
mysql> select * from mytb1;
+------+---------------------+------------+
| id   | birthdate           | pername    |
+------+---------------------+------------+
|    1 | 2013-01-23 09:45:10 | pengzitong |
|    2 | 2007-07-09 09:45:10 | pengzixin  |
+------+---------------------+------------+

7、集群停止
要想关闭 Cluster,可在MGM节点所在的机器上,在Shell中简单地输入下述命令:
[root@sqltest03 bin]#  /usr/local/mysql/ndb_mgm -e shutdown
运行以下命令关闭SQL节点的mysqld服务:
[root@sqltest01 bin]#  /usr/local/mysql/bin/mysqladmin -uroot shutdown 

本文由http://www.mfqyw.com/ 编辑整理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值