Home Database Mysql Tutorial Redhat6.5下MySQL5.6集群配置完整版

Redhat6.5下MySQL5.6集群配置完整版

Jun 07, 2016 pm 02:52 PM
Prepare Configuration cluster

1、准备三台服务器 2、为三台机器分别安装Linux操作系统(Oracle Linux / RHEL 6.5 x86_64bit) 3、分别IP地址 管理节点 192.168.1.110 (负责管理整个集群) SQL节点 192.168.1.111 (负责操作数据库) SQL节点 192.168.1.112 (负责操作数据库) 数据节点 192.168.

1、准备三台服务器

2、为三台机器分别安装Linux操作系统(Oracle Linux / RHEL 6.5 x86_64bit)

3、分别IP地址

管理节点      192.168.1.110         (负责管理整个集群)

SQL节点       192.168.1.111         (负责操作数据库)

SQL节点       192.168.1.112         (负责操作数据库)

数据节点      192.168.1.111         (负责存储数据)

数据节点      192.168.1.112         (负责存储数据)


SQL节点和数据节点可以同在一台机器上


4、修改三台服务器的/etc/hosts文件,修改完后的内容如下:

127.0.0.1    localhost    localhost.domain

192.168.1.110    node01

192.168.1.111    node02

192.168.1.112    node03

5、修改三台服务器的/etc/sysconfig/nework文件,修改完后的内容分别如下:

NETWORKING=yes

HOSTNAME=node01

GATEWAY=192.168.1.1    (网关地址因所处网络的不同而不同)


NETWORKING=yes

HOSTNAME=node02

GATEWAY=192.168.1.1    (网关地址因所处网络的不同而不同)

  

NETWORKING=yes

HOSTNAME=node03

GATEWAY=192.168.1.1    (网关地址因所处网络的不同而不同)


6、分别重启三台服务器


7、下载NDB集群软件mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz  

集群软件有三种格式:

a、以tar.gz结尾的二制进格式

b、以rpm结尾的rpm包形式

c、以源文件编译安装方式


rpm包安装方式,由于是自动安装的,所以不方便配置软件安装位置和数据存储位置


所以通常选用.tar.gz结尾的二进制格式的安装文件


注意:mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz包含了mysql数据库软件和NDB集群软件


8、分别复制mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz文件到三台服务器上的/usr/local/目录下


9、新建用户mysql

# groupadd mysql

# useradd -r -g mysql mysql      (由于mysql用户只是用于安装配置NDB集群或mysql软件,而不用用于登陆系统)

   (所以以-r参数来创建mysql用户,并且不用为该用户设置密码)


10、分别在三台服务器上解压mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz文件


# cd /usr/local

# tar zxvf mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz

# ln -s mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64  mysql

# chown -R mysql.mysql mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64

# cd mysql

# chown -R mysql.mysql .

配置完成以后,结果如下



11、在192.168.1.111和192.168.1.112两个数据节点(两台服务器)上安装mysql数据库软件

由于是二进制安装,所以mysql数据库软件就安装在/usr/local/mysql下,

     但数据库的数据可以存放到其它地方,如/u01/app/mysql/data/下面

注意:以下命令在两台数据节点服务器上都要执行

# mkdir -p /u01/app/mysql/data

# chown -R mysql.mysql /u01

# cd /usr/local/mysql

# scripts/mysql_install_db --basedir=/usr/local/mysql  --datadir=/u01/app/mysql/data --user=mysql

执行完这条命令以后,数据库的数据文件(包括mysql,test , performance_schema等数据库)就被安装到了

/u01/app/mysql/data目录下了


# cp bin/ndbd   /usr/local/bin/

# cp bin/ndbmtd /usr/local/bin/

然后将启动数据库服务的启动文件复制到/etc/rc.d/init.d/目录下


# cp support-files/mysql.server   /etc/rc.d/init.d/mysqld     (改名)

执行完上面这条命令以后,就可以使用service mysqld start | stop | restart命令来管理数据库服务了


# cp my.cnf  /etc/my.cnf

# vi /etc/my.cnf

[mysqld]

ndbcluster

basedir=/usr/local/mysql

datadir=/u01/app/mysql/data

port=3306

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


[mysql_cluster]

ndb-connectstring=192.168.1.110

再次注意:以上命令在两台数据节点服务器上都要执行

到此,数据节点和SQL节点的安装配置就结束了,如果数据节点和SQL节点是分开在不同的机器上,则每个数据节点

和每个SQL节点都要执行以上命令。


12、在管理节点上进行安装配置

由于第10步已经解压缩mysql-cluster-advanced-7.3.5-linux-glibc2.5-x86_64.tar.gz 安装包到了/usr/local

目录下,并进行了软连接等操作,所以这些工作就不用重复做了,接着往下配置即可


# cd /usr/local/mysql 

# mkdir mysql-cluster     (创建mysql-cluster目录,后面启动集群管理服务时要用)

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

# cd /var/lib

# mkdir mysql-cluster

# cd mysql-cluster

# vi config.ini  (这是管理节点上的集群配置文件,很重要) 

[ndbd default]

NoOfReplicas=1    # Number of replicas

DataMemory=80M    # How much memory to allocate for data storage

IndexMemory=18M   # How much memory to allocate for index storage

                 # For DataMemory and IndexMemory, we have used the

                  # default values. Since the "world" database takes up

                  # only about 500KB, this should be more than enough for

                  # this example Cluster setup.


[tcp default]

                  # This the default; however, you can use any

                  # port that is free for all the hosts in the cluster

                  # Note: It is recommended that you do not specify the port

                  # number at all and simply allow the default value to be used

                  # instead


[ndb_mgmd]

hostname=192.168.1.110           # Hostname or IP address of MGM node

datadir=/var/lib/mysql-cluster   # Directory for MGM node log files

NodeId=1


[ndbd]

hostname=192.168.1.111        # Hostname or IP address

datadir=/u01/app/mysql/data   # Directory for this data node's data files

NodeId=2


[ndbd]

hostname=192.168.1.112        # Hostname or IP address

datadir=/u01/app/mysql/data   # Directory for this data node's data files

NodeId=3

[mysqld]

hostname=192.168.1.111        # Hostname or IP address

NodeId=4                      # (additional mysqld connections can be

                              # specified for this node for various

                              # purposes such as running ndb_restore)


[mysqld]

hostname=192.168.1.112        # Hostname or IP address

NodeId=5                      # (additional mysqld connections can be

                              # specified for this node for various

                              # purposes such as running ndb_restore)


配置说明:

[ndbd default]                这部分是公共部分,对于每一个数据节点都有效,只需要配置一份

NoOfReplicas=1                数据镜像几份(各数据节点之间相互备份)


[tcp default]                 针对每个数据节点及管理节点之间使用哪个端口进行通讯,

                              在旧版本的NDB集群软件配置时,这个地方通常配置portnumber=2202

                              但新版的NDB软件这里不需要配置,并且MySQL官方也强烈建议不要配置


[ndb_mgmd]                     管理节点的配置部分(通常只有一个)

                               注意NodeId=1指明管理节点的节点ID为1,如果不指定,在启动集群时,会报错

hostname=192.168.1.110           指明管理节点的IP地址

datadir=/var/lib/mysql-cluster   指明集群管理日志存放的位置


[ndbd]                         数据节点配置部分,有几个数据节点就配置几个[ndbd]

hostname=192.168.1.111         指明数据节点的IP地址

datadir=/u01/app/mysql/data    指明数据节点上的数据库文件存放的位置

NodeId=2                       指明该数据节点在整个集群中的nodeid号(很重要)



[mysqld]                       SQL节点配置部分,有几个SQL节点,就配置几个[mysqld]


13、配置好上面的所有配置以后就可以在管理节点上启动怎个集群了


注意: 在管理节点上,不用执行/usr/local/mysql/scripts/mysql_install_db  --basedir=   --datadir=   --user=命令

来安装数据库了。


# ndb_mgmd -f /var/lib/mysql-cluster/config.ini   (第一次启动时这样执行,如果后面新添加了数据节点)

 (执行此命令时,需要带上--initital参数,否则新添加的节点)

 (无法被识别)

 (# ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial)


# ndb_mgm              (查看启动后的集群状态,看看集群是否成功启动,如果看到以下内容,表示集群已经成功配置并启动)

[root@mysql01 mysql-cluster]# ndb_mgm

-- NDB Cluster -- Management Client --

ndb_mgm> show

Connected to Management Server at: localhost:1186

Cluster Configuration

---------------------

[ndbd(NDB)]     2 node(s)

id=2 (not connected, accepting connect from 192.168.1.111)

id=3 (not connected, accepting connect from 192.168.1.112)


[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.1.110  (mysql-5.6.17 ndb-7.3.5)


[mysqld(API)]   2 node(s)

id=4 (not connected, accepting connect from 192.168.1.111)

id=5 (not connected, accepting connect from 192.168.1.112)

现在看到集群中包含两个数据节点、一个管理节点、两个SQL节点,但是数据节点和SQL节点都还没有启动,

所以显示的连接状态是not connected


14、分别登陆两台数据节点执行以下命令启动数据节点

# ndbd --initial    (第一次启动时,需要加--initial来初始化数据节点,第二次启动时,就不需要这个参数了)

[root@mysql02 support-files]# ndbd --initial

2014-06-12 05:42:04 [ndbd] INFO     -- Angel connected to '192.168.1.110:1186'

2014-06-12 05:42:04 [ndbd] INFO     -- Angel allocated nodeid: 2


[root@mysql03 bin]# ndbd  --initial

2014-06-12 05:41:38 [ndbd] INFO     -- Angel connected to '192.168.1.110:1186'

2014-06-12 05:41:38 [ndbd] INFO     -- Angel allocated nodeid: 3


15、再登陆到管理节点查看现在整个集群的状态

ndb_mgm> show 

Cluster Configuration

---------------------

[ndbd(NDB)]     2 node(s)

id=2    @192.168.1.111  (mysql-5.6.17 ndb-7.3.5, Nodegroup: 0, *)

id=3    @192.168.1.112  (mysql-5.6.17 ndb-7.3.5, Nodegroup: 1)


[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.1.110  (mysql-5.6.17 ndb-7.3.5)


[mysqld(API)]   2 node(s)

id=4 (not connected, accepting connect from 192.168.1.111)

id=5 (not connected, accepting connect from 192.168.1.112)


现在可以看到,两个数据节点已经连接上来了,表示两个数据节点成功启动了


16、分别登陆到两个SQL节点上启动SQL节点

[root@mysql02 ~]# cd /usr/local/mysql/bin

[root@mysql02 bin]# ./mysqld_safe --user=mysql

140612 05:51:00 mysqld_safe Logging to '/u01/app/mysql/data/mysql02.err'.

140612 05:51:00 mysqld_safe Starting mysqld daemon with databases from /u01/app/mysql/data


[root@mysql03 ~]# cd /usr/local/mysql/bin

[root@mysql03 bin]# ./mysqld_safe  --user=mysql

140612 05:52:07 mysqld_safe Logging to '/u01/app/mysql/data/mysql03.err'.

140612 05:52:07 mysqld_safe Starting mysqld daemon with databases from /u01/app/mysql/data


17、再次回到管理节点查看整个集群的状态

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)]     2 node(s)

id=2    @192.168.1.111  (mysql-5.6.17 ndb-7.3.5, Nodegroup: 0, *)

id=3    @192.168.1.112  (mysql-5.6.17 ndb-7.3.5, Nodegroup: 1)


[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.1.110  (mysql-5.6.17 ndb-7.3.5)


[mysqld(API)]   2 node(s)

id=4    @192.168.1.111  (mysql-5.6.17 ndb-7.3.5)

id=5    @192.168.1.112  (mysql-5.6.17 ndb-7.3.5)


     到此整个集群就搭建完成,并成功启动运行了


18、安全关闭整个集群

首先登陆到两个SQL节点,执行service mysqld stop命令关闭SQL节点

[root@mysql02 ~]# service mysqld stop

Shutting down MySQL...... SUCCESS! 


[root@mysql03 ~]# service mysqld stop

Shutting down MySQL..... SUCCESS!

然后登陆到管理节点上,执行shutdown命令关闭整个集群

[root@mysql01 mysql-cluster]# ndb_mgm

-- NDB Cluster -- Management Client --

ndb_mgm> show

Connected to Management Server at: localhost:1186

Cluster Configuration

---------------------

[ndbd(NDB)]     2 node(s)

id=2 (not connected, accepting connect from 192.168.1.111)

id=3 (not connected, accepting connect from 192.168.1.112)


[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.1.110  (mysql-5.6.17 ndb-7.3.5)


[mysqld(API)]   2 node(s)

id=4 (not connected, accepting connect from 192.168.1.111)

id=5 (not connected, accepting connect from 192.168.1.112)


ndb_mgm> shutdown

1 NDB Cluster node(s) have shutdown.

Disconnecting to allow management server to shutdown.

ndb_mgm> exit


7 测试。


1、从SQL节点A登录,创建数据库和表,进行简单测试。


mysql> create database zxztest ;


mysql> use zxztest;

Database changed


mysql> create table test1(id int,name varchar(10)) engine=ndb ;


mysql> insert into test1 values(1,'zhaoxuezhi');


mysql> select * from test1 ;


+------+---------+

| id   | name    |

+------+---------+

|    1 | zhaoxuezhi | 

+------+---------+


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set up Git configuration in PyCharm How to set up Git configuration in PyCharm Feb 20, 2024 am 09:47 AM

Title: How to correctly configure Git in PyCharm In modern software development, the version control system is a very important tool, and Git, as one of the popular version control systems, provides developers with powerful functions and flexible operations. As a powerful Python integrated development environment, PyCharm comes with support for Git, allowing developers to manage code versions more conveniently. This article will introduce how to correctly configure Git in PyCharm to facilitate better development during the development process.

The perfect combination of PyCharm and PyTorch: detailed installation and configuration steps The perfect combination of PyCharm and PyTorch: detailed installation and configuration steps Feb 21, 2024 pm 12:00 PM

PyCharm is a powerful integrated development environment (IDE), and PyTorch is a popular open source framework in the field of deep learning. In the field of machine learning and deep learning, using PyCharm and PyTorch for development can greatly improve development efficiency and code quality. This article will introduce in detail how to install and configure PyTorch in PyCharm, and attach specific code examples to help readers better utilize the powerful functions of these two. Step 1: Install PyCharm and Python

The working principle and configuration method of GDM in Linux system The working principle and configuration method of GDM in Linux system Mar 01, 2024 pm 06:36 PM

Title: The working principle and configuration method of GDM in Linux systems In Linux operating systems, GDM (GNOMEDisplayManager) is a common display manager used to control graphical user interface (GUI) login and user session management. This article will introduce the working principle and configuration method of GDM, as well as provide specific code examples. 1. Working principle of GDM GDM is the display manager in the GNOME desktop environment. It is responsible for starting the X server and providing the login interface. The user enters

Understand Linux Bashrc: functions, configuration and usage Understand Linux Bashrc: functions, configuration and usage Mar 20, 2024 pm 03:30 PM

Understanding Linux Bashrc: Function, Configuration and Usage In Linux systems, Bashrc (BourneAgainShellruncommands) is a very important configuration file, which contains various commands and settings that are automatically run when the system starts. The Bashrc file is usually located in the user's home directory and is a hidden file. Its function is to customize the Bashshell environment for the user. 1. Bashrc function setting environment

How to configure workgroup in win11 system How to configure workgroup in win11 system Feb 22, 2024 pm 09:50 PM

How to configure a workgroup in Win11 A workgroup is a way to connect multiple computers in a local area network, which allows files, printers, and other resources to be shared between computers. In Win11 system, configuring a workgroup is very simple, just follow the steps below. Step 1: Open the "Settings" application. First, click the "Start" button of the Win11 system, and then select the "Settings" application in the pop-up menu. You can also use the shortcut "Win+I" to open "Settings". Step 2: Select "System" In the Settings app, you will see multiple options. Please click the "System" option to enter the system settings page. Step 3: Select "About" In the "System" settings page, you will see multiple sub-options. Please click

Simple and easy-to-understand PyCharm configuration Git tutorial Simple and easy-to-understand PyCharm configuration Git tutorial Feb 20, 2024 am 08:28 AM

PyCharm is a commonly used integrated development environment (IDE). In daily development, using Git to manage code is essential. This article will introduce how to configure Git in PyCharm and use Git for code management, with specific code examples. Step 1: Install Git First, make sure Git is installed on your computer. If it is not installed, you can go to [Git official website](https://git-scm.com/) to download and install the latest version of Git

How to configure and install FTPS in Linux system How to configure and install FTPS in Linux system Mar 20, 2024 pm 02:03 PM

Title: How to configure and install FTPS in Linux system, specific code examples are required. In Linux system, FTPS is a secure file transfer protocol. Compared with FTP, FTPS encrypts the transmitted data through TLS/SSL protocol, which improves Security of data transmission. In this article, we will introduce how to configure and install FTPS in a Linux system and provide specific code examples. Step 1: Install vsftpd Open the terminal and enter the following command to install vsftpd: sudo

Node completely evacuates from Proxmox VE and rejoins the cluster Node completely evacuates from Proxmox VE and rejoins the cluster Feb 21, 2024 pm 12:40 PM

Scenario description for nodes to completely evacuate from ProxmoxVE and rejoin the cluster. When a node in the ProxmoxVE cluster is damaged and cannot be repaired quickly, the faulty node needs to be kicked out of the cluster cleanly and the residual information must be cleaned up. Otherwise, new nodes using the IP address used by the faulty node will not be able to join the cluster normally; similarly, after the faulty node that has separated from the cluster is repaired, although it has nothing to do with the cluster, it will not be able to access the web management of this single node. In the background, information about other nodes in the original ProxmoxVE cluster will appear, which is very annoying. Evict nodes from the cluster. If ProxmoxVE is a Ceph hyper-converged cluster, you need to log in to any node in the cluster (except the node you want to delete) on the host system Debian, and run the command

See all articles