# 基础环境
Management node(mgmd) - 10.2.0.13
Data node “A” (ndbd) - 10.2.0.14
Data node “B” (ndbd) - 10.2.0.15
SQL node “A” (mysqld) - 10.2.0.16
SQL node “B” (mysqld) - 10.2.0.17
注意关闭防火墙
一.准备工作
下载mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64.tar.gz
二.安装步骤
1.SQL node安装
①创建mysql用户及用户组
shell> groupadd mysql
shell> useradd -g mysql -s /bin/false mysql # 无登陆权限
②解压下载文件并创建软链接
shell> tar -C /usr/local -
mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64.tar.gz # 解压到指定目录
shell> ln -s /usr/local/mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64 /usr/local/mysql
③初始化mysql
先切换至/usr/local/mysql
shell> bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #初始化为空密码
④更改权限
shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
⑤编辑配置文件
shell> vi /etc/my.cnf # 删除原有内容替换为以下内容
[mysqld]
# Options for mysqld process:
ndbcluster # run NDB storage engine
default-storage-engine=ndbcluster
[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=10.2.0.13 # location of management server
⑥每一台SQL node相同操作
DATA node安装
①解压下载文件并拷贝相关目录
shell> tar -zxvf mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64.tar.gz
shell> cd mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64
shell> cp bin/ndbd /usr/local/bin/ndbd
shell> cp bin/ndbmtd /usr/local/bin/ndbmtd
②更改权限
shell> cd /usr/local/bin
shell> chmod +x ndb*
③创建MySQL数据目录
shell> mkdir -p /usr/local/mysql/data
⑥编辑配置文件
shell> vi my.cnf #删除原有内容替换为以下内容
[mysqld]
# Options for mysqld process:
ndbcluster # run NDB storage engine
[mysql_cluster]
# Options for NDB Cluster processes:
ndb-connectstring=10.2.0.13 # location of management server
④每一台DATA node相同操作
Management node node安装
①解压下载文件并拷贝相关目录
shell> tar -zxvf mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64.tar.gz
shell> cd mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64
shell> cp bin/ndb_mgm* /usr/local/bin
②更改权限
shell> cd /usr/local/bin
shell> chmod +x ndb_mgm*
③编辑配置文件
shell> mkdir -p /var/lib/mysql-cluster
shell> mkdir -p /usr/local/mysql/mysql-cluster
shell> cd /usr/local/mysql/mysql-cluster
shell> vi config.ini
填充以下内容
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2 # Number of replicas
[ndb_mgmd]
# Management process options:
HostName=10.2.0.13 # 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=10.2.0.14 # Hostname or IP address
NodeId=2 # Node ID for this data node
DataDir=/usr/local/mysql/data # Directory for this data node's data files
[ndbd]
# Options for data node "B":
HostName=10.2.0.15 # Hostname or IP address
NodeId=3 # Node ID for this data node
DataDir=/usr/local/mysql/data # Directory for this data node's data files
[mysqld]
# SQL node options:
HostName=10.2.0.16 # Hostname or IP address
NodeId=4 # Node ID for this data node
# (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)
[mysqld]
# SQL node options:
HostName=10.2.0.17 # Hostname or IP address
NodeId=5 # Node ID for this data node
# (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)
三.启动步骤
启动顺序Management node--->DATA node--->SQL node
1.Management node启动
shell> ndb_mgmd -f /usr/local/mysql/mysql-cluster/config.ini --initial # 注意(首次启动才需要加 --initial后面启动去掉--initial即可)
管理节点关闭命令:ndb_mgm -e shutdown
查看状态:ndb_mgm-e show
2.DATA node启动
shell> ndbd
3.SQL node启动
shell> mysql.server start
进入MySQL
shell> mysql -uroot -p
使用ndb_setup.py安装时注意 mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64/bin/ndb_setup.py -N <HOSTIP>
四.注意事项
1.mysqld置默认引擎
shell> vi /etc/my.cnf 文件中插入一行
default-storage-engine=ndbcluster
2.mysqld配置环境变量
shell> vi ~/.bash_profile
添加/usr/local/mysql/bin:/usr/local/mysql/support-files
3.设置开机自启时注意权限
shell> chmod 755 /etc/rc.local