未加星标

How to Install a MySQL Cluster on Ubuntu 16.04

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二03 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

mysql Cluster is a technology to provide high availability for MySQL Databases. It uses NDB (Network DataBase) or NDBCLUSTER as the database storage engine. MySQL Cluster is designed as multi-master ACID architecture with no single point of failure, it uses automatic sharding (partitioning) to scale out read and write processes.

To implement a MySQL Cluster, we need 3 different types of nodes:

Management Node ( ndb_mgmd ) Used for monitoring and configuring the cluster. Data Node ( ndbd ) These nodes are used to store the data they provide automatic sharding and can handle replication. SQL Node ( mysqld ) MySQL Server interfaces for connecting to all nodes.

In this tutorial, I will show you how to install a 'MySQL Cluster' on Ubuntu 16.04 LTS (Xenial Xerus).

Prerequisites 4 nodes with Ubuntu server 16.04 192.168.1.11 management-node 192.168.1.12 data-node1 192.168.1.13 data-node2 192.168.1.14 sql-node Root privileges on the nodes. Step 1 - Install and Configure the Management Node

In this step, we will install the management node for our cluster with IP address 192.168.1.11. We install MySQL cluster software and configure it as management node for the cluster.

Log in to the management node with ssh:

ssh[emailprotected]

TYPE YOUR PASSWORD

A. Install MySQL Cluster Management Node

Open the MySQL cluster site here and choose the option ' linux-generic ' and download the 64-bit package by clicking the ' Download ' button.

Download the MySQL cluster package with wget and extract it.

wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.12-linux-glibc2.5-x86_64.tar.gz

tar -xzvf mysql-cluster-gpl-7.4.12-linux-glibc2.5-x86_64.tar.gz

Rename directory to mysql:

mv mysql-cluster-gpl-7.4.12-linux-glibc2.5-x86_64/ mysql/

Go to the mysql directory and copy the 2 binary files for the cluster management command ' ndb_mgmd and ndb_mgm ' to the '/usr/local/bin/' directory, and then make them executable with the chmod command.

cd ~/mysql/

cp bin/ndb_mgm* /usr/local/bin/

chmod +x /usr/local/bin/ndb_mgm*

B. Configure MySQL Cluster Management Node

Configure the management node by creating a new directory 'mysql-cluster' for the configuration files in the '/var/lib/' directory.

Create a directory 'mysql-cluster' and create a new configuration 'config.ini' in the directory:

mkdir -p /var/lib/mysql-cluster/

vim /var/lib/mysql-cluster/config.ini

Paste the configuration below:

[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[mysqld default]
[ndb_mgmd default]
[tcp default]
# Cluster Control / Management node
[ndb_mgmd]
hostname=192.168.1.11
# Data Node 1
[ndbd]
hostname=192.168.1.12
DataDir= /var/lib/mysql-cluster
# Data Node 1
[ndbd]
HostName=192.168.1.13
DataDir=/var/lib/mysql-cluster
# SQL Node
[mysqld]
hostname=192.168.1.14
# If you to add new SQL Node
[mysqld]

Change the IP address of ndb_mgmd for management, ndbd for data node and mysqld for the sql node to match your setup.

Save the file and exit.

Next, start the management node process with the command below:

ndb_mgmd -f /var/lib/mysql-cluster/config.ini --configdir=/var/lib/mysql-cluster/

Make it to be started at boot time by adding command to ' /etc/rc.local ' file:

echo 'ndb_mgmd -f /var/lib/mysql-cluster/config.ini --configdir=/var/lib/mysql-cluster/' >> /etc/rc.local

If you see the results:

MySQL Cluster Management Server mysql-5.6.31 ndb-7.4.12

Then the management node process is running.

Check the management node with another command:

# Checking port 1186 used by ndb_mgmd

netstat -plntu

# Checking the management node is ready

ndb_mgm

show


How to Install a MySQL Cluster on Ubuntu 16.04
Step 2 - Install and Configure the Data Node

In this step, we will install the MySQL cluster software and configure it as data node. We will use 2 ubuntu 16.04 servers as data nodes: data-node1 with IP address 192.168.1.12 and data-node2 with IP address 192.168.1.13.

Log in to the data-node1 server with ssh:

ssh[emailprotected] A. Install MySQL Cluster on the Data Node

Before we install the MySQL cluster software, we need to install a new package ' libaio1 ' and create a new user and group mysql . Run the command below as root for that:

apt-get install libaio1

groupadd mysql

useradd -g mysql mysql

Now download the MySQL cluster package ' Linux-Generic ', extract and rename the directory to mysql.

wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.12-linux-glibc2.5-x86_64.tar.gz

tar -xzvf mysql-cluster-gpl-7.4.12-linux-glibc2.5-x86_64.tar.gz

mv mysql-cluster-gpl-7.4.12-linux-glibc2.5-x86_64/ mysql/

Move 'mysql' directory to '/ usr/local /' and go to that directory.

mv mysql /usr/local/

cd /usr/local/mysql/

Run the script for creating the system databases:

./scripts/mysql_install_db --user=mysql

If there is no error, copy the mysql service file to ' /etc/init.d ' directory and add the mysql start script to run at boot time.

cp support-files/mysql.server /etc/init.d/mysql

systemctl enable mysql

Next, move all mysql binary commands to the ' /usr/local/bin ' directory and create a new symlink.

mv bin/* /usr/local/bin/

rm -rf bin/

ln -s /usr/local/bin /usr/local/mysql/

Change the owner of the mysql directory to user root and group mysql, and change the data directory to mysql as owner.

chown -R root:mysql .

chown -R mysql data

B. Configure MySQL Cluster Data Node

Create a new mysql configuration file ' my.cnf ' with vim:

vim /etc/my.cnf

Paste configuration below:

# MySQL Config
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
# Run ndb storage engine
ndbcluster
# IP address management node
ndb-connectstring=192.168.1.11
[mysql_cluster]
# IP address management node
ndb-connectstring=192.168.1.11
# MySQL Pid and Log
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Save and exit.

Create a new directory for the data node's and change the ownership to the mysql user.

mkdir -p /var/lib/mysql-cluster/

chown -R mysql /var/lib/mysql-cluster

C. Start MySQL on the Data Node

Start the mysql service with the command below:

ndbd --initial

systemctl start mysql

Make sure there is no error, and the results are below (data-node2):


How to Install a MySQL Cluster on Ubuntu 16.04

MySQL on the data node is started. Now you can configure the MySQL password with the command:

mysql_secure_installation

or access the MySQL shell.

mysql -u root -p

NOTE:

Redo this step on ' data-node2 ' server IP address 192.168.1.13.

Step 3 -

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: SQLMySQLUbuntuLinuxXenSQL Server
分页:12
转载请注明
本文标题:How to Install a MySQL Cluster on Ubuntu 16.04
本站链接:http://www.codesec.net/view/482428.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(49)