Apache Webserver and Haproxy server configuration on AWS with Ansible

Apache Webserver and Haproxy server configuration on AWS with Ansible

Hello connections, in this blog i am going to configure Apache webserver and Haproxy server on AWS EC2 instance using Dynamic Inventory of Ansible playbook, i am going to write a ansible playbook for this whole setup. First of all, before configuration we should have basic knowledge about Ansible Dynamic Inventory, Ansible playbook, Apache web server, Haproxy server and about AWS EC2 Instance.

Requirements to Implement this setup:

  • You should have a AWS Acount.
  • you should have a IAM User.
  • you should have Ansible with python interpreter in your Control Node

In this setup Controller Node of Ansible will be my local VM with OS RHL8, while Target Node will be AWS EC2 Instance.

Lets Implement the setup

Step 1

First of all i am going to launch three AWS EC2 Instance using ansible playbook, I use one of instance to run haproxy server and two instance to run webserver.

No alt text provided for this image

Above playbook launch two AWS EC2 instance to configure as web server.

No alt text provided for this image

Above playbook launch one AWS EC2 instance to configure as haproxy server.

No alt text provided for this image

Three AWS EC2 Instance are created as above we can see.

Step 2

In this step i am gonna setup Dynamic Inventory on my Controller Node. Dynamic Inventory helps us to fetch the ip address of our Target Node, it means at runtime of playbook ip of Target Nodes are fetched. To set Dynamic Inventory we need two files ec2.py and ec2.ini. To download these file use the link with wget command on terminal

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

Step 3

After downloading these files we need to make both files executable, we can do so with the command chmod as

chmod +x ec2.py ec2.ini

To run these files we need boto and boto3 SDK, we need to install these SDK in our system i install these libraries in my system with command pip3 install boto boto3.

Step 4

we need to do some modification on these files. In ec2.py, we need to update the path of python interpreter.

No alt text provided for this image

And in file ec2.ini we need to set our AWS access key along with secret key of IAM user.

No alt text provided for this image

Step 5

Along with above setup we need to export AWS Access Key, AWS Secret Key and AWS Region as Shell variable by running command on terminal:-

export AWS_ACCESS_KEY= 'put your access key'

export AWS_SECRET_KEY= 'put your secret key'

export AWS_REGION='put your region'

Now we need to update our ansible config file with these executable files. To do so i create a folder with name mydb with command mkdir /mydb, and move both files on mydb, and update the ansible config file as shown.

No alt text provided for this image

After this setup we need private key of AWS in Controller Node, by which we create EC2 Instance. so i put the private key on Controller Node.

No alt text provided for this image

And change the file permission of my private key file by using command: chmod 400 master.pem

No alt text provided for this image

Step 6

Run command ansible all --list-hosts to show list of ips of hosts(Target node)

No alt text provided for this image

Step 7

To check connectivity with Target Node from Control Node we can run the command:- ansible all -m ping, here in my setup i can able to ping my Target Node from Control Node as shown.

No alt text provided for this image

Step 8

Run ec2.py file on terminal to get tag name of web server and haproxy server. we use these tag name in our playbook.

No alt text provided for this image

Step 9

Now to configuring Haproxy Remotely first we need to install the Load Balancer locally and need to do some configuration in the haproxy conf file, to install haproxy use command :- yum install haproxy -y

Now go inside the configuration file of haproxy Server /etc/haproxy/haproxy.cfg and make the changes as below. In this config file, i set the port no. 8000 to serve the service.

No alt text provided for this image

Step 10

Now, write ansible playbook to configure web server and haproxy server on EC2 Instance.

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

Step 11

Run playbook using command: ansible-playbook <playbook_name.yml>, my playbook ran successfully.

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

Step12 :- Testing the setup

No alt text provided for this image

haproxy server running successfully.

No alt text provided for this image

Apache httpd web server also running successfully. To access the web page we need to use Ip of haproxy server, that serve our web page on port 8000, as we set port no. of haproxy server 8000.

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

Finally, got result the whole setup done successfully.

Happy Reading !!

Thank You !




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

Niraj Kumar的更多文章

  • Deployment Of Machine Learning model inside Docker Container

    Deployment Of Machine Learning model inside Docker Container

    Hello connections!! In this article, i am going to deploy a machine learning model inside docker container. To run…

  • Ansible playbook for K8S multinode cluster on AWS

    Ansible playbook for K8S multinode cluster on AWS

    Hello connections!! In this blog i am going setup multi node kubernetes cluster setup on AWS by using Ansible. I wrote…

  • Case Study On AWS SQS Service

    Case Study On AWS SQS Service

    Hello connections, In this blog i am gonna discuss about SQS service of Amazon. What is Amazon SQS ? Amazon SQS is a…

  • Case Study On OpenShift

    Case Study On OpenShift

    Hello Connections, in this blog i am gonna discuss about openshift as a technology and its use cases. what is OpenShift…

  • Industry Usecases Of Jenkins

    Industry Usecases Of Jenkins

    Hello connections!! In this blog i am going to talk about Jenkins which is a automation tool/ software, mostly used in…

  • GUI Application with docker

    GUI Application with docker

    hello folks!! In this blog i am going to explain how we can run a GUI application on Docker Container. First of all we…

  • Network Topology setup

    Network Topology setup

    Hello Folks!! In this blog i am gonna discuss how we can create a network topology setup. There are three systems…

  • Amdocs with AWS cloud services

    Amdocs with AWS cloud services

    Amazon Web Services (AWS) is an evolving cloud computing platform that provides on-demand service to individuals…

  • Azure Kubernetes Service

    Azure Kubernetes Service

    Kubernetes is by far the most popular container orchestration tool, yet the complexities of managing the tool have led…

  • Neural Network

    Neural Network

    What are Neural Networks? Neural networks are a set of algorithms, they are designed to mimic the human brain, that is…

    1 条评论

社区洞察

其他会员也浏览了