SIZ Tutorials || HOW TO SETUP WEBSITE 2 REGION USING LOAD BALANCER ON CLOUD VPS || 20 payout to siz-official

in hive-181430 •  3 years ago 

Assalamualaikum everyone have a good night and my best regards to @siz-official, @suboohi and @cryptokraze. Meet me again, this time I will discuss about how to stup a 2 region website using a load balancer on a cloud vps. So that you can understand it easily I will explain in my own way. Read on for the following review.

Understanding Load Balancing

analysis-1010888_640.jpg
Image source

Load balancing is a technique for dividing the load on one server to another. For example when we have an X server and then we want to share the load on that server to server Y. In this case to do this we need two servers and one device that we will use for load balancing for example another server or a PC. Before we get into the tutorial. It would be nice if we first understand Haproxy.

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iQRqKhAHHMT6UxacBhywrtyAQA9uagQvbDriLncoyixgvuZP3y8qfFPhY2FSAJ1Cf6bkttqXWea.png

Understanding Haproxy

download.png
Image source

Haproxy is a free and open source software that provides load balancer and proxy server technology for TCP and HTTP-based applications that provide suggestions or propagate requests to several other servers. Haproxy has a very good reputation due to its technology which is very fast and efficient in using the processor and memory.

We can say Haproxy is one of the fastest software and is widely used by various well-known websites. Haproxy is currently one of the most popular and well-known load balancers today.

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iQRqKhAHHMT6UxacBhywrtyAQA9uagQvbDriLncoyixgvuZP3y8qfFPhY2FSAJ1Cf6bkttqXWea.png

Haproxy System and Load Balancer

images (1).png
Image source

HAProxy can work in two modes at once, namely TCP layer 4 and HTTP layer 7. At TCP layer 4, HAProxy forwards TCP RAW packets from the client to the application server. In HTTP layer 7, HAProxy parses the HTTP Header before forwarding it to the application server.

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iQRqKhAHHMT6UxacBhywrtyAQA9uagQvbDriLncoyixgvuZP3y8qfFPhY2FSAJ1Cf6bkttqXWea.png

How to Setup a 2 Region Website Using a Load Balancer

At this time we will try to make or implement the use of Haproxy to setup the web on two different servers so it is hoped that when one server experiences problems the other server can cover so that the web can continue to be online.

In this setup we will use 3 VMs (virtual machines) including:

  • Wordpress website (for example)
  • Haproxy Website Servers
  • Server VM for MariaDB

Alright, here we are, just login to console.idcloudhost.com and create 2 VMs in different locations.

Stage of Creating a WordPress Server

IMG_20211016_185614.jpg

At this stage we do the settings on the server location and also our username, password and billing account.

IMG_20211016_185830.jpg

After the creation of the VM is successful, then we create it and then we can open the public IP that we get and install it like in my image.

IMG_20211016_190217.jpg

Next, do the settings on the VM you created.

IMG_20211016_190335.jpg

After the installation process is successful, our website will appear like the example below.

IMG_20211016_190619.jpg

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iQRqKhAHHMT6UxacBhywrtyAQA9uagQvbDriLncoyixgvuZP3y8qfFPhY2FSAJ1Cf6bkttqXWea.png

Haproxy Installation Stages

At this stage we will start the process of creating the Haproxy server.

IMG_20211016_190817.jpg

As before, make settings on the data server and also the location of the server.

IMG_20211016_191003.jpg

After the VM is successfully built, we can login via SSH and make settings on our Haproxy like the following example.

IMG_20211016_191159.jpg

After we input the parameters on Haproxy, we can apply our website, he can access it via the IP of Haproxy so that when one of the VM Websites has a problem, the website will still be accessible, which is why it is recommended to use the data domain to access your website.

IMG_20211016_191405.jpg

You have to access the status from Haproxy via URL access:

http://ip_haproxy:1991/stats this link can be active or inactive, depending on the specifications of the user.

By entering the username and password that we created earlier.

IMG_20211016_191649.jpg

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iQRqKhAHHMT6UxacBhywrtyAQA9uagQvbDriLncoyixgvuZP3y8qfFPhY2FSAJ1Cf6bkttqXWea.png

Stage of Creating New VM Maria DB

Here to perform the need for database centralization, we can also separate the database server that we will use by the two website VMs that we created earlier. Next we will enter the process of creating a new VM through the App Catalog, namely MariaDB.

IMG_20211016_191922.jpg

First we go to the stage of creating a new VM in the IDCloudhost VPS cloud, which first creates a VM and selects the MariaDB Catalog App.

IMG_20211016_192111.jpg

Then set the settings as before.

IMG_20211016_192243.jpg

Then the VM will create and after that get a public IP like the following image.

IMG_20211016_192400.jpg

Next we can login to our SSH VM through the panel or use the ssh Client with the password and username that we set earlier.

IMG_20211016_192525.jpg

After successful login, we need to create a database that we will use for our website, in this example I use wordpress, then we can enter our mysql with the following command:

mysql

Next we can type the following command to create a database and user.

CREATE DATABASE wp_myblog;
CREATE USER 'userwp'@'%' IDENTIFIED BY 'mypassword';
GRANT ALL ON wp_myblog.* TO 'userwp'@'%';
FLUSH PRIVILEGES;
EXIT;

Securing our database server by typing the following command.

sudo mysql_secure_installation

For those whose default password is our root database user, which is empty, then we do enter and then we set our database root password to make it more secure.

IMG_20211016_193206.jpg

Next I advise you to select agree by typing Y on your keyboard and enter as follows.

IMG_20211016_193315.jpg

After we secure access to the database server we need to open our database access so that we can access it from a network other than the local network, then in the terminal we can open the file

/etc/mysql/mariadb.conf.d/50-server.cnf using Text editors like vi or nano, nano /etc/mysql/mariadb.conf.d/50-server.cnf

Then we look for the following line.

bind-address = 127.0.0.1 then we change it to bind-address = 0.0.0.0

Then we save the file and restart our database service with the command code:

systemctl restart mysql

At this stage we can access the database server from outside so we can login to our 2 VM websites via ssh and make changes to the /var/www/html/wp-config.php file with the following command code:

sudo nano /var/www/html/wp-config.php

Then adjust the database connection configuration to be like the following example:

define( 'DB_NAME', 'wp_myblog' );
define( 'DB_USER', 'userwp' );
define( 'DB_PASSWORD', 'my password' );
define( 'DB_HOST', 'fill_with_ip_server_database' );

Do this on both web servers, then we can open the IP address of our Haproxy server and reinstall Wordpress.

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iQRqKhAHHMT6UxacBhywrtyAQA9uagQvbDriLncoyixgvuZP3y8qfFPhY2FSAJ1Cf6bkttqXWea.png

Benefits

Using Haproxy on a Cloud VPS can make it easier for us to take a few steps compared to setup on other servers. Load balancing is a method of dividing traffic to several different servers in order to prevent overloading of slow servers.

Other benefits that we can get from Load Balancing such as maximum performance and saving server resources. Of course this technology helps us. If you get a lot of visitor traffic spikes. So to avoid overloading you can use this method.

Well, how do you make it easy. So this is all I can post on this occasion, hopefully it will be useful and thank you.

See next time

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iQRqKhAHHMT6UxacBhywrtyAQA9uagQvbDriLncoyixgvuZP3y8qfFPhY2FSAJ1Cf6bkttqXWea.png


About Me

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

KakaoTalk_20210722_161522824.gif

Your post has been selected in best picks.

Thanks for partition.

Good one Post dear friend you make a very good post thanks for sharing a good information with us my best wishes for you.
Regards, Faran Nabeel

Divider 2.png

You can delegate your SP to @siz-official and take benefit of our Delegation Offer getting up to 200 % Curation rewards

Quick Delegation to SIZ
501002003004005001000200030004000500010000

Nice post brother😁


image.png

Your post has been upvoted by @zero-to-infinity. We are supporting all the STEM Content Publish in Steemit.

For more,you can visit this community

JOIN WITH US ON DISCORD SERVER:

Support us by delegating STEEM POWER.
20 SP50 SP100 SP250 SP500 SP

Follow @zero-to-infinity & @steemitblog for latest updates