search
HomeDatabaseMysql TutorialLinux下构建MySQL集群

使用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
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

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

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)