𝗛𝗲𝗹𝗹𝗼 Friends !! Welcome you all to my article on Deployment of Haproxy Load Balancer and Multiple Web Servers on AWS Cloud Using Ansible. An overview of Ansible and AWS Services will also be present. Finally How can we utilize Ansible Scripts or Playbooks with AWS and Load Balancer for webserver deployment? We are also utilizing or building Ansible Playbook to create this application, as well as installing the Haproxy Load Balancer.
DESCRIPTION OF THE TASK: Deployment of Haproxy Load Balancer and Multiple Web Servers on AWS Cloud Using Ansible
- Using ansible, provision EC2 instances.
- Make the dynamic inventory idea, you may get the IP addresses of instances.
- Using the ansible role, configure the web servers.
- make the ansible role, configure the load balancer.
- The load balancer’s target nodes should auto-update based on the state of web servers.
- ⏩ We will deploy one HAPROXY load balancer on the AWS cloud and integrate it with numerous webservers operating on the AWS cloud in this work. Using Ansible Automation, the whole setup and configuration was completed in a single click.
Now let’s see how Deployment of Haproxy Load Balancer and Multiple Web Servers on AWS Cloud Using Ansible
COMPLETION OF THE TASK:
1) For AWS Cloud, everyone who contacts them is considered a client.
We’ll also use Ansible to start an instance on AWS Cloud, but how will Ansible communicate with AWS Cloud and launch the instance? Ansible uses Python libraries to setup everything behind the scenes. As a result, for AWS Cloud Python, there is a package called boto that connects Ansible to the AWS API too.
To install boto library use the command –>
pip3 install boto
2) To use Ansible to deploy a load balancer and webservers on AWS Cloud, we also utilize the Ansible ec2 module, which instructs Ansible to start an ec2 instance for the load balancer and webservers.
Playbook for Deploying Webserver Instances –>
Running the webserver instance playbook –>
ansible-playbook --ask-vault-pass playbook_name
Playbook for Deploying Load Balancer Instance –>
Running the Load Balancer Instance Playbook –>
✅ Now we can also see all the Instances are successfully launched through AWS GUI EC2 Console.
3) After the instances have been successfully launched, we must also obtain their public IP in order to configure them as a webserver and load balancer using Ansible. We’re also going to leverage the Dynamic Inventory idea to automatically obtain the target IP.
We utilize some python script code to generate the Dynamic Inventory, which can connect to the AWS cloud and retrieve the public IPs of active Instances.
Download the python scripts ec2.py and ec2.ini to dynamically get the IP address.
wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.ini
Now we also have to make these scripts files executable by changing the file permissions using command –>
chmod +x ec2.py chmod +x ec2.ini
As Ansible, you can also now connect to these python script files and navigate to the AWS Cloud and jobs. These scripts files needed to export various variables, which are listed below.
export EC2_INI_PATH='ec2.ini_file_path' export AWS_ACCESS_KEY_ID='aws_access_key' export AWS_SECERT_ACCESS_KEY='aws_secret_key'
4) Finally, we use the dynamic Inventory to dynamically obtain the IP of all Instances without the need for an Ansible Inventory file. Now we need to build an Inventory file for Ansible (/etc/myhosts.txt), in which I construct two groups named webserver and loadbalancer, which list the IP addresses that we acquired using dynamic Inventory.
Checking the connectivity of controller node with all target Instances using command –>
ansible -m ping all
Checking the list of all target hosts using command –>
ansible --list-hosts all
5) In Ansible World, creating Roles for various activities is always a smart practise in terms of effective administration and testing.
Ansible Roles are similar to work space folders that contain various files such as variables, tasks, and so on. As for our task, we must use the following command to create two separate roles, one for setting the webserver and the other for configuring the HAPROXY Load Balancer.
ansible-galaxy init role_name
We have to provide the path of destination where we created the roles to ansible configuration file .
We can see all the roles we created using the command –>
6) Now, let’s go to the heart of our problem: the HAPROXY Load Balancer.
We need to deploy the HAPROXY load balancer service on the AWS Instance we established, but there are a few adjustments we need to make to the HAPROXY cfg file first. To do this, I first installed the HAPROXY software on the controller node and made the following changes to the cfg file.
To install HAPROXY software use command ->
yum install haproxy -y
Changing some part in HAPROXY cfg file –>
We update the frontend main field to 8080 to bind and expose the HAPROXY load balancer to the public world, as seen in the above haproxy.cfg file. The load balancer must first know their back end servers, target instances, or nodes in order to do load balancing.
Since we changed the backend app field, the targets we configured as AWS web server instances should now automatically register with the HAPROXY load balancer.
This also allows us to work more quickly because we don’t have to manually register the instances with the HAPROXY load balancer.
7) To complete our responsibilities, we must also now employ the roles we defined. We also utilize the role we defined called webserver to configure web server on the instances we run on AWS. The tasks folder in this role contains the main.yml file. We must also write the task for installing and launching httpd services on instances in the main.yml file.
8) We also utilize the same role we generated named lb for HAPROXY load balancer setup on AWS Instance created. For configuring HAPROXY load balancer on AWS Instance, we must write the task in the main.yml file located in the tasks folder.
Handler file for HAPROXY Load Balancer –>
9) Finally, the roles for the web server and the HAPROXY load balancer have been correctly set. Now we also develop a task3.yml playbook that handles the configuration of the web server and HAPROXY Load Balancer on AWS Instances.
One click the entire setup of deployment of HAPROXY Load Balancer and Web server on AWS done as shown below .
10) Now go to the AWS GUI Console and login to the Load Balancer Instance using SSH to test if Ansible correctly configured the HAPROXY services.
Finally we also see that HAPROXY services are properly configured and are in running status . Besides It Going inside haproxy.cfg file we can see that all the web server Instances we launch using Ansible has registered as Target Nodes or Target Instances for HAPROXY load balancer .
11) At last we can also see the load balancing of web server Instances by HAPROXY Load Balancer using public ip of Load Balancer Instance .
Related Articles: Deployment of Haproxy Load Balancer and Multiple Web Servers on AWS Cloud Using Ansible
- Benefits of Using Angular for Web Development 2021
- KALI Linux Not Prefer Software Development Ubuntu
- How to Write Business Proposal for Client with Sample Format
- Top 10 Best Coolest Movies Chris Hemsworth of all time
- How to Increase Maximum upload file size WordPress 2 MB to TB or terabyte import unlimited – click here
- PHP 8.0 vs PHP 7.4 and PHP 8.0 features performance benchmark install setup – Click here
- WordPress Fill the form and PDF sent on Email using Contact Form 7 – Click here
- How to fix hidden plugin editor on WordPress 2020 | I can’t find my plugin editor- Click here
- GTmetrix VS Pingdom VS Google PageSpeed Insights VS Lighthouse Best performance optimization- Click here
- How to install wordpres on local machine like window 10 linux and Mac – Click here
- C vs C++ Difference Between C vs C++ vs Python vs Java
- Who is the strongest character in Naruto
- Top 10 Penny Stocks Invest 2021 Higher Return in 2025 2030
- What companies has Elon Musk owned
- Top 15 Future technology predictions for 2025 2030
- 20 Ways to Increase Traffic to Your Website Blogs