# Lab 1 - Setting up Elastic in AWS

## Base Setup:

### Setup Instance:

<figure><img src="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FqsRuHl4EL7DtLBWfYXqp%2Fimage.png?alt=media&#x26;token=db7b49e3-fbfe-4bfa-b7f2-21a958beb5a6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FhfxXxmEqHg1Dk1eBy0iO%2Fimage.png?alt=media&#x26;token=13d06301-83e7-4b69-b33b-373f5fc5c2a8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2F9DhE6laOtO99A3hafwyt%2Fimage.png?alt=media&#x26;token=e4db52bb-c8d1-4acd-bd17-677bdf3255ec" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FKT4flXSSKOISg2HsitBJ%2Fimage.png?alt=media&#x26;token=66112dbe-6bbf-4d69-bd2f-8ecd9ca9e259" alt=""><figcaption></figcaption></figure>

### Update Security Group

Port 5601: Kibana

Port 9200: Elasticsearch

<figure><img src="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FBJ678ucPBtKxaP4TCEqU%2Fimage.png?alt=media&#x26;token=6a1cf0c1-0e8f-4812-af9a-5d3600999fdd" alt=""><figcaption></figcaption></figure>

## Building ELK:

### Install Elasticsearch:

SSH into Instance:

<figure><img src="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2F9Qhl0BRFti1FZfjczcK2%2Fimage.png?alt=media&#x26;token=1ab736fe-e98f-4ca0-972f-d21243bfeb99" 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="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FjUzbU2BQwE8HhHtPnwUg%2Fimage.png?alt=media&#x26;token=13bc5309-05ef-4bd2-8737-ea55be78b840" 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="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2F1qTy7VQNxHLiPnr82jpK%2Fimage.png?alt=media&#x26;token=3927ab83-c970-43fc-b0a7-fcee93eff36e" 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="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FBFzrFik1dlRTEBodzJfo%2Fimage.png?alt=media&#x26;token=f8244214-4ead-421d-8bcd-31a9a7e6e25a" 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="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FeGNj6rApoajOXVgW3iQf%2Fimage.png?alt=media&#x26;token=29c391c9-4e8c-4c5c-a263-6dd08931ea57" 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="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FG5PMJ3u0Lry5fzM032Zy%2Fimage.png?alt=media&#x26;token=3259f392-3f67-410f-80f9-76b62ef07776" 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="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FLguSqLlBRLvzDeI1c7vu%2Fimage.png?alt=media&#x26;token=a976b66e-aefb-4258-9ed5-9093f4695179" 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="https://2873795674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwCXGslyd2ZF1jbJFU9rw%2Fuploads%2FcblzOwdFWOUcPllpohlA%2Fimage.png?alt=media&#x26;token=1885fbbf-bb01-473c-91a3-cb8a886b6987" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://paul-gleason.gitbook.io/sec-300-elk-stack-for-security-operations/labs/lab-1-setting-up-elastic-in-aws.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
