Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6683121
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Mysql/postgreSQL

2014-11-25 14:37:48

环境:

OS:Rad Hat Linux As5

mysql集群: mysql-cluster-gpl-7.2.8


1.1     节点规划

这里总共3台物理机器,其中一台为管理节点,另外两台即做数据节点和sql节点

节点角色

Ip地址

管理节点

192.168.56.102

数据节点1

192.168.56.103

数据节点2

192.168.56.104

SQL节点1

192.168.56.103

SQL节点2

192.168.56.104

 

1.2 下载安装介质

下载安装介质,下载地址为:

根据情况选择下载的版本,我这里下载的介质是mysql-cluster-gpl-7.2.8-linux2.6-x86_64.tar.gz



 

1.3 安装管理节点(192.168.56.102

 [root@node2 ~]#groupadd mysql

[root@node2 ~0] #useradd mysql -g mysql

[root@node2 ~]# passwd mysql

 

[root@node2 mysql]# cp mysql-cluster-gpl-7.2.8-linux2.6-x86_64.tar.gz /usr/local

[root@node2 local]# cd /usr/local

[root@node2 local]# tar -zxvf mysql-cluster-gpl-7.2.8-linux2.6-x86_64.tar.gz

[root@node2 local]# mv mysql-cluster-gpl-7.2.8-linux2.6-x86_64 mysql

 

[root@node2 local]# chown -R mysql:mysql ./mysql

 

[root@node2 scripts]#] cd /usr/local/mysqlclu/scripts

 

[root@node2 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

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:

 

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

/usr/local/mysql/bin/mysqladmin -u root -h node2 password 'new-password'

 

Alternatively you can run:

/usr/local/mysql/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 /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

 

Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!

 

 

1.4 配置管理节点(192.168.56.102

mysql用户下操作

[mysql@node2 mysql]$ mkdir /usr/local/mysql/config

创建config.cnf文件

该文件内容如下:

[ndbd default]

NoOfReplicas=2

DataMemory=80M

IndexMemory=18M

[ndb_mgmd]

NodeId=1

Hostname=192.168.56.102

datadir=/usr/local/mysql/logs

[ndbd]

NodeId=2

Hostname=192.168.56.103

datadir=/usr/local/mysql/data/

[ndbd]

NodeId=3

Hostname=192.168.56.104

datadir=/usr/local/mysql/data/

[MYSQLD]

[MYSQLD]

 

 

1.5 安装数据节点(192.168.56.103,192.168.56.104

两个节点执行相同的操作

[root@node3 ~]# groupadd mysql

[root@node3 ~]# useradd mysql -g mysql

[root@node3 ~]# passwd mysql

[root@node3 soft]# cp mysql-cluster-gpl-7.2.8-linux2.6-x86_64.tar.gz /usr/local

[root@node3 soft]# cd /usr/local

[root@node3 local]# tar -zxvf mysql-cluster-gpl-7.2.8-linux2.6-x86_64.tar.gz

[root@node3 local]# mv mysql-cluster-gpl-7.2.8-linux2.6-x86_64 mysql

[root@node3 local]# chown -R mysql:mysql mysql

[mysql@node3 scripts]$ cd /usr/local/mysql/scripts

 

[mysql@node3 scripts]$ ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

 

[mysql@node3 support-files]$ cd /usr/local/mysql/support-files

[mysql@node3 support-files]$ su root

[root@node3 support-files]# cp mysql.server /etc/init.d/mysqld

/mysql/data/


[ndbd]

NodeId=3

Hostname=192.168.56.104

datadir=/usr/local/mysql/data/

[MYSQLD]

[MYSQLD]

 


 

1.6 配置数据节点(192.168.56.103,192.168.56.104

每个数据节点的操作都一样

[root@node3 support-files]# vi /etc/my.cnf

内容如下:

 

[mysqld]

ndbcluster                        # run NDB storage engine

ndb-connectstring=192.168.56.102   # location of management server

 

# Options for ndbd process:

[mysql_cluster]

ndb-connectstring=192.168.56.102   # location of management server

 

[mysql@node3 support-files]$ cd /usr/local/mysql/support-files

[mysql@node3 support-files]$ su root

[root@node3 support-files]# cp mysql.server /etc/init.d/mysqld

/mysql/data/


[ndbd]

NodeId=3

Hostname=192.168.56.104

datadir=/usr/local/mysql/data/

[MYSQLD]

[MYSQLD]

 

 

1.7 启动管理节点服务(192.168.56.102

[mysql@node2 config]$ /usr/local/mysql/bin/ndb_mgmd -f /usr/local/mysql/config/config.cnf --initial

 

必须注意:只是在第一次启动或在备份/恢复或配置变化后重启ndbd时,才加–initial参数!

查看到1186端口说明已经启动

[mysql@node2 mysql-cluster]$ netstat -lntpu

(Not all processes could be identified, non-owned process info

 will not be shown, you would have to be root to see it all.)

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  

tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      -                  

tcp        0      0 0.0.0.0:1186                0.0.0.0:*                   LISTEN      7334/ndb_mgmd      

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      -                  

tcp        0      0 0.0.0.0:789                 0.0.0.0:*                   LISTEN      -                  

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -                  

tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      -                   

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -                  

tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      -                  

udp        0      0 0.0.0.0:783                 0.0.0.0:*                               -                  

udp        0      0 0.0.0.0:786                 0.0.0.0:*                               -                  

udp        0      0 0.0.0.0:40607               0.0.0.0:*                               -                  

udp        0      0 0.0.0.0:68                  0.0.0.0:*                               -                  

udp        0      0 0.0.0.0:5353                0.0.0.0:*                               -                  

udp        0      0 0.0.0.0:111                 0.0.0.0:*                               -                  

udp        0      0 0.0.0.0:631                 0.0.0.0:*                               -                   


 

1.8 启动数据节点服务(192.168.56.103, 192.168.56.104

 

每个数据节点执行同样的操作

[mysql@node3 ~]$ /usr/local/mysql/bin/ndbd --initial

2014-11-25 10:24:37 [ndbd] INFO     -- Angel connected to '192.168.56.102:1186'

2014-11-25 10:24:37 [ndbd] INFO     -- Angel allocated nodeid: 2

 

必须注意:只是在第一次启动或在备份/恢复或配置变化后重启ndbd时,才加–initial参数!

 

 

 

1.9 启动SQL节点服务(192.168.56.103, 192.168.56.104

 每个数据节点执行同样的操作

[root@node3 ~]# service mysqld start

Starting MySQL.....................................[  OK  ]

 


 

1.10 功能测试

1.10.1  在管理节点(192.168.56.102)上查看服务状态

[mysql@node2 mysql-cluster]$ /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    @192.168.56.103  (mysql-5.5.27 ndb-7.2.8, starting, Nodegroup: 0)

id=3 (not connected, accepting connect from 192.168.56.104)

 

[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.56.102  (mysql-5.5.27 ndb-7.2.8)

 

[mysqld(API)]   2 node(s)

id=4 (not connected, accepting connect from any host)

id=5 (not connected, accepting connect from any host)

 

 

1.10.2  测试1

现在我们在其中一个数据节点上进行相关数据库的创建,然后到另外一个数据节点上看看数据是否同步

 

在数据节点1(192.168.56.103)上执行:

shell> /usr/local/mysql/bin/mysql -u root -p 

mysql>show databases; 

mysql>create database hxl; 

mysql>use hxl; 

mysql>CREATE TABLE tb_test (i INT) ENGINE=NDB; //这里必须指定数据库表的引擎为NDB,否则同步失败 

mysql>INSERT INTO tb_test (i) VALUES (1),(2),(3); 

mysql>SELECT * FROM tb_test;

 

然后登陆另外一个节点查看刚才的表是否已经同步

[mysql@node4 ~]$ /usr/local/mysql/bin/mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.5.27-ndb-7.2.8-cluster-gpl MySQL Cluster Community Server (GPL)

 

Copyright (c) 2000, 2011, 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> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| hxl                |

| mysql              |

| ndb_3_fs           |

| ndbinfo            |

| performance_schema |

| test               |

+--------------------+

7 rows in set (0.00 sec)

 

mysql> use hxl;

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_hxl |

+---------------+

| tb_test       |

+---------------+

1 row in set (0.03 sec)

 

发行刚才创建的表已经同步了。

 

1.11 关闭操作

关闭集群的流程是:

关闭管理节点-->关闭数据节点-->关闭SQL节点

 

关闭管理节点: /usr/local/mysql/bin/ndb_mgm -e shutdown

关闭管理节点的同时也会关闭数据节点

 

关闭SQL节点: root用户下执行service mysqld stop

或采用如下命令关闭

/usr/local/mysql/bin/mysqladmin -uroot shutdown



-- The End --




阅读(3439) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~