centos7.5部署mysql cluster NDB总结

Posted yancao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7.5部署mysql cluster NDB总结相关的知识,希望对你有一定的参考价值。

架构:

192.168.188.101 (NDB mgmd节点;sql节点01)
192.168.188.102  (sql节点02)
192.168.188.103  (NDBD节点01)
192.168.188.104    (NDBD节点02)
192.168.188.105      (LVS-01)
192.168.188.106      (LVS-02)
192.168.188.188         (WEB前端)

 

 

一、NDB mgmd节点

安装好centos 7.5后

1、关闭selinux和防火墙

sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config
setenforce 0
systemctl stop firewalld.service
systemctl disable firewalld.service

=========================================================

2、更新yum库

yum -y update

========================================

3、下载mysql安装包

wget https://downloads.mysql.com/archives/get/file/mysql-cluster-gpl-7.6.6-linux-glibc2.12-x86_64.tar.gz

解压:

tar -xvf mysql-cluster-gpl-7.6.6-linux-glibc2.12-x86_64.tar.gz  

剪切文件到/usr/local/mysql目录

mv mysql-cluster-gpl-7.6.6-linux-glibc2.12-x86_64 /usr/local/mysql

创建mysql cluster文件夹并创建配置文件

mkdir -p /data/mysql/mysql-cluster

 cd /data/mysql/mysql-cluster

 vim mgmd.cnf

[ndbd default]

NoOfReplicas=2
DataMemory=80M
IndexMemory=18M

[ndb_mgmd]

hostname=192.168.188.101
datadir=/data/mysql/mysql-cluster

[ndbd]

hostname=192.168.188.103
datadir=/usr/local/mysql/data

[ndbd]

hostname=192.168.188.104
datadir=/usr/local/mysql/data

[mysqld]

hostname=192.168.188.101

[mysqld]

hostname=192.168.188.102

[mysqld]

  

启动mysql cluster集群

/usr/local/mysql/bin/ndb_mgmd -f mgmd.cnf 

查看进程情况

[[email protected] mysql-cluster]# ps -ef|grep mgmd|grep -v grep
root 43958 1 0 19:28 ? 00:00:00 /usr/local/mysql/bin/ndb_mgmd -f mgmd.cnf

[[email protected] mysql-cluster]# /usr/local/mysql/bin/ndb_mgm 192.168.188.101
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: 192.168.188.101:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from 192.168.188.103)
id=3 (not connected, accepting connect from 192.168.188.104)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.188.101 (mysql-5.7.22 ndb-7.6.6)

[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from 192.168.188.101)
id=5 (not connected, accepting connect from 192.168.188.102)
id=6 (not connected, accepting connect from any host)

ndb_mgm>

其他sql节点和NDB节点未部署,所以提示没连接;

二、sql节点:

安装好centos 7.5后

1、关闭selinux和防火墙

sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config
setenforce 0
systemctl stop firewalld.service
systemctl disable firewalld.service

=========================================================

2、更新yum库

yum -y update

========================================

3、下载mysql安装包

wget https://downloads.mysql.com/archives/get/file/mysql-cluster-gpl-7.6.6-linux-glibc2.12-x86_64.tar.gz

解压:

tar -xvf mysql-cluster-gpl-7.6.6-linux-glibc2.12-x86_64.tar.gz  

剪切文件到/usr/local/mysql目录

mv mysql-cluster-gpl-7.6.6-linux-glibc2.12-x86_64 /usr/local/mysql

创建data文件夹并创建配置文件

mkdir -p /usr/local/mysqldata

 

=======================================

配置mysql文件
vim /etc/my.cnf

[client]
socket=/usr/local/mysql/mysql.sock
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
ndbcluster
ndb-connectstring=192.168.188.101 #管理节点ip
[mysql_cluster]
ndb-connectstring=192.168.188.101 #管理节点ip
bind-address = 0.0.0.0

  

 

初始化MYsql数据库:
cd /usr/local/mysql
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql .
chgrp -R mysql .
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

记录下初始化后mysql的root密码

A temporary password is generated for [email protected]: v:u-LSj,j7Nr

改回授权

[[email protected] mysql]# chown -R root .
[[email protected] mysql]# chown -R mysql data

查找默认的mysql.sock目录软连接自定义的mysql.sock目录

find / -name mysql.sock

ln -s /tmp/mysql.sock /usr/local/mysql/mysql.sock

添加系统启动项

cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
service mysql start

添加全局变量:

vim /etc/profile
PATH=$PATH:/usr/local/mysql:/usr/local/mysql/bin
export PATH
wq
source /etc/profile

service mysql restart

cd //usr/local/mysql/
bin/mysqladmin -uroot -p password ‘2285003‘ #修改密码

mysql -u root -p  #登录mysql

其他多台也同样重复配置即可;

=========================================

 三、NDBD服务器部署

安装好centos 7.5后

1、关闭selinux和防火墙

sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config
setenforce 0
systemctl stop firewalld.service
systemctl disable firewalld.service

=========================================================

2、更新yum库

yum -y update

========================================

3、下载mysql安装包

wget https://downloads.mysql.com/archives/get/file/mysql-cluster-gpl-7.6.6-linux-glibc2.12-x86_64.tar.gz

解压:

tar -xvf mysql-cluster-gpl-7.6.6-linux-glibc2.12-x86_64.tar.gz  

剪切文件到/usr/local/mysql目录

mv mysql-cluster-gpl-7.6.6-linux-glibc2.12-x86_64 /usr/local/mysql

创建data文件夹并创建配置文件

mkdir -p /usr/local/mysqldata

编辑mysql配置文件

[[email protected] ~]# vim /etc/my.cnf

[mysqld]

ndbcluster #运行NDB存储引擎

ndb-connectstring=192.168.188.101 #定位管理节点

[mysql_cluster]

ndb-connectstring=192.168.188.101 #定位管理节点

  

第一次连接需要加上 --initial连接成功后以后都不要加这个参数;

 /usr/local/mysql/bin/ndbd  --initial --ndb-connectstring=192.168.188.101

连接成功后查看进程

[[email protected] data]# ps -ef | grep nbd
root 43974 1272 0 20:11 pts/0 00:00:00 grep --color=auto nbd

其他多台也同样重复配置即可;

============================================================================

回到NDB-mgmd节点查看状态:

[[email protected] ~]# /usr/local/mysql/bin/ndb_mgm 192.168.188.101
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: 192.168.188.101:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.188.103 (mysql-5.7.22 ndb-7.6.6, Nodegroup: 0, *)
id=3 @192.168.188.104 (mysql-5.7.22 ndb-7.6.6, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.188.101 (mysql-5.7.22 ndb-7.6.6)

[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from 192.168.188.101)
id=5 (not connected, accepting connect from 192.168.188.102)
id=6 @192.168.188.101 (mysql-5.7.22 ndb-7.6.6)

ndb_mgm>

 

这样就完成了mysql cluster NDB部署,后面再补上lvs+keepalive的部署;

注意:NDB高可用集群只支持用NDB引擎创建的表在各节点同步,sql库的权限也是独立的,所以还需要做集群后mysql用户权限同步;

 






















































以上是关于centos7.5部署mysql cluster NDB总结的主要内容,如果未能解决你的问题,请参考以下文章

Centos7.5安装mysql5.7.24二进制包方式部署

Centos7.5安装mysql5.7.24二进制包方式部署(主从复制)

Centos7.5安装mysql5.7.24二进制包方式部署(keepalived+主从复制)

mysql-cluster 7.3.5安装部署

Mysql部署

Mysql部署