Configuration of load balancer using haproxy on aws cloud with the help of ansible.

Configuration of load balancer using haproxy on aws cloud with the help of ansible.

In this task we will configure load balancer using haproxy and backend servers will be configured as webserver which are ec2 instances using ansible.

What is load balancer and how it works?

Load balancing is defined as the methodical and efficient distribution of network or application traffic across multiple servers in a server farm. Each load balancer sits between client devices and backend servers, receiving and then distributing incoming requests to any available server capable of fulfilling them.

For load balancing we use haproxy.

What is ansible?

Ansible works by connecting to your nodes and pushing out small programs, called "Ansible modules" to them. These programs are written to be resource models of the desired state of the system. Ansible then executes these modules (over SSH by default), and removes them when finished.

What is haproxy?

HAProxy is free, open source software that provides a high availability load balancer and proxy server for TCP and HTTP-based applications that spreads requests across multiple servers. It is written in C and has a reputation for being fast and efficient (in terms of processor and memory usage)

Steps:

Step 1:

Deploy EC2 instance

Here deploy ec2 instance using ec2 module the values for parameters in module are taken from variable file.

Here set count to 3 which will launch 3 ec2 instances.

ec2.yml:

No alt text provided for this image

aws_vars.yml:

No alt text provided for this image

aws_cred.yml is vault containing access key and secret key of aws account.

vault creation:

No alt text provided for this image

aws_cred.yml:

In this file provide credentials

No alt text provided for this image

And now you can run ansible playbook.

No alt text provided for this image
No alt text provided for this image

Three ec2 instances will be launched.

No alt text provided for this image

Step 2:

Creation of Dynamic inventory

What is dynamic inventory?

As described in Working With Dynamic InventoryAnsible can pull inventory information from dynamic sources, including cloud sources. You can also create a new dynamic inventory provider by creating a script or program that can output JSON in the correct format when invoked with the proper arguments.

Use dynamic inventory for ec2 instances which will automatically tell us about ec2 instances launched. These inventories are available on ansible community.

Download those files using wget command from github.

No alt text provided for this image

And set their path as inventory in ansible config file.

No alt text provided for this image

Change python version from ec2.py according to version of pyhton on your VM.

No alt text provided for this image

And export ansible credentials variables.

No alt text provided for this image

You can see ec2 instances using list hosts option of ansible.

No alt text provided for this image

Step 3:

Configure EC2 instance as webserver using role.

Set path of roles in ansible configuration file.

Roles:

No alt text provided for this image

tasks/main.yml:

No alt text provided for this image

Apply the role using yml file.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Webservers are configured.

Step 4:

Configure localhost as loadbalancer by applying created role.

lb/tasks/main.yml:

No alt text provided for this image

templates/haproxy.cfg:

This file is config file of haproxy the changes are done for bind port and set loop for backend servers (Here are ec2 instances)

No alt text provided for this image

What is bind?

A bind setting assigns a listener to a given IP address and port. The IP can be omitted to bind to all IP addresses on the server and a port can be a single port, a range, or a comma-delimited list. You’ll often use the ssl and crt arguments to instruct HAProxy to manage SSL/TLS terminations, rather than having your web servers doing that.

-Apply the loadbalancer role using yml file

No alt text provided for this image
No alt text provided for this image

Loadbalancer is configured.

Output:

No alt text provided for this image

Here you can see load balancing is achieved.

Thank you for reading!!

Ninad Deogaonkar

SDE I at Hewlett Packard Enterprise

4 年

Nice

回复

要查看或添加评论,请登录

Akanksha Jamdade的更多文章

  • Static Partition in Linux OS

    Static Partition in Linux OS

    Static Partition This is the oldest and simplest technique used to put more than one processes in the main memory. In…

    2 条评论
  • Network topology: Can ping Google but not Facebook

    Network topology: Can ping Google but not Facebook

    Network terminologies: Before starting the setup we will go through some network terminologies which will be used in…

  • Configuration of webserver and python3 on docker container

    Configuration of webserver and python3 on docker container

    What is docker? Docker is an open platform for developing, shipping, and running applications. Docker enables you to…

  • Kubernetes & its Use cases

    Kubernetes & its Use cases

    What is Kubernetes? Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and…

  • AWS SQS & case study : Oyster

    AWS SQS & case study : Oyster

    What is Amazon SQS? Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to…

  • High Availability Architecture with AWS CLI

    High Availability Architecture with AWS CLI

    What is S3? Amazon S3 or Amazon Simple Storage Service is a service offered by Amazon Web Services (AWS) that provides…

    2 条评论
  • Ansible Use cases

    Ansible Use cases

    What is Ansible? Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration…

    2 条评论
  • Artificial Intelligence(AI), Machine Learning(ML) and Spotify

    Artificial Intelligence(AI), Machine Learning(ML) and Spotify

    What is AI? Artificial intelligence (AI) refers to the simulation of human intelligence in machines that are programmed…

    4 条评论
  • Launch EC2 instance through CLI

    Launch EC2 instance through CLI

    Here in this task we are going to launch EC2 instance of AWS through CLI. So first you have to download AWS CLI program…

    4 条评论
  • Unilever Case Study

    Unilever Case Study

    What is cloud computing? Cloud computing is the on-demand delivery of IT resources over the Internet with pay-as-you-go…

    7 条评论

社区洞察

其他会员也浏览了