Home Database Mysql Tutorial MySQL 多主多活 Galera 集群部署使用_MySQL

MySQL 多主多活 Galera 集群部署使用_MySQL

May 30, 2016 pm 05:10 PM
cluster

Galera是一款可以让MySQL同步复制的工具,实现真正的双主、多主,客户端连接到不同的MySQL实例进行读写操作就跟操作同一个实例一样,多个MySQL之间的数据是完全一致的。Galera主要是在保证数据一致性的前提下提高整体读的吞吐量,因此比MySQL自带主从方式更好。

 

Galera并没有分表分库功能,如果想要使用Galera,又想分表分库,可与Cobar结合使用,Cobar下如果使用Galara可以获得更高的可靠性,数据一致性,避免有些Cobar切换了主从,而另外一些没切换带来的数据不一致问题。

 

 

第一步:下载安装

 

使用galera时,还需要一个Galera库,官方下载地址是http://galeracluster.com/downloads/  。

Galera需要的MySQL/MariaDB版本有一个额外wsrep的补丁,因此不能直接用普通的版本。MySQL的版本可以从Galera的官网下载到,目前提供5.5和5.6两个版本。

MariaDB的版本可以从MariaDB的官网下载到https://downloads.mariadb.org/mariadb-galera/  ,MariaDB的10.0对应MySQL的5.6。

 

源码编译galera前需要安装的依赖库有boost,scons,check,openssl的开发版,您可根据自己的情况安装。galera使用scons安装,因此跟常规的命令不同,其实只要执行一个脚本即可。

 

$ scripts/build.sh

编译后在当前目录下生成libgalera_smm.so文件。

 

 

第二步:配置

 

Galera只需要在MySQL的配置文件my.cnf中增加几行wsrep相关内容即可

 

[mysqld]

# 配置前面编译出来的libgalera_smm.so文件路径

wsrep_provider  = /home/lyw/c2/galera-3-25.3.12/libgalera_smm.so

 

# 配置整个集群各实例的ip:port

wsrep_cluster_address   = 'gcomm://192.168.1.8:24011,192.168.1.8:24021,192.168.1.8:24031'

 

# 配置自己的ip:port,每个配置各不相同

wsrep_node_address      = '192.168.1.8:24011'

其他配置根据自己的情况配置。我这里配置了3个,my11.cnf,my21.cnf,my31.cnf。

 

 

第三步:初始化

 

初始化同MySQL一样,对每个数据库执行一下 mysql_install_db 脚本即可:

 

$ scripts/mysql_install_db --defaults-file=etc/my11.cnf

$ scripts/mysql_install_db --defaults-file=etc/my21.cnf

$ scripts/mysql_install_db --defaults-file=etc/my31.cnf

 

第四步:启动

 

前面配置的三台MySQL,我们先启动第一台,需要设置 --wsrep_cluster_address=gcomm:// 参数:

 

$ bin/mysqld_safe --defaults-file=etc/my11.cnf --wsrep_cluster_address=gcomm:// &

 

等待第一台启动成功后,我们启动后面两台,这个时候不需要上面的参数,实际上是使用了配置文件中的值:

 

$ bin/mysqld_safe --defaults-file=etc/my21.cnf  &

$ bin/mysqld_safe --defaults-file=etc/my31.cnf  &

这样就整个集群就启动好了,以后如果有某进程挂了,需要重启,就不需要加--wsrep_cluster_address参数。

 

 

第五步:测试

 

启动好后我们要测试下是否真的成功。我这里使用mysql客户端,您可使用自己喜欢的客户端工具,注意这里连接的端口是MySQL的端口,而不是上面Galera的端口。

$ bin/mysql -uroot -h127.0.0.1 -P14011
MariaDB [(none)]> create database lyw;

$ bin/mysql -uroot -h127.0.0.1 -P14021
MariaDB [(none)]> show databases like 'lyw';
+----------------+
| Database (lyw) |
+----------------+
| lyw            |
+----------------+
1 row in set (0.00 sec)

$ bin/mysql -uroot -h127.0.0.1 -P14031
MariaDB [(none)]> show databases like 'lyw';
+----------------+
| Database (lyw) |
+----------------+
| lyw            |
+----------------+
1 row in set (0.00 sec)
Copy after login

可见在一个库里作了一个操作,在其他库中也有了相同的修改,Galera启动成功。

我们也可以查看wsrep相关的参数判断是否启动成功:

MariaDB [(none)]> show variables like 'wsrep_on';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wsrep_on      | ON    |
+---------------+-------+

MariaDB [(none)]> show status like 'wsrep_connected';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| wsrep_connected | ON    |
+-----------------+-------+

MariaDB [(none)]> show status like 'wsrep_ready';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wsrep_ready   | ON    |
+---------------+-------+
Copy after login

 

wsrep_on 值为ON则说明启动成功。

wsrep_connected值为ON说明连接到了集群。

wsrep_ready值为ON说明已经准备好接受SQL请求了。该值最关键。

wsrep打头的参数都是跟galera相关的,其他的在使用中慢慢研究了。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

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

Optimization method of database in PHP high concurrency environment Optimization method of database in PHP high concurrency environment Aug 11, 2023 pm 03:55 PM

PHP database optimization method in high concurrency environment With the rapid development of the Internet, more and more websites and applications need to face high concurrency challenges. In this case, database performance optimization becomes particularly important, especially for systems that use PHP as the back-end development language. This article will introduce some database optimization methods in PHP high concurrency environment and give corresponding code examples. Using connection pooling In a high-concurrency environment, frequent creation and destruction of database connections may cause performance bottlenecks. Therefore, using connection pooling can

How to use Docker to manage and expand multi-node clusters How to use Docker to manage and expand multi-node clusters Nov 07, 2023 am 10:06 AM

In today's cloud computing era, containerization technology has become one of the most popular technologies in the open source world. The emergence of Docker has made cloud computing more convenient and efficient, and has become an indispensable tool for developers and operation and maintenance personnel. The application of multi-node cluster technology is widely used based on Docker. Through multi-node cluster deployment, we can utilize resources more efficiently, improve reliability and scalability, and also be more flexible in deployment and management. Next, we will introduce how to use Docker to

What are the common clusters in php? What are the common clusters in php? Aug 31, 2023 pm 05:45 PM

Common clusters in PHP include LAMP cluster, Nginx cluster, Memcached cluster, Redis cluster and Hadoop cluster. Detailed introduction: 1. LAMP cluster. LAMP refers to a combination of Linux, Apache, MySQL and PHP. It is a common PHP development environment. In a LAMP cluster, multiple servers run the same application and are balanced through a load balancer. Requests are distributed to different servers; 2. Nginx cluster, Nginx is a high-performance web server and so on.

How to use MongoDB to implement data clustering and load balancing functions How to use MongoDB to implement data clustering and load balancing functions Sep 19, 2023 pm 01:22 PM

How to use MongoDB to implement data clustering and load balancing functions Introduction: In today's big data era, the rapid growth of data volume has put forward higher requirements for database performance. In order to meet these requirements, data clustering and load balancing have become indispensable technical means. As a mature NoSQL database, MongoDB provides rich functions and tools to support data clustering and load balancing. This article will introduce how to use MongoDB to implement data clustering and load balancing functions, and provide specific code

Server cluster implementation method in Workerman documentation Server cluster implementation method in Workerman documentation Nov 08, 2023 pm 08:09 PM

Workerman is a high-performance PHPSocket framework that allows PHP to handle asynchronous network communication more efficiently. In Workerman's documentation, there are detailed instructions and code examples on how to implement a server cluster. In order to implement a server cluster, we first need to clarify the concept of a server cluster. A server cluster connects multiple servers to a network to improve system performance, reliability and scalability by sharing loads and resources. In Workerman, you can use the following two methods

How to configure the cluster environment of MySQL database? How to configure the cluster environment of MySQL database? Jul 12, 2023 pm 02:52 PM

How to configure the cluster environment of MySQL database? Introduction: With the development of the Internet and the continuous growth of data volume, the database has become one of the core systems necessary for every enterprise. At the same time, in order to ensure high data availability and read and write performance requirements, database cluster environments have gradually become the choice of enterprises. This article will introduce how to configure the cluster environment of MySQL database and provide corresponding code examples. 1. Environment preparation Before configuring the cluster environment of the MySQL database, we need to ensure that the following environment preparations have been completed: Install M

MySQL cluster deployment and maintenance project experience summary MySQL cluster deployment and maintenance project experience summary Nov 02, 2023 pm 01:33 PM

MySQL cluster deployment and maintenance project experience summary MySQL is one of the most commonly used databases in Internet application development. As the business scale continues to expand, stand-alone MySQL can no longer meet the demand. Therefore, it is necessary to consider using the MySQL cluster solution to expand the performance and capacity of the database. . This article summarizes the experience and lessons learned in the MySQL cluster deployment and maintenance process, hoping to be helpful to everyone's MySQL cluster deployment and maintenance work. 1. Deployment and architecture design of MySQL cluster MySQL cluster

See all articles