Drbd9 Mysql Rhel8
Drbd9 Mysql Rhel8
Drbd9 Mysql Rhel8
RHEL/CentOS 8
Brian Hellman;Ryan Ronnander
1.0, 2020-07-09
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2. Installation Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3. Initial Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.3. SELinux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
6. Failure Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7. Special Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8. Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
9. Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Appendix B: Legalese . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Chapter 1. Introduction
This guide describes an approach for designing and implementing High Availability (HA) MySQL cluster using DRBD,
Pacemaker, and Corosync on RHEL 8 or CentOS 8 servers.
There are several options available to achieve HA for MySQL using this particular software stack, all of which may be
combined:
• Shared storage cluster - This deployment type relies on a single, shared data "silo" which holds the data files
associated with the MySQL database. This option, while creating redundancy at the server level, relies on a
single instance of data which itself is typically not highly available. Clusters of this type may use a fibre channel
or iSCSI based storage area network (SAN). When properly configured, shared storage clusters guarantee
transaction integrity across failover.
• DRBD based shared-nothing cluster - This cluster type makes use of local, directly attached storage whose
content is synchronously replicated between cluster nodes. This adds an additional layer of redundancy in that
MySQL’s data storage is available on more than one node. Like shared storage clusters, DRBD based clusters
guarantee transaction integrity across failover.
• MySQL Replication based shared-nothing cluster - This cluster type makes use of local, directly attached
storage and uses MySQL replication to propagate database events across the cluster. Like DRBD, this adds
redundancy in that MySQL’s data storage is available on more than one node. As of DRBD 9, both DRBD and
MySQL replication can utilize multiple secondaries with a single primary, are asynchronous, hence highly
suitable for scale-out solutions. MySQL Replication, however, does not make any guarantees about not losing
updates upon failover.
This technical guide describes the DRBD based shared-nothing option. This approach has some advantages over the
shared storage based one:
• In a shared storage cluster, while there exists server redundancy and the cluster can always tolerate the failure
of a cluster node, the shared storage itself is often not redundant. Thus, as soon as the cluster loses access to
its data — which may or may not involve data destruction — the cluster as a whole is out of service. By
contrast, in a DRBD based shared-nothing cluster, every node has access to its own replica of the data. This
allows DRBD to provide redundancy at both the data as well as the node levels.
• As a consequence, DRBD based shared-nothing clusters may be deployed in their entirety across separate
hypervisors, networks, locations, or any other such divide. By contrast, a shared storage cluster typically
deploys nodes over such boundaries, but does not do so for its data storage.
SERVICE SERVICE
Shared-nothing clusters can also be achieved by using storage replication mechanisms other than
DRBD. Such synchronous replication solutions, however, are typically proprietary and strongly
coupled to a specific set of storage hardware. DRBD is entirely software based, open source, and
hardware agnostic.
1
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 2.1. Register Nodes and Repository Configuration
In order to create a highly available MySQL cluster, you will need to install the following software packages:
• MySQL is an open source relational database management system (RDBMS). This guide assumes that you are
using MySQL version 8.0 or greater.
• Pacemaker is a cluster resource management framework which you will use to automatically start, stop,
monitor, and migrate resources. Distributions typically bundle Pacemaker in a package simply named
pacemaker. This guide assumes that you are using Pacemaker 2.0.2 or greater installed from LINBIT’s
[pacemaker-2] repository.
• Corosync is the cluster messaging layer that Pacemaker uses for communication and membership. In
distributions, the Corosync package is usually simply named corosync. This guide assumes that you are using
Corosync version 3.0.2 or greater installed from LINBIT’s [pacemaker-2] repository.
• DRBD is a kernel block-level synchronous replication facility which serves as an imported shared-nothing
cluster building block. This guide assumes use of DRBD 9.0 installed from LINBIT’s [drbd-9.0] repository.
LINBIT support customers can get pre-compiled binaries from the official repositories. As always the source can
be found at https://github.com/LINBIT/drbd.
You may be required to install packages other than the above-mentioned ones due to package
dependencies. However, when using a package management utility such as dnf, these
dependencies should be resolved automatically.
Once you have access to the customer portal, you can register and configure your node’s repository access by using
the Python command line tool outlined in the "REGISTER NODES" section of the portal.
To register the cluster nodes and configure LINBIT’s repositories, run the following on all nodes, one at a time:
# curl -O https://my.linbit.com/linbit-manage-node.py
# chmod +x ./linbit-manage-node.py
# ./linbit-manage-node.py
If no python interpreter found :-( is displayed when running linbit-manage-
node.py, install Python 3 using the following command: # dnf install python3.
The script will prompt you for your LINBIT portal username and password. Once provided, it will list cluster nodes
associated with your account (none at first).
After you tell the script which cluster to register the node with, you will be asked a series of questions regarding which
repositories you’d like to enable.
Be sure to say yes to the questions regarding installing LINBIT’s public key to your keyring and writing the repository
configuration file.
After that, you should be able to # dnf info kmod-drbd and see dnf pulling package information from LINBIT’s
repository.
2
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 2.1. Register Nodes and Repository Configuration
Before installing packages, make sure to only pull the cluster stack packages from LINBIT’s
repositories.
To ensure we only pull cluster packages from LINBIT, we will need to add the following exclude line to our repository
files:
The x86_64 architecture repositories are used in the following examples. Adjust accordingly if
your system architecture is different.
# '/etc/yum.repos.d/redhat.repo' example:
[rhel-8-for-x86_64-baseos-rpms]
name = Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
baseurl = https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/baseos/os
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslcacert = /etc/rhsm/ca/redhat-uep.pem
sslclientkey = /etc/pki/entitlement/<your_key_here>.pem
sslclientcert = /etc/pki/entitlement/<your_cert_here>.pem
metadata_expire = 86400
enabled_metadata = 1
exclude=cluster* corosync* drbd kmod-drbd libqb* pacemaker* resource-agents*
[rhel-8-for-x86_64-appstream-rpms]
name = Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
baseurl = https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/appstream/os
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslcacert = /etc/rhsm/ca/redhat-uep.pem
sslclientkey = /etc/pki/entitlement/<your_key_here>.pem
sslclientcert = /etc/pki/entitlement/<your_cert_here>.pem
metadata_expire = 86400
enabled_metadata = 1
exclude=cluster* corosync* drbd kmod-drbd libqb* pacemaker* resource-agents*
If the Red Hat High Availability Add-On is enabled, either add the exclude line to the [rhel-8-
for-x86_64-highavailability-rpms] section or consider disabling the repository. LINBIT
provides most of the packages available in the HA repository.
3
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 2.2. Installing DRBD
# /etc/yum.repos.d/CentOS-Base.repo example:
[BaseOS]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$i
nfra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
exclude=cluster* corosync* drbd kmod-drbd libqb* pacemaker* resource-agents*
# /etc/yum.repos.d/CentOS-AppStream.repo example:
[AppStream]
name=CentOS-$releasever - AppStream
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra
=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
exclude=cluster* corosync* drbd kmod-drbd libqb* pacemaker* resource-agents*
Now prevent DRBD from starting at boot, Pacemaker will be responsible for starting the DRBD service:
4
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 2.4. Installing MySQL
Ensure the MySQL service is not started boot as Pacemaker will be responsible for starting the MySQL service:
5
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 3.1. System Configurations
We’ll need a virtual IP for MySQL services to bind to. For this guide we will use
192.168.122.200.
The Logical Volume Manager (LVM) commands used in the creation of this guide are included for your convenience,
adjust accordingly:
# pvcreate /dev/vdb
Physical volume "/dev/vdb" successfully created.
3.3. SELinux
If you have SELinux enabled, and you’re having issues, consult your distributions documentation for how to properly
configure it, or disable it (not recommended).
6
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 3.4. Configuring DRBD
For more detailed instructions regarding initial configuration, please see the chapter 4 of the DRBD
User’s Guide.
It is highly recommended that you put your resource configurations in separate resource files that reside in the
/etc/drbd.d directory, whose name is identical to that of the resource such as /etc/drbd.d/mysql.res. Its
contents should look similar to this:
resource mysql {
protocol C;
device /dev/drbd0;
disk /dev/vg_drbd/lv_mysql;
meta-disk internal;
on node-a {
address 172.16.0.201:7788;
}
on node-b {
address 172.16.0.202:7788;
}
}
Copy this configuration to both DRBD nodes. Next it will be necessary to bring the DRBD resource named mysql up
and online as it will serve as the backing storage for the database.
First create the metadata for the DRBD resource. This step must be done on both nodes:
Then load the DRBD module and bring the resource up on both nodes:
# drbdadm up mysql
The DRBD resource should now be in the connected state, the Secondary role on both nodes, and show a disk state of
Inconsistent on both nodes. Verify their state by typing the following on either node:
# drbdadm status
mysql role:Secondary
disk:Inconsistent
node-b role:Secondary
peer-disk:Inconsistent
At this point we may either begin the initial device synchronization, or, as this is a brand new volume and identical on
both nodes already (empty), we can safely skip the initial synchronization with the --clear-bitmap option. Run the
following command on one node:
The /0 at the end of the above command is to specify the volume number of the resource. Even
though the above examples do not utilize the multi-volume support in DRBD, it is still required to
specify a volume number, 0 being the default.
The DRBD resource should now be in the connected state, the Secondary role on both nodes, and show a disk state of
7
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 3.5. Creating a Filesystem
UpToDate on both nodes. Verify their state by typing the following on either node:
# drbdadm status
mysql role:Secondary
disk:UpToDate
node-b role:Secondary
peer-disk:UpToDate
Now that the resource disk state is no longer inconsistent, promote the resource to Primary on the node you wish to
use for creation of the filesystem:
# mkfs.xfs /dev/drbd0
You only need to create the filesystem on the Primary node. Other filesystems such as ext4 and
btrfs may be deployed instead of xfs.
Change the file ownership for the newly mounted filesystem on the Primary node:
The MySQL data directory preparation is now complete and its contents reside on the DRBD backed filesystem. Since
filesystem mounting and the mysqld service will be managed by Pacemaker, run the following commands on the
Primary node:
# umount /var/lib/mysql
8
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 3.7. Configuring Corosync
To improve MySQL’s security, mysql_secure_installation will be invoked in a subsequent
section.
MySQL configuration files such as /etc/my.cnf are not synchronized by DRBD and should be
identical across all nodes.
Create and edit the file /etc/corosync/corosync.conf, it should look like this:
totem {
version: 2
secauth: off
cluster_name: cluster
transport: knet
rrp_mode: passive
}
nodelist {
node {
ring0_addr: 172.16.0.201
ring1_addr: 192.168.122.201
nodeid: 1
name: noda-a
}
node {
ring0_addr: 172.16.0.202
ring1_addr: 192.168.122.202
nodeid: 2
name: node-b
}
}
quorum {
provider: corosync_votequorum
two_node: 1
}
logging {
to_syslog: yes
}
Now that Corosync has been configured we can start the Corosync and Pacemaker services:
Verify that everything has been started and is working correctly by issuing the following command, you should see
9
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 3.8. Creating a Basic Pacemaker Configuration
2 nodes configured
0 resources configured
No inactive resources
Migration Summary:
* Node node-a:
* Node node-b:
• Disable STONITH.
• Set Pacemaker’s "no quorum policy" to ignore loss of quorum.
• Set the default resource stickiness to 200.
To do so, issue the following commands from the CRM shell accessible from the crm command on either node (not
both):
# crm
crm(live)# configure
crm(live)configure# property stonith-enabled="false"
crm(live)configure# property no-quorum-policy="ignore"
crm(live)configure# rsc_defaults resource-stickiness="200"
crm(live)configure# commit
crm(live)configure# exit
bye
recommended to prevent split brains, and potential loss of data on the split brain victim. For
brevity this guide disables STONITH. An excellent guide on STONITH and its configuration can be
found on Clusterlab’s site, or you may always contact LINBIT for more information.
10
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 4.1. Basic Configuration
• The DRBD resource to be used as your database storage area is named mysql, and it manages the device
/dev/drbd0.
• The DRBD device holds an xfs filesystem which is to be mounted to /var/lib/mysql - the default MySQL
data directory.
The MySQL database will utilize that filesystem, and listen on a dedicated cluster IP address, 192.168.122.200.
crm(live)# configure
crm(live)configure# primitive p_drbd_mysql ocf:linbit:drbd \
params drbd_resource="mysql" \
op start interval="0s" timeout="240s" \
op stop interval="0s" timeout="100s" \
op monitor interval="29s" role="Master" \
op monitor interval="31s" role="Slave"
You must set an appropriate shutdown and startup timeout based on your database utilization and
expected workload. Failure to do so will cause Pacemaker to prematurely consider operations
timed-out and initiate recovery operations.
11
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 4.2. Adding Network Connectivity Monitoring
crm(live)# configure
crm(live)configure# primitive p_ping_gw ocf:pacemaker:ping \
params host_list="192.168.122.1" \
dampen="5s" \
multiplier="1000" \
op start interval="0s" timeout="60s" \
op stop interval="0s" timeout="60s" \
op monitor interval="15s" timeout="60s"
Finally, add a location constraint to tie the Primary role of your DRBD resource to a node with upstream network
connectivity:
12
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 4.2. Adding Network Connectivity Monitoring
• Move resources away from any node that loses connectivity to upstream IP addresses.
Ensure ICMP echo is not blocked by any firewalls nor IDS filtering on the IP addresses used for ping
monitoring. Additional firewall rules or modification of existing allow lists may be required.
13
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 5.1. Securing the MySQL Installation
An initial recommended step to do so is to run the mysql_secure_installation security utility from the
command line. This utility allows you to set a MySQL password for the root user, disallow any root logins over
remote connections, and also remove the test database.
Database security is an advanced topic beyond the scope of this guide. Your security requirements
may call for additional configuration steps beyond running mysql_secure_installation.
Consult with a MySQL expert if needed.
The following example assumes the import of a database backup named database_backup.sql created with the
mysqldump utility:
From a remote client, assuming the database is running on host node-a with an IP address of 192.168.122.201,
access the MySQL installation as follows:
However, if the database is a highly available one managed by Pacemaker, then it is vital that remote clients connect to
it only via the virtual floating cluster IP address of 192.168.122.200:
Additionally, the MySQL server bind-address attribute may be specified. It can either be
defined in additional_parameters for the ocf:heartbeat:mysql resource in the
Pacemaker cluster configuration, or, as a parameter defined under the [mysqld] section
commonly found in /etc/my.cnf.
14
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 5.3. Accessing Databases
Client connections in the above scenario will always connect to the correct node which currently
holds the DRBD resource in the Primary role, has mounted the file system, advertises the virtual
floating cluster IP address, and is actively running the mysqld service.
15
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 6.1. Node Failure
In this scenario Pacemaker moves the failed node from the Online to the Offline state, and starts the affected
resources on the surviving peer node.
Details of node failure are also explained in chapter 6 of the DRBD User’s Guide.
Node failure does entail MySQL database recovery on the node taking over the service. See MySQL Storage Engine
Recommendations and InnoDB Buffer Pool Size for important considerations applying to database recovery.
Details of this functionality are explained in chapter 2 of the DRBD User’s Guide.
If the DRBD replication link fails, DRBD continues to serve data from the Primary node, and re-synchronizes the DRBD
resource automatically as soon as network connectivity is restored.
Details of this functionality are explained in chapter 2 of the DRBD User’s Guide.
16
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: 7.1. MySQL Storage Engine Recommendations
Highly available MySQL installations should always utilize the InnoDB storage engine. This is the default storage
engine.
A large buffer pool increases InnoDB recovery time after a hard server failure, such as a node crash or forced failover.
A properly configured InnoDB database will eventually recover from such a condition, but possibly after a lengthy
recovery process, potentially over the course of many hours. This may lead to extended and unexpected system
outages.
It is thus often necessary to accept somewhat reduced performance on the highly available MySQL system by
selecting a smaller buffer pool, to ensure proper failover times in return. Proper values for this setting vary greatly
based on both hardware and application load, and users should always consult with a MySQL high availability expert to
select a good value.
The InnoDB buffer pool size is set in the MySQL configuration file, typically located in /etc/my.cnf:
[mysqld]
innodb-buffer-pool-size = <value>
17
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: Chapter 8. Conclusion
Chapter 8. Conclusion
Building a highly available MySQL server cluster managed by Pacemaker while leveraging DRBD as the backing storage
device is an elegant solution to ensure the uptime of your databases in the event of hardware failure.
If you have any questions or concerns regarding deployment of the methods outlined in this document with your
existing MySQL databases, or with your unique system(s) you can always consult with the experts at LINBIT®. See
https://www.linbit.com/contact-us/ for contact information.
18
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: Chapter 9. Feedback
Chapter 9. Feedback
Feedback regarding any errors, or even just suggestions, or comments regarding this document are encouraged, and
very much appreciated. You can contact the author directly using the email address(s) listed on the title page when
present, or [email protected].
For a public discussion about the concepts mentioned in this white paper, you are invited to subscribe and post to the
drbd-user mailing list. Please see the drbd-user mailing list for details.
19
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: Appendix A: Additional Information and Resources
20
MySQL High Availability using Pacemaker and DRBD on RHEL/CentOS 8: B.1. Trademark Notice
Appendix B: Legalese
B.1. Trademark Notice
DRBD® and LINBIT® are trademarks or registered trademarks of LINBIT in Austria, the United States, and other
countries. Other names mentioned in this document may be trademarks or registered trademarks of their respective
owners.
21