{"id":3163,"date":"2016-11-11T17:47:22","date_gmt":"2016-11-11T22:47:22","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=3163"},"modified":"2017-12-12T16:06:46","modified_gmt":"2017-12-12T21:06:46","slug":"high-availability-heartbeat-drbd-ubuntu-16","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/","title":{"rendered":"How to Achieve High Availability with Heartbeat &#038; DRBD on Ubuntu 16"},"content":{"rendered":"<h1>How to Achieve High Availability with Heartbeat &#038; DRBD on Ubuntu 16<\/h1>\n<p>Heartbeat and DRBD can be used effectively to maintain high availability for MySQL databases on Ubuntu 16.04. Heartbeat is a network-oriented tool for maintaining high availability and managing failover. With heartbeat, you can make sure that a shared IP address, is active on one and only one server at a time in your cluster. DRBD (Distributed Replicated Block Device) synchronizes data between two nodes by writing the data to the primary server first and then writing to the secondary server. When used to provide high availability for MySQL databases, heartbeat and DRBD allow for a seamless transition from the primary to the secondary server when the primary server fails. This guide will take you through the steps necessary to create and initiate such a setup.<\/p>\n<h2>Getting Started<\/h2>\n<p>In order to follow this guide you will need to have the following in place:<br \/>\n\u2022\tTwo nodes (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\">Cloud Server<\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\">Dedicated Server<\/a>) on a single LAN with Ubuntu 16.04 installed. We will call these servers DB1 and DB2 below<br \/>\n\u2022\tThree network cards on each server to allow for the establishment of all required IP addresses<br \/>\n\u2022\tA second unpartitioned drive on each server to serve as the DRDB device<br \/>\n\u2022\tRoot access to the nodes<\/p>\n<p>Throughout the tutorial, ALL commands must be done on both servers unless otherwise specified.<\/p>\n<h2>Tutorial<\/h2>\n<p><strong>IP Assignment<\/strong><\/p>\n<p>You will need to assign public and private IP addresses to the servers, a floating IP address through which your MySQL databases will be accessed, and IP addresses for DRBD traffic. In this guide, we assume that the IP range for your public network is 173.209.49.66\/29 and the IP range for your private network (LAN) is 10.119.0.0\/24. We also assume you have a third network card on both servers with a cross-connect between servers for DRBD traffic. The LAN subnet for this cross-connect presumably covers the IP range 192.168.5.0\/24.<\/p>\n<p>The networking required for such a setup may be configured in a number of ways. We chose to use the easiest to understand. In the setup described below, the first LAN will be used for floating IP&#8217;s and heartbeat while the third network will be reserved for DRBD.<\/p>\n<p>We have assigned the following IP addresses to the components we will use in this tutorial. <\/p>\n<p>Server eth0 (wan) eth1 (lan) eth1 (drbd)<br \/>\nDB1 173.209.49.66 10.119.0.1 192.168.5.1<br \/>\nDB2 173.209.49.67 10.119.0.2 192.168.5.2<br \/>\nFloating None 10.119.0.10 None<\/p>\n<p>Always makes sure your system is up to date before you install any software.<\/p>\n<p><code>apt-get update<br \/>\napt-get -y upgrade<\/code><\/p>\n<p>Disable Ubuntu&#8217;s firewall (if it is installed) before you assign the above IP addresses. <\/p>\n<p><code>ufw disable<\/code><\/p>\n<p>Configure the hostnames for your servers. To do so run the following commands on <\/p>\n<p>On DB1:<\/p>\n<p><code>echo \"db1.mydomain.com\" > \/etc\/hostname<br \/>\nhostname db1.mydomain.com<\/code><\/p>\n<p>On DB2:<br \/>\n<code>echo \"db2.mydomain.com\" > \/etc\/hostname<br \/>\nhostname db2.mydomain.com<\/code><\/p>\n<p>Add the hostnames you have created as entries in the host file:<\/p>\n<p><code>nano \/etc\/hosts<\/code><\/p>\n<p>Next, add the following entries on both servers. This will bind hostnames to the DRBD IP&#8217;s in the 192.168.5.0\/24 range:<\/p>\n<p><code class=\"gris\">192.168.5.1 db1.mydomain.com<br \/>\n192.168.5.2 db2.mydomain.com<\/code><\/p>\n<p>Your network is now set up.<\/p>\n<p><strong>Install and Configure DRBD and Heartbeat<\/strong><\/p>\n<p>With your network configuration in place, install DRBD and heartbeat. Configure your nodes so that both DRDB and heartbeat start when the servers boot:<\/p>\n<p><code>apt-get -y install drbd8-utils heartbeat<br \/>\nsystemctl enable drbd<br \/>\nsystemctl enable heartbeat<\/code><\/p>\n<p>You will need to set up a DRDB device for each server. Check that your second unpartitioned drive is available to use as your DRBD device:<\/p>\n<p><code>fdisk -l<\/code><\/p>\n<p>Below, we can see that we have a 16GB \/dev\/sdb drive in our setup. We will use this drive for DRBD.<\/p>\n<p><code class=\"gris\">Disk \/dev\/sda: 16 GiB, 17179869184 bytes, 33554432 sectors<br \/>\nUnits: sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisklabel type: dos<br \/>\nDisk identifier: 0xcda6f1d3<br \/>\nDevice     Boot   Start      End  Sectors  Size Id Type<br \/>\n\/dev\/sda1  *       2048   976895   974848  476M 83 Linux<br \/>\n\/dev\/sda2        976896  4976639  3999744  1.9G 82 Linux swap \/ Solaris<br \/>\n\/dev\/sda3       4976640 33552383 28575744 13.6G 83 Linux<br \/>\nDisk \/dev\/sdb: 16 GiB, 17179869184 bytes, 33554432 sectors<br \/>\nUnits: sectors of 1 * 512 = 512 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<\/code><\/p>\n<p>The second drive can easily be partitioned using the simple formula below. This formula will create a single partition that occupies the whole disk.<\/p>\n<p><code>echo -e 'n\\np\\n1\\n\\n\\nw' | fdisk \/dev\/sdb<\/code><\/p>\n<p>With the DRBD devices in place, it is time to configure DRBD on both nodes. First, create the DRBD configuration file on each node:<\/p>\n<p><code>echo \"\" > \/etc\/drbd.d\/global_common.conf<br \/>\nnano \/etc\/drbd.d\/r0.res<\/code><\/p>\n<p>Add the following into both DRBD configuration files:<\/p>\n<p><code class=\"gris\">global {<br \/>\n    usage-count no;<br \/>\n}<br \/>\nresource r0 {<br \/>\n    protocol C;<br \/>\n    startup {<br \/>\n        degr-wfc-timeout 60;<br \/>\n    }<br \/>\n    disk {<br \/>\n        on-io-error detach;<br \/>\n    }<br \/>\n    syncer {<br \/>\n        rate 100M;<br \/>\n    }<br \/>\n    net {<br \/>\n        cram-hmac-alg sha1;<br \/>\n        shared-secret \"wXE8MqVa\";<br \/>\n    }<br \/>\n    on db1.mydomain.com {<br \/>\n        device \/dev\/drbd0;<br \/>\n        disk \/dev\/sdb1;<br \/>\n        address 192.168.5.1:7789;<br \/>\n        meta-disk internal;<br \/>\n    }<br \/>\n    on db2.mydomain.com {<br \/>\n        device \/dev\/drbd0;<br \/>\n        disk \/dev\/sdb1;<br \/>\n        address 192.168.5.2:7789;<br \/>\n        meta-disk internal;<br \/>\n    }<br \/>\n}<\/code><\/p>\n<p>We will now edit the various files used to configure our servers for high availability. Remember to edit the files on both servers in exactly the same way except where we indicate there need to be differences.<\/p>\n<p>The first file we will edit is the configuration file \/etc\/ha.d\/ha.cf on both nodes. You may open the file like so:<\/p>\n<p><code>nano \/etc\/ha.d\/ha.cf<\/code><\/p>\n<p>Enter the following parameters in the file. The bcast parameter line is of critical importance. In our case, we have 3 network interfaces. We need to put eth2 on this line. If you are using an existing network setup that is designed differently than our simple example you may need to enter a different value here:<\/p>\n<p><code class=\"gris\"># Check Interval<br \/>\nkeepalive 1<br \/>\n# Time before server declared dead<br \/>\ndeadtime 10<br \/>\n# Secondary wait delay at boot<br \/>\ninitdead 60<br \/>\n# Auto-failback<br \/>\nauto_failback off<br \/>\n# Heartbeat Interface<br \/>\nbcast eth2<br \/>\n# Nodes to monitor<br \/>\nnode db1.mydomain.com<br \/>\nnode db2.mydomain.com<\/code><\/p>\n<p>The next file to edit is the resources file \/etc\/ha.d\/haresources<\/p>\n<p><code>nano \/etc\/ha.d\/haresources<\/code><\/p>\n<p>We will enter only one line in this file. Inspect this entry carefully. It should include the hostname of your main active node (db1), the floating IP (10.119.0.10), the device (\/dev\/drbd0) and its mount point (\/var\/lib\/mysql):<\/p>\n<p><code>db1.mydomain.com 10.119.0.10\/24 drbddisk::r0 Filesystem::\/dev\/drbd0::\/var\/lib\/mysql::ext4::noatime<\/code><\/p>\n<p>To secure your high availability setup you will need to define and store identical authorization keys on both nodes. To do so, open and edit \/etc\/ha.d\/authkeys<\/p>\n<p><code>nano \/etc\/ha.d\/authkeys<\/code><\/p>\n<p>This file should only contain the two lines below. Use the same password on both nodes. The password is the text immediately after the &#8220;sha1&#8221; statement.<\/p>\n<p><code class=\"gris\">auth1<br \/>\n1 sha1 e86b38f5075de0318548edad9566436423ada422<\/code><\/p>\n<p>Using the partitions created above, create the DRBD disks. Start by entering the following command on DB1:<\/p>\n<p><code>drbdadm create-md r0<br \/>\nsystemctl restart drbd<br \/>\ndrbdadm outdate r0<br \/>\ndrbdadm -- --overwrite-data-of-peer primary all<br \/>\ndrbdadm primary r0<br \/>\nmkfs.ext4 \/dev\/drbd0<br \/>\nchmod 600 \/etc\/ha.d\/authkeys<br \/>\nmkdir \/var\/lib\/mysql<\/code><\/p>\n<p>If you get an error message along the following lines, &#8220;The file \/dev\/drbd0 does not exist and no size was specified,\u201d check that your hostnames have been set properly.<\/p>\n<p>Once the DRBD disk is created on DB1, you may create the DRBD disk on DB2:<\/p>\n<p><code>drbdadm create-md r0<br \/>\nsystemctl restart drbd<br \/>\nchmod 600 \/etc\/ha.d\/authkeys<br \/>\nmkdir \/var\/lib\/mysql<\/code><\/p>\n<p>With both disks in place, you may now verify that the DRBD disk is connected and is properly syncing<\/p>\n<p><code>cat \/proc\/drbd<\/code><\/p>\n<p>The above command should yield the below output. In this output, you should see Primary\/Secondary. This output indicates that the DB1 node is the master while the other node is the slave. It also shows that everything is syncing as expected.<\/p>\n<p><code class=\"gris\">root@db1:~# cat \/proc\/drbd<br \/>\nversion: 8.4.5 (api:1\/proto:86-101)<br \/>\nsrcversion: D496E56BBEBA8B1339BB34A<br \/>\n 0: cs:SyncSource ro:Primary\/Secondary ds:UpToDate\/Inconsistent C r-----<br \/>\n    ns:550488 nr:0 dw:135424 dr:416200 al:35 bm:0 lo:0 pe:11 ua:0 ap:0 ep:1 wo:f oos:16233752<br \/>\n        [>....................] sync'ed:  3.3% (15852\/16380)M<br \/>\n        finish: 0:16:45 speed: 16,136 (16,932) K\/sec<\/code><\/p>\n<p>With properly configured synchronization in place between the primary and secondary nodes, it is time to enable the failover portion of our setup. To do so, we will simply start heartbeat on both nodes<\/p>\n<p><code>systemctl start heartbeat<\/code><\/p>\n<p>The DRBD partition should be mounted on DB1 only. Verify that this is so:<\/p>\n<p><code>root@db1:\/etc\/ha.d# mount | grep drbd<br \/>\n\/dev\/drbd0 on \/var\/lib\/mysql type ext4 (rw,noatime,data=ordered)<\/code><\/p>\n<p>Once you verify that the floating IP is only bound to DB1 with the following command, you are ready to install your MySQL-type database service.<\/p>\n<p><code>root@db1:\/etc\/ha.d# ip addr show | grep 10.119.0.10<br \/>\n    inet 10.119.0.10\/24 brd 10.119.0.255 scope global secondary eth1:0<\/code><\/p>\n<p><strong>Install MariaDB Database Service<\/strong><\/p>\n<p>Now is the time to install our database service on both servers. There are several variants of MySQL that were created as forks of the original MySQL source code. In the following, we have opted to install MariaDB because of its performance and good track record.<\/p>\n<p><code>apt-get install mariadb-server<\/code><\/p>\n<p>Percona DB and MySQL are two other options you might choose.<\/p>\n<p>The database service on a given node should only start if that node is designated as the primary node at the time. To assure you don&#8217;t end up with MySQL running on both nodes simultaneously, disable auto-start for the MariaDB service on both nodes<\/p>\n<p><code>systemctl disable mysql<\/code><\/p>\n<p>By design, DB1 is primary when our setup is initiated. No database service should be running on DB2. So long as DB1 is primary, databases on DB2 should be created and populated through synchronization with DB1. Therefore, on DB2, you need to stop the MariaDB service and empty \/var\/lib\/mysql. Perform this command ON DB2 ONLY:<\/p>\n<p><code>systemctl stop mysql<br \/>\nrm -rfv \/var\/lib\/mysql\/*<\/code><\/p>\n<p>Before you proceed further, configure the root password on DB1. To do so, simply run the wizard. Set a new root password and allow all other options to retain their default values for now:<\/p>\n<p><code class=\"gris\">root@db1:\/var\/lib# mysql_secure_installation<br \/>\nNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB<br \/>\n      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!<br \/>\nIn order to log into MariaDB to secure it, we'll need the current<br \/>\npassword for the root user.  If you've just installed MariaDB, and<br \/>\nyou haven't set the root password yet, the password will be blank,<br \/>\nso you should just press enter here.<br \/>\nEnter current password for root (enter for none):<br \/>\nOK, successfully used password, moving on...<br \/>\nSetting the root password ensures that nobody can log into the MariaDB<br \/>\nroot user without the proper authorisation.<br \/>\nSet root password? [Y\/n] y<br \/>\nNew password:<br \/>\nRe-enter new password:<br \/>\nPassword updated successfully!<br \/>\nReloading privilege tables..<br \/>\n ... Success!<br \/>\nBy default, a MariaDB installation has an anonymous user, allowing anyone<br \/>\nto log into MariaDB without having to have a user account created for<br \/>\nthem.  This is intended only for testing, and to make the installation<br \/>\ngo a bit smoother.  You should remove them before moving into a<br \/>\nproduction environment.<br \/>\nRemove anonymous users? [Y\/n] Y<br \/>\n ... Success!<br \/>\nNormally, root should only be allowed to connect from 'localhost'.  This<br \/>\nensures that someone cannot guess at the root password from the network.<br \/>\nDisallow root login remotely? [Y\/n] Y<br \/>\n ... Success!<br \/>\nBy default, MariaDB comes with a database named 'test' that anyone can<br \/>\naccess.  This is also intended only for testing, and should be removed<br \/>\nbefore moving into a production environment.<br \/>\nRemove test database and access to it? [Y\/n] Y<br \/>\n - Dropping test database...<br \/>\n ... Success!<br \/>\n - Removing privileges on test database...<br \/>\n ... Success!<br \/>\nReloading the privilege tables will ensure that all changes made so far<br \/>\nwill take effect immediately.<br \/>\nReload privilege tables now? [Y\/n] Y<br \/>\n ... Success!<br \/>\nCleaning up...<br \/>\nAll done!  If you've completed all of the above steps, your MariaDB<br \/>\ninstallation should now be secure.<br \/>\nThanks for using MariaDB!<\/code><\/p>\n<p>Copy the MySQL Maintenance configuration file from DB1 to DB2<\/p>\n<p><code>rsync -av \/etc\/mysql\/debian.cnf root@192.168.5.2:\/etc\/mysql\/debian.cnf<\/code><\/p>\n<p>Now we will create a root user for remote management of and access to the databases on the highly available MySQL instance. We will make use of wildcards to do so.<\/p>\n<p>Our cluster architecture is set up so that all other servers on our LAN can reach the database at the floating IP 10.119.0.10. If you wish to enable users outside your LAN to access your highly available database you may bind a public IP in \/etc\/ha.d\/haresources for database access as well, following the pattern set above in editing that file.<\/p>\n<p>In our case, we have set up our high availability database servers to be accessible from other servers on the LAN that share the IP range 10.119.0.0\/24.<\/p>\n<p><code>mysql -u root -p<\/code><\/p>\n<p>Enter the following commands to create the root user. Replace \u201cmy-password\u201d with the MySQL root password you wish to assign to the remote access user:<\/p>\n<p><code>MariaDB [(none)]> CREATE USER 'root'@'10.119.0.%' IDENTIFIED BY 'my-password';<br \/>\nMariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.119.0.%' WITH GRANT OPTION;<br \/>\nMariaDB [(none)]> FLUSH PRIVILEGES;<br \/>\nMariaDB [(none)]> QUIT;<\/code><\/p>\n<p>Set the bind address for MySQL on both servers<\/p>\n<p><code>sed -i 's\/127.0.0.1\/0.0.0.0\/g' \/etc\/mysql\/mariadb.conf.d\/*.cnf<\/code><\/p>\n<p><strong>Initiate Heartbeat for MySQL Service<\/strong><\/p>\n<p>Add support for the MySQL service in our heartbeat instances on both servers. First, open the configuration file:<\/p>\n<p><code>nano \/etc\/ha.d\/haresources<\/code><\/p>\n<p>Then, simply add mysql at the end of the line and save the file<\/p>\n<p><code class=\"gris\">db1.mydomain.com 10.119.0.10\/24 drbddisk::r0 Filesystem::\/dev\/drbd0::\/var\/lib\/mysql::ext4::noatime mysql<\/code><\/p>\n<p>Once heartbeat is configured we need to restart it on both servers. heartbeat must be started on the primary server (DB1) first. Once heartbeat has started on DB1 allow at least 20 seconds before you restart heartbeat on DB2.<\/p>\n<p>The command sequence is as follows. ON DB1 enter:<\/p>\n<p><code>systemctl restart heartbeat<\/code><\/p>\n<p>Wait 20 seconds or more and then enter the following on DB2:<\/p>\n<p><code>systemctl restart heartbeat<\/code><\/p>\n<p>The delay between initiating the heartbeat stack on DB1 and DB2 will prevent heartbeat from inadvertently initiating failover to DB2 upon startup.<\/p>\n<p><strong>Testing redundancy of our setup<\/strong><\/p>\n<p>Our goal throughout this tutorial has been to tie together our servers such that MySQL service will not be interrupted if the active server fails. Now that our setup is complete, we will perform a series of tests to verify that heartbeat will actually trigger a transfer from the active server to the passive server when the active server fails in some way. We will also verify that DRBD is properly syncing the data between the two servers.<\/p>\n<p><strong>Tests to Perform on DB1<\/strong><\/p>\n<p>First, we will verify that DB1 is the primary drbd node<\/p>\n<p><code>root@db1:~# cat \/proc\/drbd<\/code><br \/>\n<code class=\"gris\">version: 8.4.5 (api:1\/proto:86-101)<br \/>\nsrcversion: D496E56BBEBA8B1339BB34A<br \/>\n 0: cs:Connected ro:Primary\/Secondary ds:UpToDate\/UpToDate C r-----<br \/>\n    ns:22764644 nr:256 dw:529232 dr:22248299 al:111 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0<\/code><\/p>\n<p>Next, we will verify that the DRBD disk is mounted<\/p>\n<p><code>root@db1:~# mount | grep drbd<\/code><br \/>\n<code class=\"gris\">\/dev\/drbd0 on \/var\/lib\/mysql type ext4 (rw,noatime,data=ordered)<\/code><\/p>\n<p>The floating IP must be bound correctly for the setup to function properly<\/p>\n<p><code>root@db1:~# ip addr show | grep 10.119.0.10<\/code><br \/>\n<code class=\"gris\">    inet 10.119.0.10\/24 brd 10.119.0.255 scope global secondary eth1:0<\/code><\/p>\n<p>Check to make sure that MariaDB is running<\/p>\n<p><code>root@db1:~# ps -ef | grep mysqld<\/code><br \/>\n<code class=\"gris\">root      7472     1  0 05:52 ?        00:00:00 \/bin\/bash \/usr\/bin\/mysqld_safe<br \/>\nmysql     7617  7472  0 05:52 ?        00:00:00 \/usr\/sbin\/mysqld --basedir=\/usr --datadir=\/var\/lib\/mysql --plugin-dir=\/usr\/lib\/mysql\/plugin --user=mysql --skip-log-error --pid-file=\/var\/run\/mysqld\/mysqld.pid --socket=\/var\/run\/mysqld\/mysqld.sock --port=3306<br \/>\nroot      7618  7472  0 05:52 ?        00:00:00 logger -t mysqld -p daemon error<\/code><\/p>\n<p>Use the remote access root user to test the MySQL connection directly on the floating (failover) IP and create a test database.<\/p>\n<p><code>mysql -h 10.119.0.10 -u root -p<\/code><br \/>\n<code class=.gris\">MariaDB [(none)]> create database failtest;<br \/>\nMariaDB [(none)]> quit<\/code><\/p>\n<p>Restart heartbeat on DB1.<\/p>\n<p><code>systemctl restart heartbeat<\/code><\/p>\n<p>Heartbeat will interpret this restart as a failure of DB1 and should trigger failover to make DB2 the primary server. Ensure that DRBD is now treating DB1 as the secondary server:<\/p>\n<p><code>root@db1:~# cat \/proc\/drbd<\/code><br \/>\n<code class=\"gris\">version: 8.4.5 (api:1\/proto:86-101)<br \/>\nsrcversion: D496E56BBEBA8B1339BB34A<br \/>\n 0: cs:Connected ro:Secondary\/Primary ds:UpToDate\/UpToDate C r-----<br \/>\n    ns:22764856 nr:388 dw:529576 dr:22248303 al:112 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0<\/code><\/p>\n<p>Having triggered the failover, we will now test that our setup is fully functional with DB2 acting as the primary server.<\/p>\n<p><strong>Tests to perform on DB2<\/strong><\/p>\n<p>Verify that DB2 is now the primary drbd node<\/p>\n<p><code>root@db2:~# cat \/proc\/drbd<\/code><br \/>\n<code class=\"gris\">version: 8.4.5 (api:1\/proto:86-101)<br \/>\nsrcversion: D496E56BBEBA8B1339BB34A<br \/>\n 0: cs:Connected ro:Primary\/Secondary ds:UpToDate\/UpToDate C r-----<br \/>\n    ns:412 nr:20880892 dw:20881304 dr:11463 al:7 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0<\/code><\/p>\n<p>Verify that the DRBD disk is mounted on DB2<\/p>\n<p><code>root@db2:~# mount | grep drbd<\/code><br \/>\n<code class=\"gris\">\/dev\/drbd0 on \/var\/lib\/mysql type ext4 (rw,noatime,data=ordered)<\/code><\/p>\n<p>Verify the floating IP is now bound to DB2 correctly<\/p>\n<p><code>root@db2:~# ip addr show | grep 10.119.0.10<\/code><br \/>\n<code class=\"gris\">    inet 10.119.0.10\/24 brd 10.119.0.255 scope global secondary eth1:0<\/code><\/p>\n<p>Check to make sure that MariaDB is running on DB2<\/p>\n<p><code>root@db2:~# ps -ef | grep mysqld<\/code><br \/>\n<code class=\"gris\">root      7568     1  0 06:13 ?        00:00:00 \/bin\/bash \/usr\/bin\/mysqld_safe<br \/>\nmysql     7713  7568  0 06:13 ?        00:00:00 \/usr\/sbin\/mysqld --basedir=\/usr --datadir=\/var\/lib\/mysql --plugin-dir=\/usr\/lib\/mysql\/plugin --user=mysql --skip-log-error --pid-file=\/var\/run\/mysqld\/mysqld.pid --socket=\/var\/run\/mysqld\/mysqld.sock --port=3306<br \/>\nroot      7714  7568  0 06:13 ?        00:00:00 logger -t mysqld -p daemon error<\/code><\/p>\n<p>Use the remote access user to connect to the MySQL instance at the floating (failover) IP. If your setup is working properly, the following commands should enable you to view the test database we created earlier while DB1 was the primary server.<\/p>\n<p><code>mysql -u 10.119.0.10 -u root -p<\/code><br \/>\n<code class=\"gris\">MariaDB [(none)]> show databases;<br \/>\n+--------------------+<br \/>\n| Database           |<br \/>\n+--------------------+<br \/>\n| failtest           |<br \/>\n| information_schema |<br \/>\n| lost+found         |<br \/>\n| mysql              |<br \/>\n| performance_schema |<br \/>\n+--------------------+<br \/>\n5 rows in set (0.04 sec)<br \/>\nMariaDB [(none)]> exit<\/code><\/p>\n<p>Restart Heartbeat.<\/p>\n<p><code>systemctl restart heartbeat<\/code><\/p>\n<p>As it did before, this restart should trigger failover. To check that it has done so, ensure that DRBD is now secondary on DB2<\/p>\n<p><code>root@db2:~# cat \/proc\/drbd<\/code><br \/>\n<code class=\"gris\">version: 8.4.5 (api:1\/proto:86-101)<br \/>\nsrcversion: D496E56BBEBA8B1339BB34A<br \/>\n 0: cs:Connected ro:Secondary\/Primary ds:UpToDate\/UpToDate C r-----<br \/>\n    ns:508 nr:20881012 dw:20881520 dr:11475 al:7 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0<\/code><\/p>\n<p>Provided your tests yielded the expected results, your high availability MySQL setup should now be fully operational.<\/p>\n<h2>Conclusion<\/h2>\n<p>Congratulations, the high-availability MySQL setup you have created on your Ubuntu 16.04 servers will make your databases more reliable for mission critical functions. This frees you to create content while your users get nearly continuous data access. <\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>How to Achieve High Availability with Heartbeat &#038; DRBD on Ubuntu 16 Heartbeat and DRBD can be used effectively to maintain high availability for MySQL databases on Ubuntu 16.04. Heartbeat is a network-oriented tool for maintaining high availability and managing failover. With heartbeat, you can make sure that a shared IP address, is active on<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[],"class_list":["post-3163","post","type-post","status-publish","format-standard","hentry","category-ha-clustering","operating_system-ubuntu-16-04"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Achieve High Availability with Heartbeat &amp; DRBD on Ubuntu 16 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to achieve High Availability with Heartbeat and DRBD on your Ubuntu 16 Server. Read now &amp; Maintain HA for MySQL databases!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Achieve High Availability with Heartbeat &amp; DRBD on Ubuntu 16 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to achieve High Availability with Heartbeat and DRBD on your Ubuntu 16 Server. Read now &amp; Maintain HA for MySQL databases!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-11T22:47:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-12T21:06:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/\",\"name\":\"How to Achieve High Availability with Heartbeat & DRBD on Ubuntu 16 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"datePublished\":\"2016-11-11T22:47:22+00:00\",\"dateModified\":\"2017-12-12T21:06:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will show you how to achieve High Availability with Heartbeat and DRBD on your Ubuntu 16 Server. Read now & Maintain HA for MySQL databases!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Achieve High Availability with Heartbeat &#038; DRBD on Ubuntu 16\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Achieve High Availability with Heartbeat & DRBD on Ubuntu 16 - Globo.Tech","description":"This tutorial will show you how to achieve High Availability with Heartbeat and DRBD on your Ubuntu 16 Server. Read now & Maintain HA for MySQL databases!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/","og_locale":"en_US","og_type":"article","og_title":"How to Achieve High Availability with Heartbeat & DRBD on Ubuntu 16 - Globo.Tech","og_description":"This tutorial will show you how to achieve High Availability with Heartbeat and DRBD on your Ubuntu 16 Server. Read now & Maintain HA for MySQL databases!","og_url":"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/","og_site_name":"Globo.Tech","article_published_time":"2016-11-11T22:47:22+00:00","article_modified_time":"2017-12-12T21:06:46+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/","url":"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/","name":"How to Achieve High Availability with Heartbeat & DRBD on Ubuntu 16 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-11-11T22:47:22+00:00","dateModified":"2017-12-12T21:06:46+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will show you how to achieve High Availability with Heartbeat and DRBD on your Ubuntu 16 Server. Read now & Maintain HA for MySQL databases!","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/high-availability-heartbeat-drbd-ubuntu-16\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to Achieve High Availability with Heartbeat &#038; DRBD on Ubuntu 16"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=3163"}],"version-history":[{"count":5,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3163\/revisions"}],"predecessor-version":[{"id":4017,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3163\/revisions\/4017"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=3163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=3163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=3163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}