mysql-cluster(2)——部署
mysql-cluster系列:
- mysql-cluster(1)——简介
- mysql-cluster(2)——部署
- mysql-cluster(3)——集群管理和维护
- mysql-cluster(4)——创建内存表和磁盘表
- mysql-cluster(5)——jdbc
- mysql-cluster(6)——配置详解
- mysql-cluster(7)——基准测试
- mysql-cluster(8)——最佳实践
- mysql-cluster(9)——NDB和InnoDB区别
- mysql-cluster(10)——注意事项
本文目录:
1 准备工作
操作系统:redhat7(x64)
版本:mysql-cluster-gpl-7.4.11-linux-glibc2.5-x86_64.tar.gz(
http://cdn.mysql.com//Downloads/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.11-linux-glibc2.5-x86_64.tar.gz)
management节点:10.5.11.85
data节点:10.5.11.86
sql节点:10.5.11.87
2 部署
需要部署3类节点:MGM节点(管理节点)、NDB节点(数据节点)、API节点(SQL节点)。
3类节点上部署的应用均相同,但需要配置的文件不同。
2.1 新建linux用户
groupadd admin
useradd -d /home/admin -g admin-s /bin/bash admin
chown -R admin:admin ./mysql-cluster-gpl-7.4.11-linux-glibc2.5-x86_64.tar.gz
su admin
2.2 解压安装包
tar zxvf mysql-cluster-gpl-7.4.11-linux-glibc2.5-x86_64.tar.gz
mv -f mysql-cluster-gpl-7.4.11-linux-glibc2.5-x86_64 /usr/local
cd /usr/local
mv -f mysql-cluster-gpl-7.4.11-linux-glibc2.5-x86_64 mysql
cd mysql
2.3 NDB节点和API节点配置my.cnf
cp ./support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
[MYSQLD]
user=admin
character_set_server=utf8
ndbcluster
ndb-connectstring=10.5.11.85
default-storage-engine=ndbcluster
datadir=/opt/mysql/data
basedir=/usr/local/mysql
[MYSQL_CLUSTER]
ndb-connectstring=10.5.11.85
2.4 指定用户权限和数据位置
./scripts/mysql_install_db –user=admin –datadir=/opt/mysql/data –basedir=/usr/local/mysql
2.5 NDB节点配置mysqld
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
2.6 MGM节点配置config.ini
touch /opt/mysql/data/config.ini
vim /opt/mysql/data/config.ini
[NDBD DEFAULT]
NoOfReplicas=1 #每个数据节点的镜像数量,通常最低设置为2,否则就没有意义了,这里是方便后面测试。
DataMemory=64M #每个数据节点中给数据分配的内存
IndexMemory=16M #每个数据节点中给索引分配的内存
#管理节点
[NDB_MGMD]
nodeid=1
hostname=10.5.11.85 #管理节点ip
datadir=/opt/mysql/data #管理节点数据目录,存放相关日志,以及pid文件
#第一个 ndbd 节点:
[NDBD]
nodeid=2
hostname=10.5.11.86 #数据节点ip地址
datadir=/opt/mysql/data
# SQL node options:
[MySQLD]
nodeid=3
hostname=10.5.11.87 #SQL节点ip地址
[MySQLD] #这里保留了一个空节点。否则停止NDB会报错:No free node id found for ndbd(NDB).
2.7 mysql命令快捷方式生效
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /home/admin/.bash_profile
source /home/admin/.bash_profile
3 卸载
rm -rf /usr/local/mysql
rm -rf /etc/my.cnf
rm -rf /opt/mysql/data
rm -rf /etc/init.d/mysqld
vim /home/admin/.bash_profile
修改PATH,去除:/usr/local/mysql/bin
source /home/admin/.bash_profile
4 启动示例
4.1 启动management-node
[[email protected] mysql]# ndb_mgmd -f /opt/mysql/data/config.ini
MySQL Cluster Management Server mysql-5.6.29 ndb-7.4.11
[[email protected] mysql]#
查看是否有相关连接:
[[email protected] mysql]# netstat -ntlp | grep 1186
tcp 0 0 0.0.0.0:1186 0.0.0.0:* LISTEN 6661/ndb_mgmd
[[email protected] mysql]#
查看是否有相关进程:
[[email protected] mysql]# ps -ef | grep ndb_mgmd | grep -v grep
root 6661 1 0 16:00 ? 00:00:00 ndb_mgmd -f /opt/mysql/data/config.ini
[[email protected] mysql]#
4.2 启动data-node
[[email protected] mysql]# ndbd –initial
2016-06-29 16:02:40 [ndbd] INFO – Angel connected to ‘10.5.11.85:1186’
2016-06-29 16:02:40 [ndbd] INFO – Angel allocated nodeid: 2
[[email protected] mysql]#
查看是否有相关进程:
[[email protected] mysql]# ps -ef | grep ndbd | grep -v grep
root 3334 1 0 16:02 ? 00:00:00 ndbd –initial
root 3335 3334 0 16:02 ? 00:00:01 ndbd –initial
ndbd进程是使用NDB存储引擎处理表中数据的进程。通过该进程,存储节点能够实现分布式事务管理,节点恢复,在线备份相关任务。
4.3 启动sql-node
[[email protected] mysql]# /etc/init.d/mysqld start
Starting MySQL.. [ OK ]
[[email protected] mysql]#
4.4 验证集群
4.4.1 节点全部启动成功后。
在management-node使用ndb_mgm工具的show命令查看集群状态:
[[email protected] mysql]# ndb_mgm
– NDB Cluster – Management Client –
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 1 node(s)
id=2 @10.45.11.86 (mysql-5.6.29 ndb-7.4.11, Nodegroup: 0, *)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @10.45.11.85 (mysql-5.6.29 ndb-7.4.11)
[mysqld(API)] 2 node(s)
id=3 @10.45.11.87 (mysql-5.6.29 ndb-7.4.11)
id=4 (not connected, accepting connect from any host)
ndb_mgm>
4.4.2 数据同步检查。
在sql-node上进行数据操作。红色部分为标注。
(1)10.5.11.87创建数据库、表,并添加数据
[[email protected] mysql]# mysql -u root -p
Enter password: #默认管理员密码为空
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.29-ndb-7.4.11-cluster-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2016, 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 |
| mysql |
| ndbinfo |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> create database test2;
Query OK, 1 row affected (0.04 sec)
mysql> use test2
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table abc (id int) engine=ndbcluster;#指定数据库表的引擎为NDB,否则同步失败
Query OK, 0 rows affected (0.07 sec)
mysql> insert into abc () values (1);
Query OK, 1 row affected (0.01 sec)
mysql> select * from abc;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
mysql> show tables;
+-----------------+
| Tables_in_test2 |
+-----------------+
| abc |
+-----------------+
1 row in set (0.00 sec)
mysql>
(2)10.5.11.86查询数据
[[email protected] mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.29-ndb-7.4.11-cluster-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2016, 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> select * from abc;
ERROR 1046 (3D000): No database selected
mysql> quit
Bye
[[email protected] mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.29-ndb-7.4.11-cluster-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2016, 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 test2;
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> select * from abc;
+------+
| id |
+------+
| 1 |
+------+
1 rows in set (0.00 sec)
mysql>
(3)10.5.11.86添加新数据
mysql> insert into abc () values (2);
Query OK, 1 row affected (0.00 sec)
mysql> select * from abc;
+------+
| id |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec)
mysql>
(4)10.5.11.87查询数据
mysql> select * from abc;
+------+
| id |
+------+
| 2 |
| 1 |
+------+
2 rows in set (0.00 sec)
上一篇: docker镜像加速