如何在CentOS 7服务器上使用MariaDB配置Galera群集

介绍 (Introduction)

Clustering adds high availability to your database by distributing changes to different servers. In the event that one of the instances fails, others are quickly available to continue serving.

群集通过将更改分发到不同的服务器来增加数据库的高可用性。 万一其中一个实例发生故障,其他实例很快就可以继续使用。

Clusters come in two general configurations, active-passive and active-active. In active-passive clusters, all writes are done on a single active server and then copied to one or more passive servers that are poised to take over only in the event of an active server failure. Some active-passive clusters also allow SELECT operations on passive nodes. In an active-active cluster, every node is read-write and a change made to one is replicated to all.

群集有两种常规配置, 主动-被动主动-主动 。 在主动-被动群集中,所有写操作均在一台主动服务器上完成,然后复制到一个或多个被动服务器上,这些服务器准备仅在主动服务器发生故障时接管。 一些主动-被动群集还允许在被动节点上执行SELECT操作。 在双活群集中,每个节点都是可读写的,并且对一个节点所做的更改将被复制到所有节点。

MariaDB is an open source relational database system that is fully compatible with the popular MySQL RDBMS system. You can read the official documentation for MariaDB at this page. Galera is a database clustering solution that enables you to set up multi-master clusters using synchronous replication. Galera automatically handles keeping the data on different nodes in sync while allowing you to send read and write queries to any of the nodes in the cluster. You can learn more about Galera at the official documentation page.

MariaDB是一个开放源代码关系数据库系统,与流行MySQL RDBMS系统完全兼容。 您可以在此页面上阅读MariaDB的官方文档。 Galera是一种数据库群集解决方案,使您可以使用同步复制来设置多主群集。 Galera自动处理使不同节点上的数据保持同步的过程,同时允许您向集群中的任何节点发送读写查询。 您可以在官方文档页面上了解有关Galera的更多信息。

In this guide, you will configure an active-active MariaDB Galera cluster. For demonstration purposes, you will configure and test three CentOS 7 Droplets that will act as nodes in the cluster. This is the smallest configurable cluster.

在本指南中,您将配置一个主动-主动MariaDB Galera集群。 出于演示目的,您将配置和测试将用作集群中节点的三个CentOS 7 Droplet。 这是最小的可配置群集。

先决条件 (Prerequisites)

To follow along, you will need a DigitalOcean account, in addition to the following:

要继续进行下去 ,除了以下内容之外,您还需要一个DigitalOcean帐户

While the steps in this tutorial have been written for and tested against DigitalOcean Droplets, many of them should also be applicable to non-DigitalOcean servers with private networking enabled.

尽管本教程中的步骤是针对DigitalOcean Droplet编写的,并已针对它们进行了测试,但其中许多步骤也应适用于启用了专用网络的非DigitalOcean服务器。

步骤1 —将MariaDB存储库添加到所有服务器 (Step 1 — Adding the MariaDB Repositories to All Servers)

In this step, you will add the relevant MariaDB package repositories to each of your three servers so that you will be able to install the right version of MariaDB used in this tutorial. Once the repositories are updated on all three servers, you will be ready to install MariaDB.

在此步骤中,您将相关的MariaDB软件包存储库添加到三个服务器中的每一个中,以便能够安装本教程中使用的正确版本的MariaDB。 一旦所有三台服务器上的存储库都更新,您就可以安装MariaDB了。

One thing to note about MariaDB is that it originated as a drop-in replacement for MySQL, so in many configuration files and startup scripts, you’ll see mysql rather than mariadb. In many cases, these are interchangeable. For consistency’s sake, we will use mariadb in this guide where either could work.

关于MariaDB的一件事要注意,它最初是MySQL的替代产品,因此在许多配置文件和启动脚本中,您将看到mysql而不是mariadb 。 在许多情况下,这些是可互换的。 为了保持一致性,我们将在本指南中使用mariadb ,无论哪种方法都可行。

In this tutorial, you will use MariaDB version 10.4. Since this version isn’t included in the default CentOS repositories, you’ll start by adding the external CentOS repository maintained by the MariaDB project to all three of your servers.

在本教程中,您将使用MariaDB 10.4版 。 由于此版本未包含在默认的CentOS存储库中,因此您首先需要将由MariaDB项目维护的外部CentOS存储库添加到所有三个服务器中。

Note: MariaDB is a well-respected provider, but not all external repositories are reliable. Be sure to install only from trusted sources.

注意: MariaDB是受人尊敬的提供者,但并非所有外部存储库都是可靠的。 确保仅从受信任的来源进行安装。

First, you’ll add the MariaDB repository key by creating a repository file with a text editor. This tutorial will use vi:

首先,您将通过使用文本编辑器创建存储库文件来添加MariaDB存储库密钥。 本教程将使用vi

  • sudo vi /etc/yum.repos.d/mariadb.repo

    须藤vi /etc/yum.repos.d/mariadb.repo

Next, add the following contents to the file by pressing i to enter insert mode, then adding the following:

接下来,通过按i进入插入模式,然后添加以下内容,将以下内容添加到文件中:

/etc/yum.repos.d/mariadb.repo
/etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Press the esc key to return to normal mode, then type :wq to save and exit the file. If you would like to learn more about the text editor vi and its predecessor vim, take a look at our tutorial on Installing and Using the Vim Text Editor on a Cloud Server.

esc键返回到正常模式,然后键入:wq保存并退出文件。 如果您想了解有关文本编辑器vi及其之前版本的vim ,请查看我们的有关在云服务器安装和使用Vim文本编辑器的教程。

Once you have created the repository file, enable it with the following command:

创建存储库文件后,请使用以下命令启用它:

  • sudo yum makecache --disablerepo='*' --enablerepo='mariadb'

    sudo yum makecache --disablerepo ='*'--enablerepo ='mariadb'

The makecache command caches the repository metadata so that the package manager can install MariaDB, with --disablerepo and --enablerepo targeting the command to the mariadb repo file that you just created.

makecache命令缓存存储库元数据,以便程序包管理器可以使用--disablerepo--enablerepo将命令定位到刚创建的mariadb repo文件来安装MariaDB。

You will receive the following output:

您将收到以下输出:


   
   
   
Output
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile mariadb | 2.9 kB 00:00:00 (1/3): mariadb/primary_db | 43 kB 00:00:00 (2/3): mariadb/other_db | 8.3 kB 0
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值