Pieter Fiers
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # ELK ## Groepsleden Pieter Fiers Dieter Draelants Joeri Sprengers ## Common All components require the Elasticsearch GPG key. Add it to apt: ```shell= curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - ``` The Elasticsearch repo requires HTTPS: ```shell= sudo apt-get install apt-transport-https ``` Add the Elasticsearch apt repo to /etc/apt/sources.list.d/elastic-7.x.list: ```shell= echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list ``` Update apt: ```shell= sudo apt update ``` ## Elasticsearch Install Elasticsearch: ```shell= sudo apt install elasticsearch ``` First step for the basic configuration of elastic is in the elasticsearch.yml: ```shell= sudo nano /etc/elasticsearch/elasticsearch.yml ``` Here you gone gone give your cluster a name but also name your node. After this you also need to configure your hostname. After you have configured your hostname, you also specify which discovery type you gone chose, we chose single-node because we are only using 1 elastic node. ```yaml= network.host: 193.191.177.158 cluster.name: ELK node.name: elastic discovery.type: single-node ``` After you have configured your elasticsearch.yml file you start up the service. The second command is if you want it to start-up at boot. ```shell= sudo systemctl start elasticsearch sudo systemctl enable elasticsearch ``` If you have configured everything correctly, it should work. Now you can reach the application with localhost:9200, but you wanne reach it wit a dns you still need to configure couple of things. First go to your dns settings, in our case its in: ```shell= nano /etc/bind/zones/db.joeri-sprengers.sb.uclllabs.be ``` Here you add an cname record for you application. ``` elasticsearch IN CNAME @ ``` After you have done this you need to restart your dns service. ```shell= systemctl restart bind9.service ``` Now we gone create in apache a vhost, you can configure this in: ```shell= nano /etc/apache2/sites-available/001-wwwconfig-le-ssl.conf ``` Specifically we are gone create an secure connection, so first we add the vhost in the file: ``` <VirtualHost *:443> ServerName elasticsearch.joeri-sprengers.sb.uclllabs.be ServerAdmin webmaster@localhost ErrorLog ${APACHE_LOG_DIR}/elastic-error.log CustomLog ${APACHE_LOG_DIR}/elastic-access.log combined ProxyPass "/" "http://localhost:9200/" Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/secure.joeri-sprengers.sb.uclllabs.be-0001/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/secure.joeri-sprengers.sb.uclllabs.be-0001/privkey.pem </VirtualHost> ``` After you have added it to the config file you need to reload the apache service. ```shell= systemctl reload apache2.service ``` Now we can acces the application with the link http://elasticsearch.joeri-sprengers.sb.uclllabs.be/, but it still need an certificate before it can be called a safe site. So we run certbot or wait till it is runned by the crontab: ```shell= certbot -n --agree-tos --expand --apache --no-redirect -d secure.joeri-sprengers.sb.uclllabs.be -d supersecure.joeri-sprengers.sb.uclllabs.be -d elasticsearch.joeri-sprengers.sb.uclllabs.be ``` Now you have configured everything, and can you start configure the next part. ## Logstash Install Logstash: ```shell= sudo apt install logstash ``` We also need to start and enable start on reboot: ```shell= systemctl start logstash systemctl enable logstash ``` So actually first we tried making it work without Logstash, all went great. We could see logs get uptime feed of configured sites and such. But after enabling, getting it enabled it worked but after a few hours there were these errors saying the disk capacity was full. After pulling out our hairs for certain amount of time we found a solution that nobody mentioned in their solutions. It was under **Index Lifecycle Policies** where we found that you could cap how much data was being stored. (not comfirmed that this is actually working) So now for logstash after the install you really only need to edit 1 file (excluding the different beats) the `pipelines.yml`. Its actually best practice to put your pipeline(s) in the `/conf.d` subdirectory, `pipelines.yml` loads every file in this directory ending with *.conf* So this is our created pipeline. The first part is the input for which I configured 2 static file streams (for testing purposes) and one filestream that collects everything beat-related. Currently only the filebeat is linked to logstash the others are directly to elasticsearch. As you can see there is a type defined. This is used in the output part as we will see now. ``` # Beats -> Logstash -> Elasticsearch pipeline. input { file { path => "/var/log/auth.log" type => "syslog" } file { path => "/var/log/apache2/access.log" type => "apache" } beats { port => "5044" type => "beats" } } ``` Now for the output we have a basic system out. And then a 'if statement' that checks for the type - earlier defined in the input streams - when it matches it excecutes that specific part. They all neet to redirect to the host, beeing the elasticsearchserver and its corresponding port beeing 9200 by default. We can also give it a custom index that we can use to easly identify the dataset in kibana. For this there is also a standard beeing the name of the fileset followed by a '-' and then '%{+YYYY.MM.dd}' the last thing will automatically create the date of the dataset. ``` output { stdout {codec => rubydebug} if [type] == "syslog" { elasticsearch { hosts => ["http://elasticsearch.joeri-sprengers.sb.uclllabs.be:9200"] index => "syslogOnly-%{+YYYY.MM.dd}" #user => "elastic" #password => "changeme" } } if [type] == "apache" { elasticsearch { hosts => ["http://elasticsearch.joeri-sprengers.sb.uclllabs.be:9200"] index => "apache_accessOnly-%{+YYYY.MM.dd}" #user => "elastic" #password => "changeme" } } if [type] == "beats" { elasticsearch { hosts => ["http://elasticsearch.joeri-sprengers.sb.uclllabs.be:9200"] index => "beatsby-%{+YYYY.MM.dd}" #user => "elastic" #password => "changeme" } } } ``` After everychange its also important to restart logstash by writing: ```shell= systemctl restart logstash ``` ## Beats So this part is about the different beats that we've installed (or tried to). Most of these have a similar installation and configuration but we'll address them quickly in each part. ### Filebeat After you start Filebeat, open the Logs UI and watch your files being tailed right in Kibana. Use the search bar to filter by service, app, host, datacenter, or other criteria to track down curious behavior across your aggregated logs. Filebeat ships with modules for observability and security data sources that simplify the collection, parsing, and visualization of common log formats down to a single command. They achieve this by combining automatic default paths based on your operating system, with Elasticsearch Ingest Node pipeline definitions, and with Kibana dashboards. Plus, a few Filebeat modules ship with preconfigured machine learning jobs. Lastly a interesting fact. Filebeat uses a backpressure-sensitive protocol when sending data to Logstash or Elasticsearch to account for higher volumes of data. If Logstash is busy crunching data, it lets Filebeat know to slow down its read. Once the congestion is resolved, Filebeat will build back up to its original pace and keep on sending data'. Install filebeat: ```shell= sudo apt-get install filebeat ``` ### Metricbeat Metricbeat can be deployed on all your Linux, Windows, and Mac hosts, connect it to Elasticsearch and voila: you get system-level CPU usage, memory, file system, disk IO, and network IO statistics, and thons off other system statistics. We had some issues with visualising some of this data though. Install metricbeat: ```shell= sudo apt-get install metricbeat ``` ### Heartbeat Heartbeat makes it easy to generate uptime and response time data. You can track availability of your websites, services and even see when your TLS is going to expire Install heartbeat: ```shell= sudo apt-get install heartbeat ``` ### Auditbeat Monitor user activity and processes, and analyze your event data in the Elastic Stack without touching auditd. Auditbeat communicates directly with the Linux audit framework, collects the same data as auditd, and sends the events to the Elastic Stack in real time. Install auditbeat: ```shell= sudo apt-get install auditbeat ``` This is the one that didn't work and I think it has something to do about us running on containers or something. It just always gave the error that I didn't have enough permissions while I gave the user root permissions. ## Kibana Install Kibana: ```shell= sudo apt install kibana ``` Add reference to Elasticsearch node: in `/etc/kibana/kibana.yml` ``` elasticsearch.hosts: ["http://elasticsearch.joeri-sprengers.sb.uclllabs.be:9200"] ``` Configure HTTP reverse proxy: I use a Ansible playbook to configure Nginx and run certbot - [see GitHub](https://github.com/ubipo/syb/blob/master/etc/ansible/deploy-http-server.yml#L147) ### Visualisations There are two types classes visualisations: _Lens_ and traditional. Lens visualisations are easier to create but are less versatile (no customisation of legend, no custom aggregations...). The easiest way to create a Lens visualisation is to use the "Discover" tool (under Kibana in the hamburger menu). ![](https://i.imgur.com/4xmCMLi.png) Use the "Search field names" box to find a metric to visualise. The hash indicates a number field, "t" text and so on. Click "Visualize" to open the Lens editor. ![](https://i.imgur.com/aH21TrA.png) ![](https://i.imgur.com/U1MvJwY.png) <br> The simplest way to create a traditional visualization is to first create a dashboard under `Kibana > Dashboard` and to then click "Create new" in edit mode. ![](https://i.imgur.com/GxUDQ86.png) The configuration for our network usage graph looks like this: ![](https://i.imgur.com/FXSItgH.png) Combined with two gauges we created a simple monitoring dash: ![](https://i.imgur.com/gU3t2ez.png) ### Index Lifecycle Policies We experienced quite a bit of problems involving storage capacity and partially broke the entire stack multiple times while trying to clear space on disk. Luckily there exists a better solution than manually deleting indices: "Index Lifecycle Policies". These policies define how long logs are retained for a certain index. We added a 5GB, 4 hours retention policy to all our indices. ![](https://i.imgur.com/yYuzxLY.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully