192.168.100.10 管理节点

192.168.100.20 sql节点

192.168.100.30 sql节点


192.168.100.40 存储节点

192.168.100.50 存储节点

系统均为centos6.4 x64

一、安装前准备

[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-Cluster-7.3/MySQL-Cluster-gpl-7.3.5-1.el6.x86_64.rpm-bundle.tar

[root@node1 ~]# tar xvf MySQL-Cluster-gpl-7.3.5-1.el6.x86_64.rpm-bundle.tar

解压后文件

MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm

MySQL-Cluster-devel-gpl-7.3.5-1.el6.x86_64.rpm MySQL-Cluster-shared-compat-gpl-7.3.5-1.el6.x86_64.rpm

MySQL-Cluster-embedded-gpl-7.3.5-1.el6.x86_64.rpm MySQL-Cluster-shared-gpl-7.3.5-1.el6.x86_64.rpm

MySQL-Cluster-gpl-7.3.5-1.el6.x86_64.rpm-bundle.tar MySQL-Cluster-test-gpl-7.3.5-1.el6.x86_64.rpm

拷贝MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm到所有服务器

 [root@node1 ~]# scp MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm 192.168.100.20:~/

 [root@node1 ~]# scp MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm 192.168.100.30:~/

 [root@node1 ~]# scp MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm 192.168.100.40:~/

 [root@node1 ~]# scp MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm 192.168.100.50:~/

拷贝MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm到sql节点

 [root@node1 ~]# scp MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm 192.168.100.20:~/

 [root@node1 ~]# scp MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm 192.168.100.30:~/

所有节点机器清理旧的Mysql安装

yum remove mysql

rpm -qa | grep mysql*

对于找到的1个剩余mysql包,请按照如下的命令格式予以删除:

rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.x86_64


安装依赖库

yum -y install libaio


二、安装mysql-cluster


每个节点机器安装MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm

rpm -Uvh MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm


安装后会提示默认密码存放在/root/.mysql_secret文件中

spacer.gifwKioL1Ohtp_gaGVOAAJisotrf1g842.jpg


在sql节点机器安装MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm


[root@node2 ~]# rpm -Uvh MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm

[root@node3 ~]# rpm -Uvh MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm

三、配置管理节点

[root@node1 ~]# mkdir /var/lib/mysql-cluster 
[root@node1 ~]# cd /var/lib/mysql-cluster/

[root@node1 mysql-cluster]# vim config.ini

[ndbd default]

NoOfReplicas=2 # 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 tabkes up

                # only about 500kb, this should be more than enough for

                # this example Cluster setup

[ndb_mgmd]

#Management process otions

hostname=192.168.100.10 #Hostname or IP address of MGM node

datadir=/var/lib/mysql-cluster #Directory for MGM node log files

[ndbd]

#Options for data node "A"

hostname=192.168.100.40 #Hostname or IP address

datadir=/usr/local/mysql/data #Directory for this data node's data files

[ndbd]

#Options for data node "B"

hostname=192.168.100.50 #Hostname or IP address

datadir=/usr/local/mysql/data #Directory for this data node's data files

[mysqld]

#SQL node options

hostname=192.168.100.20 #Hostname or IP address

[mysqld]

hostname=192.168.100.30 #Hostname or IP address


四、配置存储节点和SQL节点

存储节点:

[root@node4 ~]# mkdir -p /usr/local/mysql/data

[root@node5 ~]# mkdir -p /usr/local/mysql/data

SQL节点:

[root@node2 ~]# mkdir -p /var/run/mysqld

[root@node2 ~]# chmod -R 777 /var/run/mysqld/

[root@node3 ~]# mkdir -p /var/run/mysqld 
[root@node3 ~]# chmod -R 777 /var/run/mysqld/


在所有存储节点和SQL节点上建立配置文件/etc/my.cnf


 vim /etc/my.cnf 

[client] 
socket=/var/lib/mysql/mysql.sock 

[mysqld] 
max_connections=100 
datadir=/var/lib/mysql 
socket=/var/lib/mysql/mysql.sock 
ndbcluster 
ndb-connectstring=192.168.100.10 

[mysqld_safe] 
log-error=/var/log/mysqld.log 
pid-file=/var/run/mysqld/mysqld.pid 

[mysql_cluster] 
ndb-connectstring=192.168.100.10


五、启动各个节点


注意顺序。

1. 启动管理节点:

[root@node1 ~]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini

2. 启动存储节点:

[root@node4 ~]# ndbd --initial

[root@node5 ~]# ndbd --initial

   初次启动时需要加–initial参数,以后只需要执行ndbd即可;

3. 启动SQL节点:

[root@node2 ~]# mysqld_safe --defaults-file=/etc/my.cnf --explicit_defaults_for_timestamp &

[root@node3 ~]# mysqld_safe --defaults-file=/etc/my.cnf --explicit_defaults_for_timestamp &


六、检查所有节点是否正常启动


在管理节点中执行ndb_mgm 进入集群管理console,使用show命令列出所有节点信息

wKiom1Ohtv-xhKniAAE9yixTraM339.jpg

七、修改root用户密码

在每个sql节点执行

[root@node2 ~]# cat .mysql_secret         ----记录安装cluster-server时自动生成的初始密码
# The random password set for the root user at Sat Jun 14 01:20:33 2014 (local time): HtPV2gJbSrRPi8Is

[root@node2 ~]# mysqladmin -uroot -pHtPV2gJbSrRPi8Is password 'zhyzhy'

Warning: Using a password on the command line interface can be insecure.        ----此警告提示密码设置过于简单不安全

[root@node2 ~]# mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 20 
Server version: 5.6.17-ndb-7.3.5-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> exit 
Bye


[root@node3 ~]# cat .mysql_secret 
# The random password set for the root user at Sat Jun 14 01:21:06 2014 (local time): NtwwjhqTfsqTihGM

[root@node3 ~]# mysqladmin -uroot -pNtwwjhqTfsqTihGM password 'zhyzhy' 
Warning: Using a password on the command line interface can be insecure.

[root@node3 ~]# mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 4 
Server version: 5.6.17-ndb-7.3.5-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> exit 
Bye


八、测试集群: 

在sql节点 node2上登陆mysql: 

[root@node2 ~]# mysql -u root -pzhyzhy

mysql> create database lxw; 

Query OK, 1 row affected (0.06 sec) 



在sql节点node3上登陆mysql: 

[root@node3 ~]# mysql -u root -pzhyzhy 

mysql> show databases; 

+——————–+ 

| Database | 

+——————–+ 

| information_schema | 

| lxw | 

| mysql | 

| ndbinfo | 

| performance_schema | 

| test | 

+——————–+ 

6 rows in set (0.00 sec) 

可以看到database已经同步。 

九、常用命令: 

1) ndb_mgmd管理命令:ndb_mgm 

执行之后就是管理控制台了,里面可以继续输入命令。 

查看集群里面的全部节点的状态:show 

2) 停止集群服务器的命令:ndb_mgm -e shutdown 

如果集群配置有更新了:rm /usr/mysql-cluster/ndb_1_config.bin.1 

3) 停止SQL节点的命令:mysqladmin -uroot shutdown 

4) SQL Node上连接MySQL:mysql -u root –pPASSWORD 

执行之后就是MySQL控制台了,里面可以继续输入命令。