centos7 mysql cluster集群搭建基于docker
Posted Jt00
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7 mysql cluster集群搭建基于docker相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
MySQL 8.0.11 innodb cluster 运维管理手册之二--集群搭建
docker swarm使用keepalived+haproxy搭建基于percona-xtradb-cluster方案的高可用mysql集群