How to Install and Configure ELK stack using Ansible playbook on AWS Ubuntu

Photo by Brooke Lark on Unsplash

How to Install and Configure ELK stack using Ansible playbook on AWS Ubuntu

Prerequisites:

  1. AWS account

Tight your grip on the handle as we start on this rollercoaster ride

image.png

Step 1. Create an EC2 instance

Create 2 EC2 instances (ansible-master and ansible-node) with t2.xlarge instance type.

image.png

image.png

Step 2. Setup ansible in ansible-master

Install ansible in ansible-master

To install and setup ansible in the Master node use the below commands(as root):

sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible

To check if successfully installed or not

ansible --version

image.png

To Generate SSH key

ssh-keygen

image.png

Copy the key generated for further use.

 cat /root/.ssh/id_rsa.pub

image.png

Step 3. Configuring ansible-node

In ansible-node type the following command:

cd .ssh

Open authorized_keys file using your vim code editor.

sudo vim authorized_keys

And paste the key generated in Step 2. and save the file.

image.png

Install net-tools package to IP address of ansible-node.

sudo apt install net tools

Now get the I.P. Address of the ansible-node using ifconfig

ifconfig

image.png The IP address of ansible-node is 172.31.37.110(yours will be different)

In the ansible-master
Try establishing an SSH connection from the ansible-master using the below command:

ssh 172.31.37.110

(Note: Change 172.31.37.110 with your ansible-node IP address.)

image.png

Type exit to exit from ssh connection.

Step 4. Establishing Connection between ansible-master and ansible-node.

In the ansible-master Edit the hosts file located in /etc/ansible/hosts

vim /etc/ansible/hosts

Add the following line in hosts file

[node]
172.31.37.110

image.png

Save and exit the file.

To test if the ansible-master is connected to ansible-node type the below command in ansible-master:

ansible -m ping all

image.png

Final Step. Running ansible-playbook

image.png

(Note: All the below commands are for ansible-master) Cloning the ansible playbook from GitHub.

git clone https://github.com/Abhishek-569/ansible-elk-playbook.git
cd  ansible-elk-playbook/
cd ansible-elk-playbook/

(Repetition is not a mistake) You can now see the content of main.yml and the roles folder in the current directory.

image.png

ansible-playbook  main.yml

image.png

image.png

Changing the in-Bound rules of security-group

To establish an HTTP connection with ElasticSearch (running at :9200 port) and Kibana(running at :5601 port) Change the inbound rules of the security group associated with ansible-node.

image.png

That is done now you can access the ElasticSearch at the public IP address of ansible-node with port 9200.(HTTP://{your_ansible-node_public_ip}:9200)

image.png And kibana at (HTTP://{your_ansible-node_public_ip}:5601)

image.png

----------------------------------------------The END---------------------------------------------------- image.png