> For the complete documentation index, see [llms.txt](https://paul-gleason.gitbook.io/sec-300-elk-stack-for-security-operations/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://paul-gleason.gitbook.io/sec-300-elk-stack-for-security-operations/labs/lab-1-setting-up-elastic-in-aws.md).

# Lab 1 - Setting up Elastic in AWS

## Base Setup:

### Setup Instance:

<figure><img src="/files/10qhKV9GMzB7zAQ1tczO" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/M6jbkW9mWpeQtABJ5bW1" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/GVEB2E8PQLl8t8tNHyeM" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/bFGHoHtebcNrHamwDD18" alt=""><figcaption></figcaption></figure>

### Update Security Group

Port 5601: Kibana

Port 9200: Elasticsearch

<figure><img src="/files/0BKqEknpJUYKH6S0bTcb" alt=""><figcaption></figcaption></figure>

## Building ELK:

### Install Elasticsearch:

SSH into Instance:

<figure><img src="/files/UiV46xgoD8RNPafNJbHu" alt=""><figcaption></figcaption></figure>

Commands to install Elastic Search

<pre><code>wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

sudo apt-get update
sudo apt-get install apt-transport-https

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

<strong>echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
</strong>
sudo apt-get update
sudo apt-get install elasticsearch
</code></pre>

Now that we have installed Elasticsearch we must change some configs

It is a good best practice to bind Elasticsearch to the private IP (like 172.31.something):&#x20;

```
sudo nano /etc/elasticsearch/elasticsearch.yml
```

<figure><img src="/files/z6GN5zXXdNJUvJ99nou6" alt=""><figcaption></figcaption></figure>

Now to start Elasticsearch

```
sudo service elasticsearch start
```

Test Elasticsearch

```
curl http://<Private IP>:9200
```

### Install Logstash:

```
sudo apt-get install default-jre
```

Verify the java version with the command below

```
java -version
```

<figure><img src="/files/KqTxl3AKx1mQTXPCUpT0" alt=""><figcaption></figcaption></figure>

Now install logstash

```bash
sudo apt-get install logstash
```

#### Create data pipeline:

```bash
mkdir /logstash
cd /logstash
# pull down sample data
sudo chown -R logstash /logstash
sudo chgrp -R logstash /logstash
```

#### Create Logstash Configuration File:

```bash
sudo nano /etc/logstash/conf.d/apache-01.conf
```

<figure><img src="/files/zG8eO4yVW3woUxnMeFAo" alt=""><figcaption></figcaption></figure>

To test config

```bash
/usr/share/logstash/bin/logstash --config.test_and_exit -f /etc/logstash/conf.d/apache-01.conf
```

It can take a minute or so to run - but should get a configuration OK message

#### Start Logstash

```
sudo service logstash start
```

Test if it's working

```
curl http://<Private IP>:9200/_cat/indices?v
```

<figure><img src="/files/SISMiIFDavk9wC1zKQvh" alt=""><figcaption></figcaption></figure>

### Install Kibana:

```
sudo apt-get install kibana
```

Edit config

```
sudo nano /etc/kibana/kibana.yml
```

Change the lines below

```
server.port: 5601
server.host: '<YourPrivateIP>'
elasticsearch.hosts: ["http://<YourPrivateIP>:9200"]
```

Start Kibana

```
sudo service kibana start
```

Test Kibana

<figure><img src="/files/5iZYM3oxyNhlHMoWXbsF" alt=""><figcaption></figcaption></figure>

### Add an Index Pattern to display to Logstash Index

Go to Stack Management → Kibana -> Index Patterns - select “Create Index Pattern”

<figure><img src="/files/mpLKy03SnFRMgGBuPnp1" alt=""><figcaption></figcaption></figure>

#### Use Kibana to query data <a href="#docs-internal-guid-49f5a165-7fff-73fe-7560-783c5f3bdd9e" id="docs-internal-guid-49f5a165-7fff-73fe-7560-783c5f3bdd9e"></a>

<figure><img src="/files/eEu1Z0Ygwxuu5BjUMQ4p" alt=""><figcaption></figcaption></figure>
