Home Database Mysql Tutorial Linux下构建MySQL集群

Linux下构建MySQL集群

Jun 07, 2016 pm 04:43 PM
mysql cluster or database

使用6台RHEL 6.5虚拟机,如图所示。其中sql1和sql2作为SQL节点,ndb1和ndb2作为数据节点,mgmsvr作为管理节点,这5个构成MySQL集

一、目标

1.安装MySQL-Cluster相关软件包。

2.依次配置管理/数据/SQL节点。

3.启动并测试MySQL-Cluster集群架构。

二、方案

使用6台RHEL 6.5虚拟机,如图所示。其中sql1和sql2作为SQL节点,ndb1和ndb2作为数据节点,mgmsvr作为管理节点,这5个构成MySQL集群体系的5个节点应安装Cluster版的MySQL相关软件包;测试用的Linux客户机只需安装普通版的MySQL-client即可。

Linux下构建MySQL集群

--------------------------------------分割线 --------------------------------------

Ubuntu 14.04下安装MySQL

《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

Ubuntu 14.04下搭建MySQL主从服务器

Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群

Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb

MySQL-5.5.38通用二进制安装

--------------------------------------分割线 --------------------------------------

三、实现

1、准备工作

 1)确认各节点服务器的IP地址,使各节点能互通,防火墙和selinux处于关闭状态。

关闭防火墙:

    # iptables -F                      //清空防火墙条目

    # service iptables stop      //关闭防火墙

    # chkconfig iptables off    //开机不自启

关闭selinux:

  vim打开 /etc/selinux/config修改SELINUX=disabled 

  # getenforce 0

2)卸载所有节点上的冲突包

官方提供的MySQL-Cluster相关软件包(可在这里获得  )已集成数据库服务端/客户端程序,因此可直接用来替换普通的MySQL服务端/客户端程序。如果已安装有普通版的mysql-server、mysql、MySQL-server、MySQL-client包,先将其卸载(若没有则忽略):

  # rpm -qa | grep -i mysql        //检查有没有安装普通版的mysql软件

对于RHEL自带的mysql-libs暂时保留(如果直接卸载会因为依赖关系删除许多重要的包,比如crontab、postfix等),但在安装MySQl-Cluster相关包的时候采用“-U”升级的方式执行替换。

  # rpm -e --nodeps MySQL-client

如果有残留的/etc/my.cnf文件,确保已转移备用或直接删除。

  # mv /etc/my.cnf /etc/my.cnf.bak

3)在所有节点上,解压下载的MySQL-Cluster集合包

  # tar xvf MySQL-Cluster-gpl-7.3.3-1.el6.x86_64.rpm-bundle.tar

  MySQL-Cluster-shared-gpl-7.3.3-1.el6.x86_64.rpm


  MySQL-Cluster-shared-compat-gpl-7.3.3-1.el6.x86_64.rpm    //安装共享库和兼容包

  MySQL-Cluster-server-gpl-7.3.3-1.el6.x86_64.rpm                //安装服务端程序

  MySQL-Cluster-client-gpl-7.3.3-1.el6.x86_64.rpm                //安装客户端程序

  MySQL-Cluster-test-gpl-7.3.3-1.el6.x86_64.rpm

  MySQL-Cluster-devel-gpl-7.3.3-1.el6.x86_64.rpm

  MySQL-Cluster-embedded-gpl-7.3.3-1.el6.x86_64.rpm

 

在SQL节点(sql1、sql2)服务器上,修改MySQL数据库的root密码:

  [root@sql1 ~]# service mysql start        //启动MySQL服务程序

  Starting MySQL... [确定]

  [root@sql2 ~]# cat /root/.mysql_secret

  # The random password set for the root user at Wed Sep  3 21:04:20 2014 (local time): msA7Bq2B

 

  [root@sql1 ~]# mysql –u root –pmsA7Bq2B            //以上述默认密码登录

    mysql> set password=password("123456");

    Query OK, 0 rows affected (0.17 sec)

在数据节点(ndb1、ndb2)和管理节点(mgmsvr)上,实际上并不需要启动MySQL服务程序,因此建议将mysql服务的自启状态设为关闭

  [root@ndb1 ~]# chkconfig mysql off

4)在sql节点添加授权数据库用户

在SQL节点(sql1、sql2)服务器上,添加相应的授权数据库用户,以方便客户端使用数据库服务。以用户user为例,允许其从192.168.4.0/24网段访问:

 

  mysql> grant all on *.* to user@'192.168.4.%' identified by "123456"; 

  Query OK, 0 rows affected (0.03 sec)

 

2、配置管理节点mgmsvr(192.168.4.3)

 1)创建工作文件夹

为管理节点提供一个工作目录,方便记录mysql集群相关的日志消息:

  [root@mgmsvr ~]# mkdir /var/log/mysql-cluster

 2)创建配置文件

在管理节点的配置文件中,应涵盖所有节点的设置,主要包括各节点的ID号、主机名或IP地址、工作目录等信息。

针对本实验,管理节点的配置参考如下:

  [root@mgmsvr ~]# cat /etc/config.ini    //文件名可以随意

  [ndbd default]                //为所有的节点指定默认配置

  NoOfReplicas=2//保留2份数据拷贝

  DataMemory=80M//数据缓存大小

  IndexMemory=18M//索引缓存大小

  [ndb_mgmd]//指定一个管理节点的配置,可以有多个管理节点

  nodeid=3//节点的id号,作为节点的唯一识别码,不可以与其他节点相同

  hostname=192.168.4.3  //节点的ip地址

  datadir=/var/log/mysql-cluster  //该管理节点的工作目录

  [ndbd]//指定数据节点的配置,,每个数据节点对应一个ndbd配置

  nodeid=4

  hostname=192.168.4.4     

  datadir=/var/log/mysql-cluster/data

  [ndbd]

  nodeid=5

  hostname=192.168.4.5

  datadir=/var/log/mysql-cluster/data

  [mysqld]//指定SQL节点的配置,每个SQL节点对应一个配mysqld置

  nodeid=6

  hostname=192.168.4.6

  [mysqld]

  nodeid=7

  hostname=192.168.4.7

更多详情见请继续阅读下一页的精彩内容:

linux

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 does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

See all articles