mysql-cluster集群搭建

2019-12-18 18:07:21 浏览数 (1)

1.环境介绍

官方网站下载mysql-cluster-gpl-7.5.7-linux-glibc2.12-x86_64.tar.gz (mysql集群)

管理节点:192.168.0.1

数据节点:192.168.0.2

数据节点:192.168.0.3

SQL节点:192.168.0.4

SQL节点:192.168.0.5

2.mysql配置文件/etc/my.cnf如下:

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[client]

port = 3306

socket = /usr/local/lnmp/mysql-cluster-7.5/mysql.sock

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# basedir = .....

# datadir = .....

# port = .....

# server_id = .....

# socket = .....

basedir = /usr/local/lnmp/mysql-cluster-7.5

datadir = /usr/local/lnmp/mysql-cluster-7.5/data

port = 3306

server_id = 1

socket = /usr/local/lnmp/mysql-cluster-7.5/mysql.sock

log-bin = /usr/local/lnmp/mysql-cluster-7.5/mysql-bin

expire_logs_days = 10

max_binlog_size = 100M

#general_log = 1

#general_log_file = /usr/local/lnmp/mysql-cluster-7.5/query.log

slow_query_log = 1

slow_query_log_file = /usr/local/lnmp/mysql-cluster-7.5/slow-query.log

long-query_time = 2

log-error = /usr/local/lnmp/mysql-cluster-7.5/error.log

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M 

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

3.分别在5台主机上安装mysql

/usr/local/lnmp/mysql-cluster-7.5/bin/mysqld --initialize --user=mysql

安装后启动并统一修改root密码为同一个,然后停止mysql

4.启动mysql管理节点

mysql管理节点配置文件/usr/local/lnmp/mysql-cluster-7.5/config.ini #(默认没有,需要手动生成)

[ndbd default] #每个数据节点的默认配置

NoOfReplicas = 1 #每个数据节点镜像的数量

DataMemory = 200M #每个数据节点中给数据分配的内存

IndexMemory = 20M #每个数据节点中给索引分配的内存

ServerPort = 2202 #使用的端口号

[ndb_mgmd] #配置管理节点

NodeId = 1 

HostName = 192.168.0.1

DataDir = /usr/local/lnmp/mysql-cluster-7.5/data #管理节点数据日志目录

[ndbd] #数据节点配置

NodeId = 2

HostName = 192.168.0.2

DataDir = /usr/local/lnmp/mysql-cluster-7.5/data #数据节点目录

[ndbd]

NodeId = 3

HostName = 192.168.0.3

DataDir = /usr/local/lnmp/mysql-cluster-7.5/data

[mysqld] #配置sql节点(连接数据库所用)

HostName = 192.168.0.4

[mysqld]

HostName = 192.168.0.5

启动管理节点192.168.0.1:

/usr/local/lnmp/mysql-cluster-7.5/bin/ndb_mgmd -f /usr/local/lnmp/mysql-cluster-7.5/config.ini --configdir=/usr/local/lnmp/mysql-cluster-7.5

5.修改mysql数据节点与SQL节点my.conf配置文件

主要添加

[mysql_cluster]

ndb-connectstring = 192.168.0.162 #管理节点IP

[mysqld]

ndbcluster

ndb-connectstring = 192.168.0.162 #管理节点IP

default-storage-engine=ndbcluster

user=mysql

修改结果如下:

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[mysql_cluster]

ndb-connectstring = 192.168.0.162

[client]

port = 3306

socket = /usr/local/lnmp/mysql-cluster-7.5/mysql.sock

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# basedir = .....

# datadir = .....

# port = .....

# server_id = .....

# socket = .....

ndbcluster

ndb-connectstring = 192.168.0.162

default-storage-engine=ndbcluster

user=mysql

basedir = /usr/local/lnmp/mysql-cluster-7.5

datadir = /usr/local/lnmp/mysql-cluster-7.5/data

port = 3306

server_id = 1

socket = /usr/local/lnmp/mysql-cluster-7.5/mysql.sock

log-bin = /usr/local/lnmp/mysql-cluster-7.5/mysql-bin

expire_logs_days = 10

max_binlog_size = 100M

#general_log = 1

#general_log_file = /usr/local/lnmp/mysql-cluster-7.5/query.log

slow_query_log = 1

slow_query_log_file = /usr/local/lnmp/mysql-cluster-7.5/slow-query.log

long-query_time = 2

log-error = /usr/local/lnmp/mysql-cluster-7.5/error.log

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M 

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

6.启动数据节点192.168.0.2和192.168.0.3

/usr/local/lnmp/mysql-cluster-7.5/bin/ndbd --initial #(只在首次启动使用)

7.启动SQL节点192.168.0.4和192.168.0.5

/usr/local/lnmp/mysql-cluster-7.5/support-files/mysql.server start

8.查看状态

/usr/local/lnmp/mysql-cluster-7.5/bin/ndb_mgmd

ndb_mgm > show

0 人点赞