码迷,mamicode.com
首页 > 数据库 > 详细

centos7 mysql cluster集群搭建基于docker

时间:2017-08-02 18:54:41      阅读:1818      评论:0      收藏:0      [点我收藏+]

标签:wget   blog   set   bsp   ref   dir   nbsp   address   srv   

 

1.准备

mn:集群管理服务器用于管理集群的其他节点。我们可以从管理节点创建和配置集群上的新节点、重新启动、删除或备份节点。

db2/db3:这是节点间同步和数据复制的过程发生的层。

db4/db5:应用程序使用的接口服务器连接到数据库集群。

[root@java1 ~]# docker inspect -f ‘{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}‘ $(docker ps -aq)
/db5 - 172.17.0.6
/db4 - 172.17.0.5
/db3 - 172.17.0.4
/db2 - 172.17.0.3
/mn - 172.17.0.2
[root@java1 ~]#

2.mn安装

cd ~
wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar
tar -xvf MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar

技术分享

yum -y install perl-Data-Dumper
yum -y remove mariadb-libs

cd ~
rpm -Uvh MySQL-Cluster-client-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-server-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-shared-gpl-7.4.10-1.el7.x86_64.rpm

Make sure there is no error.

 

配置mn:

mkdir -p /var/lib/mysql-cluster

cd /var/lib/mysql-cluster
vi config.ini

[ndb_mgmd default]
# Directory for MGM node log files
DataDir=/var/lib/mysql-cluster
 
[ndb_mgmd]
#Management Node db1
HostName=192.168.1.120
 
[ndbd default]
NoOfReplicas=2      # Number of replicas
DataMemory=256M     # Memory allocate for data storage
IndexMemory=128M    # Memory allocate for index storage
#Directory for Data Node
DataDir=/var/lib/mysql-cluster
 
[ndbd]
#Data Node db2
HostName=192.168.1.121
 
[ndbd]
#Data Node db3
HostName=192.168.1.122
 
[mysqld]
#SQL Node db4
HostName=192.168.1.123
 
[mysqld]
#SQL Node db5
HostName=192.168.1.124

start mn:

ndb_mgmd --config-file=/var/lib/mysql-cluster/config.ini

MySQL Cluster Management Server mysql-5.6.28 ndb-7.4.10
2016-03-22 19:26:08 [MgmtSrvr] INFO     -- The default config directory ‘/usr/mysql-cluster‘ does not exist. Trying to create it...
2016-03-22 19:26:08 [MgmtSrvr] INFO     -- Successfully created config directory

ndb_mgm
show

技术分享

 

 

db2/db3配置数据节点:

cd ~
wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar
tar -xvf MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar

yum -y install perl-Data-Dumper
yum -y remove mariadb-libs

cd ~
rpm -Uvh MySQL-Cluster-client-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-server-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-shared-gpl-7.4.10-1.el7.x86_64.rpm

vi /etc/my.cnf

[mysqld]
ndbcluster
ndb-connectstring=192.168.1.120     # IP address of Management Node
 
[mysql_cluster]
ndb-connectstring=192.168.1.120     # IP address of Management Node

mkdir -p /var/lib/mysql-cluster

ndbd

results:

2016-03-22 19:35:56 [ndbd] INFO     -- Angel connected to ‘192.168.1.120:1186‘
2016-03-22 19:35:56 [ndbd] INFO     -- Angel allocated nodeid: 2

技术分享

db4/db5配置:

cd ~
wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar
tar -xvf MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar

yum -y install perl-Data-Dumper
yum -y remove mariadb-libs

cd ~
rpm -Uvh MySQL-Cluster-client-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-server-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-shared-gpl-7.4.10-1.el7.x86_64.rpm

vi /etc/my.cnf

[mysqld]
ndbcluster
ndb-connectstring=192.168.1.120       # IP address for server management node
default_storage_engine=ndbcluster     # Define default Storage Engine used by MySQL
 
[mysql_cluster]
ndb-connectstring=192.168.1.120       # IP address for server management node

service mysql start

 集群监控:

ndb_mgm
ndb_mgm> show

技术分享

ndb_mgm -e "all status"
ndb_mgm -e "all report memory"

在db4或者在db5 测试集群:

mysql -u root -p

CREATE USER ‘root‘@‘%‘ IDENTIFIED BY ‘aqwe123‘;

select user, host, password from mysql.user;

GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY PASSWORD ‘*94CC7BF027327993D738E11...(Encrypted PASSWORD)‘ WITH GRANT OPTION;

技术分享

最后的结果:

技术分享

db5上也出现结果:

技术分享

他们说问题多,主流的是mycat+mysql。明天再折腾。

centos7 mysql cluster集群搭建基于docker

标签:wget   blog   set   bsp   ref   dir   nbsp   address   srv   

原文地址:http://www.cnblogs.com/Jt00/p/7275059.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!