High Availability Setup with Heartbeat and Floating IP | Aleksey Grebeshkov | Skillshare

High Availability Setup with Heartbeat and Floating IP

Aleksey Grebeshkov

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
8 Lessons (45m)
    • 1. Introduction

      2:00
    • 2. What are we going to do

      5:06
    • 3. Creating DigitalOcean account and generating the Personal Access Token

      3:52
    • 4. Creating droplets (VPSs) for our HA infrastructure

      9:07
    • 5. Setting up a floating IP address and configuring the DNS

      3:10
    • 6. Installing and configuring Heartbeat

      11:35
    • 7. Creating service for floating IP reassignment

      6:46
    • 8. Digital Ocean Bonuses and Promo Codes

      3:21

About This Class

Step-by-step guide to configuring simple high availability cluster using Digital Ocean VPS. 

This course is suitable for beginning web server administrators. Through this course, you'll learn the fundamentals of high availability web server cluster. Each chapter is packed with step-by-step guides which will put your new learned skills into practical use immediately.

You will start with creating a new Digital Ocean account and setting up two virtual servers. Then you will configure the Personal Access Token for your Digital Ocean account. After that, you will configure the Floating IP, set up and configure the Heartbeat, and finally you will set up the IP reassignment service.

Students completing the course will have the knowledge and skills to set up and administrate their own fail-proof web server cluster.

Please, don't forget to download the workbook with additional information for the course.

Transcripts

1. Introduction: If you've bean once running a website and having a business dependent on it, you know how it is important to have your website available. 24 7 Nowadays, even minor failure in the availability off your website application or any other online resource can result in huge money loss. That is why I'm concerned that creating a high availability clusters, or set ups is very important and is a crucial skill for today's system administrator or even online entrepreneur. High availability is a function off system designed that our lows and application to automatically restart rewrote work to another capable system or server in the event off a failure in terms off servers. There few different technologies, which can be used to set up a higher, highly available system. Their A T least must be competent than can redirect the work on. There must be a mechanism to monitor the failure and transition the system. If an interruption is detected in this course, we will demonstrate how to use some of these services and software to set up a highly available Web service. Um, we will go on configure offloading AP address that can be moved between two capable Web servers. If the primary server goes down, the floating I P will be moved to the second server automatically, and these will alot the main service to resume instantly. 2. What are we going to do: Okay, Welcome back. And now let's look, What are we going to do in the first section? Off the scores. So in the first section, we're gonna be setting up a very simple set up off floating. I be digital ocean service and a heartbeat. Heartbeat is the program that provides Gloucester infrastructure capabilities for client service, which is a crucial component in heil high availability server infrastructure. Heartbeat is typically used in conjunction with a cluster resource manager such, for example, as a pacemaker, um, to achieve a complete heil ever liberalised set up. However, in this section we will demonstrate how to create a simple two note Ah, highly available server set up by simply using the heartbeat on digital ocean floating I peas. Okay, so just a little bit more about the heartbeat. Typically, it's a program that runs specialized Scripps automatically whenever a server is initialized or rebooted. Originally, it was designed for to note leanings based blasters. Ah, but heartbeat is easily extensible to ah, larger configurations. What we should know and understand is that any system running, heartbeat, notes or servers, they communicate by exchanging back. It's called heart beats at the rate off about twice per second on the name of the Programa comes from their regularity off the packet exchange, usually where the heartbeat is a used in Multan out system, one machine or one server is designated as a primary node, and the other one is secondary. Note. If the primary node fails or requires, for example, downtime for maintenance on the secondary note can take over the primary role and answer to the users. So typically, it's a great simple set up for the introduction in the high availability set ups. Ah, for a more robust high availability set up. So you need to look into such products as coursing or peacemaker or keep alive. D. Okay, so let's take a closer look at how this set up that we are configuring in this section of the course will work. As you can see on this scheme you have, we have a user. We have a floating I p set up on DWI have a primary lord balancer, a secondary, a lot balancer and a set off to application servers who run main implication, which should be available to users. For example, the Iran they can run Web server with a website. So when everything works, fine user types the Ural off the website. Hey, or she intends to visit the girl is a revised by Dina Service on, uh, eat sends the traffic to the active server lot balancer. And then, sir Ah, these scheme works if everything is fine and heartbeat monitor tells the whole system that everything is fine. If something happens and we have the primary load balancer or primary server not available at the moment, then the main traffic will bus through the passive or secondary server. But still the end user will get the website that he requested. That is the whole main idea off the high availability servers. Andi, there is the simplest set up that we can dry to make riel and to get a good idea off how all these systems were. I should also know that this course on the covers setting up off the active passive higher availability at the gateway level. Ah, that is it includes the floating I P and the load balancer servers primary and secondary for our purposes. For the purposes off. Getting into the topic off higher availability servers. Ah, it is very good because it is simple. And this is the way that instead of configuring reverse proxy load balancers on each server , we will simply configure these lot balancers to respond with their respective host name and the public i p address. 3. Creating DigitalOcean account and generating the Personal Access Token: welcome back. And in this lesson, we will create the digital ocean account and the A P I access token personal access token for your account. Okay, So, first of all, what we need to do is to go to the digital Ocean website. Let's do it right now. So open the browser and go to Digital Ocean that come here. You need to select these. Sign up, and here just enter your email address and your password, disaster, password and heat. Sign up. You will get all the details to your email address. Okay. So when you are successfully registered, go to the logging page, enter your credentials and hit Logan. As you can see, I already have one. Drop it here. Listen, no one as you can see. So what we need to do in this lesson also is to create the personal access token for the digital ocean. A p I in general, the digital ocean FBI allows you to manage droplets, your virtual servers and also other resources within your digital ocean account. It allows you to make http simple http calls to retrieve information or to execute actions within your account. An action that you can perform through the Jesu lotion control panel except maybe personal access to our connections can also be per firmed via the A p I. That is why to have the possibility to do all these, we need to have a key. And this key is your personal access token. The first step to using the A P I east to generate thes personal access token for your account. Personal access token functions like ordinary off access tokens. They can be used instead of password for digital ocean over the https or and can be used to authenticate to the A P I over basic authentication. Digital ocean allows you to great tokens with read or read and write scope. Right scope is required if you want to modify your account, for example, great or dilly droplets eso to generate the personal access token. First of all, we need to log in tow into our account and then we need to select the A P I section of the website heresy your token section and here we need to hit the general new token bottom. Here we ride the name or the token is just for you to remember. I will write high availability You to me. You may choose any name you like here. The read flag is already said, And we also need to set the right flag here. And we had the general token bottom. Okay, so we have the token generated. And now we need to copied and Teoh save it for our future use. Do it right now because the token won't be shown even to you anymore. Due to security limitations off digital ocean. Okay, so that is it. Now you can go on with the rest of the course. 4. Creating droplets (VPSs) for our HA infrastructure: welcome back. And in this lesson, we will go through our first practical step. He's to create the two ah droplets in the same digital ocean data Sander in the same region . Okay, so these do droplets, they will act as primary and secondary servers which we described breathes lessons, salt. Let's do it. After we've logged in into our digital ocean account, we hit the create droplet. But, um, here we choose the operating system that use the baboon to then which is the droplet size. We can go along with the minimum one and here we need to choose the one region and the same day to central It would be New York one. We don't need any additional options, but we need to droplets to be created Hit the plus and let's name the droplets as primary and as secondary Game on DWI hit Create. Now we need to wait for about a minute. For these droplets to be created by digital ocean. The primary is done and the secondary is always done. Okay, we have our two servers, the primary one and the secondary one. Let's move on and configure them appropriately. So what? We want to do next is to configure our two newly created servers to each of these. We will install the engines. Web server. Ah, that will return us the default weapon when we're accessing the droplet with the public. I p So what we need to do is to change the default html index html pages off the both servers. Ah, for them to return us the information about Ah, what server is sending us these webpage at any given moment? Ah, so that we can check or test which droplet the floating i e east pointing to at the any given moment. Okay, let's go on and start with the primary server to connect our servers leads to use the poutine. You can download it from the internet. Just google the pootie. It doesn't need any installation. You just download these ah software and Iran it Okay, this is the ssh client. Okay, so let's copy the I P address. Ah, that's connect with it. Yes, the Logan is route by the fold and you've received an email with the root password for each off your newly created servers. Let's use these. Plus were just based it here during our first connection will need to change the root password. Do it right now. First of all, we need to based the current password and then enter the new one two. Simple. Okay, let's make it more complicated. Don't These passwords is okay, so we are locked in to our primary server. What I want to do now is to make the letters more visible to you. Just a moment. Okay. So that you can see everything. Cleary, let's do the up to get I Day two. Why is for yes? So we answer all the questions with yes. Okay. And after that, let's put this command in. I've got in stroll engines and let Simms told the Web server, and we're done. Okay. Now, what we need to do is to replay the default index html page with the one that will tell us . What server are we pointing at at the moment? So usually the default HTML page is located here in thes directory. Let's edit it with Nano. Here it is. So had welcome to jeans. Some styling here. Okay, let's change these string. Welcome to Primary Server. And let's just delete, uh, all the rest information we don't need Frank and let's save it. Yes, I said it. Okay. And now maybe we can test the set up off the primary server. Lets copy the euro and let's visited. So welcome to primary server. We're done. And now we have to repeat the same procedure for the secondary server. That's the wrong one. More instance off booty here. And find the root boss foot for it. Okay, I will make the letters more visible as well. Route her password. Okay. The current password with the new one. Great. Now let's I have a date Run to get updates. Great. And now let's install the engines on the secondary server. We're done with it. And now let's add it with Nano, their default index html page way will, uh, change this line as well. Do welcome to San Gun injuries. So really server and do it all the rest information. Save it. Great. Now let's check the set up from the secondary server. Copy the I P address I visited and we have welcome to secondary service. So what now? We have the A very clear distinction between the primary and the secondary Sterile. When the visit, the I p address the memories when we will configure. Now the floating I p, we will have the same might be here and here. If one off these servers is ah is not accessible than the other will give the answer to the user. So for us to understand that everything works as expected, we need to know what server is replying to the user. To the visitor. Okay, great. Let's move on. 5. Setting up a floating IP address and configuring the DNS: Okay, So what we need to do next after configuring the to web servers East too. Great. A floating AP address. So we need to go in the digital ocean Control panel, click networking in the top menu and then select the floating I P section from the side menu. Okay, here, we need to assign a floating a beam to our primary droplet. And then Okay, we still like the primary. Drop it, and then we click the assigned floating ap bottom. The proceeds go on, and we have our loading. I p reserved understand to our primary droplet. So let's now go to these AP address and we should see the reply from the primary server. So everything is configured fine. And this bland Okay. And now, if we wish to be able to access our high availability set up via their to my name, we need to go ahead and great and a record in our DNs that points to our domain to our floating I p address. And once that change is saved and propagated Ah, we then will have access to our servers via the domain name. Okay, lets go now and, um, assign these be addressed to on a record off mine own domain. I will go on and logging. Do the control panel off my domain name register and be back with you. Okay? I have looked in. Do the control panel off my register of my demand names. Uh, let's search for DNS management section and let's change the DNs records hair. So I have my primary records assigned to another server, But I want great in a record with the high availability sub domain and the I P address, which had the floating I p address we've created, um, a little bit earlier. Gail is gone and add these record. So I hope by the time that we're done with our configuration, these sub domain will be assigned Do the floating AP, and a bit later we will be able to access our high availability cluster with the's domain name 6. Installing and configuring Heartbeat: Okay, so our next step will be installing the heartbeat to D both off our servers. Uh, let's open up both consoles or the primary and for the secondary server, because we'll have to Ron the same command there. Okay. And that's Ron D. Install up. Get install Heartbeat command. So now we have heartbeat installed on both our servers, but it needs to be configured before it will do what we needed to do. In order to get our cluster up and running, we must set up some heartbeat configuration files. And these files should be identical on both servers. The first filer first to global configuration of the Heartbeat cluster, including it member notes. The 2nd 1 contains security key that provides notes away to authenticate to the class ter, and 3rd 1 specifies the servers that are managed by the cluster and the node that is the preferred owner off the services. I should know that we also need to provide a script that will perform the floating a peer assignment in the event and the primary droplets availability changes. Eso We now have the primary and the secondary server. We have the floating I P address that is now pointing to the primary server. But if, um, de primary server fails, we have two point DCP address to the secondary server. And in order to do these, we have to configure a special script to reconfigure the whole cluster for these. Okay, so before configuring thes h a dot cf filed. Ah, we should look up the names off each note. Ah, heartbeat requires that each note name. Ah, much there you name output. So we must make sure that this output in the common line will match the name of the note. So to find the appropriate node names, let's run this command on both off our servers Primary secondary. So you see the that the output of the command says primary and secondary, which matches what we named the drop leads. We will also need to look up the network interface and AP address that each note will use to communicate with the rest of the class ter to determine which notes are available. Ah, you may use any network interface as long as each note can reach the other notes in the class ter, We will use the public interface off our droplets which happens to be f zero. So in order to be sure what I p address is assigned to the droplet to the virtual server. Ah, we will use this command to look that up. Be dress show at zero and you can see that these ease the public ap address of the server and here as well. Okay, Sorry. Here is the address of the secondary server. Okay, Now let's go on and configure the heartbeat configuration file on the both servers. Note that the file should be new and empty, and we will need to add the network interfaces and the names off each note in our cluster. So let's begin with the primary server Will use Nano. I like this editor. Okay, so you see new file. Okay. We can do the both can fix simultaneously. Let's do you know here as well we have written down the primary might be addressed. And the secondary servers i p address as well. These are the host names over the primary and secondary server, and these are their I P addresses. Now, let's, um, create deconflict file here, and then we will copy and based and the contents to the configuration files on primary and secondary service. So we're right here. Note primary. Then you cast and that to work interface, and they be addressed off primary server. Then we type note secondary and as well you cast the network interface is gonna be one. Do if you have them in your machine. But here we will stick with eth zero and they be address of secondary machine. So the seas, the contents of the config file Let's carpet and basted here to based something into the booty. You need to breast shift insert. Okay on. Did we save changes? Yes. Save the changes. And here also save the changes. Okay. No, let us go. And great. The authorization keys for our servers. The authorization key is used to a low cluster members to join a cluster. We can simply generate a random key for this purpose. So too great. The authorization key for our servers. Let's use Nana as well. Uh, you see the buff? Try H A d d art keys, and we have a new file. The secondary server as well here. What we need to put inside were right off one new line. One line uh, one this age. A one. And now let's go. To make it simple, you can generate these hedge function from the common line, but are to make it simple eyes just you to go to a stager s h A one online did come and just generate random has or just take any light. Anyone, however, liberated you, Timmy, and take Hess. Okay, take these. Copy it. Let's go back to our servers. Andi basted here. Okay, then here. One basted here as well. And we saved the file just to make sure that the key is great. It successfully let's take a look inside the file with the help of a cat. Uh, commend. And yes, it's OK. And here it's okay as well. You also want to make sure that these files are a readable by route on Lee. So let's make the change mode Command Aunt applied to these file on the secondary server as well. So we now have the identical authorization keys for both primary and the secondary server. So what we do now is we configure the H A resources file. This file specifies the preferred hosts Baird with services that the cluster manages the preferred tossed with note that shoot Ron the Associated Service or services even notice available. If the preferred note is not available, for example, it is not reachable by the cluster. Then one of the other notes will take over. In other words, the secondary server will take over if the primary server goes down. So now on both servers, we need to open H A Resources file. Let's go and do it. So it's hoping this file with Nano now we need to add the same line to the both to the files on the both servers with type Primary A lot. Sorry float 18. So primary year stands for the host name off your primary server. Ive the host named Differs from these words you need to put here the host name off your primary server. These configuration file now tells that the primary server in the preferred host for the Flowed I P service, which is currently on defined Let's now go on and set up the Floater p service. But first we need do save the changes done. Let's move on 7. Creating service for floating IP reassignment: Okay. Now our heartbeat cluster is configured to maintain the float AP service. Which note can use to assign the floating AP address to itself, But we still need to great the service before we set up the service itself. Um, let's create a script that will assign the floating A B address via the digital ocean a p i to the note that runs it, then we'll great the flowed I P Service, which will run on the floating I be reassignment script. So what we now need to do is to download the python script that a science have floating AP address to a given droplet i d. He does it using the digital ocean ap I Let's download the script to both, uh, servers. We do it by running this command. You can copy and paste it from the election materials. Okay. Here on dhere, we need to make it exact executable on both servers. No, maybe Let's take a look inside that script, Uh, so you can see the contents of the script itself, and you can go on on and, um, take a closer look at it and understand what it does particularly, but what it does in general is it uses the digital ocean ap I token to assign the floating I p address to the server that runs these script. If you took a closer look at this group itself, you can see that it has three ah arguments. The first argument floating I p address that is being assigned. The second argument is the droplet i d that the floating AP address should be assigned to and the third argument the digital ocean Ah, personal access token or the a p I token. Okay, So after we've covered this group made it executable on Now we can go on and grade the float AP Service degrade the Float I p Service. All we need to do is to grade the initialization script that invokes the assign a piece creeped that we've created already And it also should respond to start and stop commands. Thes and initialization script will be risk are responsible for looking up the droplet i d of the server via the droplet made to that a service Also it will require the floating I p that will be reassigned and the digital ocean ap I token or personal access Dokan. Let's go on and create the flow type we file in the initialization directory. Been you file. We do it on the both service simultaneously. Then what we need to do is to copy and paste the initialization script on replace the parts where we need to put our digital ocean a p I key and the floating I p that we will be reassigning. Okay, you can take the script text from the materials off this election. So as you can see the two parts we need to replace the digital ocean token and they i d Let's do it right now. So remember when we've created the personal access token, I suggested to you to write it down somewhere or to save it somewhere. Because now when you go back to the digital ocean control panel, you just can't view it anymore. You can't go out there and basted. You will have to generating you one for you. Just go and find the one that you've saved. I've saved mine, okay? And as to the i P address, you can go to networking section floating a piece and the floating I p ease here just carpet and passed in here. That's it. And now we need to copy the whole script, go to our console and based it into the files that we've created. Now, opening to do is to make these file executable. So what we've done is we've created the Florida AP service that when it is started, it will call the assign I team by phone script and these by thanks creeped will assign the specified floating i p address to the droplet that executed this creeped. This is this group that will be called by the secondary server to reassign the floating I be to itself if the primary server fails for some reason. On the contrary, the same script will be run by the primary server to reclaim the floating I p Once eat rejoins the cluster once it is up and running properly. 8. Digital Ocean Bonuses and Promo Codes: Okay, so now that we're down with configuration, we're ready to start the heartbeat cluster to do it on the both servers. We need run dis command service heartbeats start to run a gay on the secondary server. It ran OK as well. So now our high availability set up is complete. But before moving on, we need to test it. We know that the floating AP address is now assigned to our primary note to our primary server accessing the floating AP now via the AP address or by the domain name the sub demand that we've configured earlier. It will simply show the index page off the primary server that is Go on and check it. This is our, ah floating 18 and thesis our sub domain on. Yes, we have the index page off the primary server. OK, And now let's assume that our primary server failed for some reason. Let's just go on and power it off the power and power off after the server is powered off our high availability class or shoot, reassign the floating AP address to the secondary server. And when we will go to the sub domain, we should see the index page of the secondary server. Let's go on a check it. Yes, and we have the index page of the secondary server. So the secondary server replaced the primary that failed and showed us the page that it should show. That means that our high availability set up is working. Now let's go on and power on the primary server and see if the system will reassign the I P address to the primary server back. Okay, it's up. Let's refresh the page. Not yet, Yes, and in a couple of seconds, we have the primary server back, and now it returns the webpages do the users. So I congratulate you. You have successfully configured to your very first high availability cluster using Heartbeat and the digital ocean floating 18. I'm looking forward to see you in my next courses for ah, more complicated, high availability setups that will expand your abilities in building the complicated and more professional high availability Web server. Gloucester's