본문 바로가기
서버 및 보안

Installing Elasticsearch 5.0.0 and Kibana 5.0.0 on Debian

by 다움위키 2023. 12. 25.

Installing ELK stack on Debian를 작성한지 얼마 되지 않아 ELK가 판번호를 통일하면서 5.0.0을 출시했습니다. 큰 그림은 바뀌지 않았지만, 조금씩 변한 내용을 위주로 새롭게 문서를 만들어 봤습니다.

Elasticsearch 5.x 설치

설정 파일 /etc/elasticsearch/elasticsearch.yml을 확인합니다.

network.host: localhost

  • sudo systemctl restart elasticsearch

이제 elasticsearch가 기동해서 동작중일 것입니다. 다음으로 이 상황을 확인할 수 있습니다.

  • netstat -plntu

tcp6 0 0 127.0.0.1:9200  :::* LISTEN -

또는

  • curl -XGET 'localhost:9200/?pretty'
{
  "name" : "HgZJVum",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "d7cJY700T6K4QvI3ewtLkA",
  "version" : {
    "number" : "5.6.11",
    "build_hash" : "bc3eef4",
    "build_date" : "2018-08-16T15:25:17.293Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  },
  "tagline" : "You Know, for Search"
}

또는 브라우저로 http://localhost:9200 로 접근해 봅니다.

Kibana 5.0.0 설치

  • sudo apt-get install kibana

설정 /etc/kibana/kibana.yml을 확인합니다.

server.host: localhost

  • sudo systemctl start kibana

http://localhost:5601 로 접근합니다.

Logstash 5.0.0 설치

  • sudo apt-get install logstash
  • cd /usr/share/logstash
  • sudo bin/logstash-plugin install logstash-input-beats

설정 /etc/logstash/conf.d/logstash.conf을 확인합니다.

input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
    hosts => "localhost:9200"
    manage_template => false
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
    document_type => "%{[@metadata][type]}"
  }
}

Packetbeat 5.0.0 설치

  • sudo apt-get install packetbeat

설정 /etc/packetbeat/packetbeat.yml을 확인합니다.

# Select the network interface to sniff the data. On Linux, you can use the
# "any" keyword to sniff on all connected interfaces.
packetbeat.interfaces.device: any
...
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["localhost:9200"]
  template.name: "packetbeat"
  template.path: "packetbeat.template.json"
  template.overwrite: false
...
output.logstash:
  # The Logstash hosts
  hosts: ["localhost:5044"]

수동으로 packetbeat.template.jason을 넣고 싶다면 모든 서비스를 켠 후에:

{"acknowledged":true}

점검을 하고 싶다면:

...
          "port" : 11211,
          "proc" : "",
          "responsetime" : 0,
          "server" : "dawoum",
          "status" : "OK",
          "transport" : "tcp",
          "type" : "memcache"
        }
      }
    ]
  }
}

Metricbeat 5.0.0 설치

  • sudo apt-get install metricbeat

설정 /etc/metricbeat/metricbeat.yml을 확인합니다.

metricbeat.modules:
- module: system
  metricsets:
    - cpu
    - filesystem
    - memory
    - network
    - process
  enabled: true
  period: 10s
  processes: ['.*']
  cpu_ticks: false
...
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["localhost:9200"]
  template.name: "metricbeat"
  template.path: "metricbeat.template.json"
  template.overwrite: false
...
output.logstash:
  # The Logstash hosts
  hosts: ["localhost:5044"]
  • sudo systemctl enable metricbeat
  • sudo systemctl start metricbeat

수동으로 metric.template.jason을 넣고 싶다면 모든 서비스를 켠 후에:

{"acknowledged":true}

점검을 하고 싶다면:

...
          "@version" : "1",
          "host" : "dawoum",
          "metricset" : {
            "rtt" : 173,
            "module" : "system",
            "name" : "network"
          },
          "type" : "metricsets",
          "tags" : [
            "beats_input_raw_event"
          ]
        }
      }
    ]
  }
}

FileBeat 5.x 설치

  • sudo apt-get install filebeat

설정 /etc/filebeat/filebeat.yml을 확인합니다.

- input_type: log

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /var/log/*.log
    #- /var/log/auth.log #이것과 아래줄을 이용하기도 합니다.
    #- /var/log/syslog
...
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["localhost:9200"]
  template.name: "filebeat"
  template.path: "filebeat.template.json"
  template.overwrite: false
...
output.logstash:
  # The Logstash hosts
  hosts: ["localhost:5044"]
  • sudo systemctl enable filebeat
  • sudo systemctl start filebeat

수동으로 filebeat.template.jason을 넣고 싶다면:

{"acknowledged":true}

점검을 하고 싶다면,

...
          "input_type" : "log",
          "host" : "dawoum",
          "source" : "/var/log/auth.log",
          "message" : "Nov  1 21:14:03 dawoum sudo: pam_unix(sudo:session): session opened for user root by (uid=0)",
          "type" : "log",
          "tags" : [
            "beats_input_codec_plain_applied"
          ]
        }
      }
    ]
  }
}

Importing Existing Beat Dashboards

개발자들이 만들어 놓은 index와 dashboard를 가져와서 사용해 보겠습니다. filebeat는 dashboard가 없고 index-pattern만 있습니다.

  • cd /usr/share/filebeat
  • ./scripts/import_dashboards
Create temporary directory /tmp/tmp389313006
Downloading https://artifacts.elastic.co/downloads/beats/beats-dashboards/beats-dashboards-5.0.0.zip
Unzip archive  /tmp/tmp389313006
/tmp/tmp389313006/beats-dashboards-5.0.0/filebeat
Import directory  /tmp/tmp389313006/beats-dashboards-5.0.0/filebeat/index-pattern
Import index to /.kibana/index-pattern/filebeat-* from /tmp/tmp389313006/beats-dashboards-5.0.0/filebeat/index-pattern/filebeat.json
No directory /tmp/tmp389313006/beats-dashboards-5.0.0/filebeat/dashboard
/tmp/tmp389313006/beats-dashboards-5.0.0/metricbeat
/tmp/tmp389313006/beats-dashboards-5.0.0/packetbeat
/tmp/tmp389313006/beats-dashboards-5.0.0/winlogbeat
  • cd /usr/share/packetbeat
  • ./scripts/import_dashboards
...
Import vizualization  /tmp/tmp665702230/beats-dashboards-5.0.0/packetbeat/visualization/Slowest-Thrift-RPC-methods.json
Import search  /tmp/tmp665702230/beats-dashboards-5.0.0/packetbeat/search/Thrift-transactions.json
Import vizualization  /tmp/tmp665702230/beats-dashboards-5.0.0/packetbeat/visualization/Thrift-response-times-percentiles.json
Import search  /tmp/tmp665702230/beats-dashboards-5.0.0/packetbeat/search/Thrift-transactions.json
Import vizualization  /tmp/tmp665702230/beats-dashboards-5.0.0/packetbeat/visualization/Top-Thrift-RPC-methods.json
Import search  /tmp/tmp665702230/beats-dashboards-5.0.0/packetbeat/search/Thrift-transactions.json
Import vizualization  /tmp/tmp665702230/beats-dashboards-5.0.0/packetbeat/visualization/Top-Thrift-RPC-calls-with-errors.json
Import search  /tmp/tmp665702230/beats-dashboards-5.0.0/packetbeat/search/Thrift-errors.json
/tmp/tmp665702230/beats-dashboards-5.0.0/winlogbeat
  • cd /usr/share/metricbeat
  • ./scripts/import_dashboards
...
Import search  /tmp/tmp165362232/beats-dashboards-5.0.0/metricbeat/search/System-stats.json
Import vizualization  /tmp/tmp165362232/beats-dashboards-5.0.0/metricbeat/visualization/System-load.json
Import search  /tmp/tmp165362232/beats-dashboards-5.0.0/metricbeat/search/Load-stats.json
Import vizualization  /tmp/tmp165362232/beats-dashboards-5.0.0/metricbeat/visualization/CPU-Usage.json
Import search  /tmp/tmp165362232/beats-dashboards-5.0.0/metricbeat/search/Cpu-stats.json
/tmp/tmp165362232/beats-dashboards-5.0.0/packetbeat
/tmp/tmp165362232/beats-dashboards-5.0.0/winlogbeat

Nginx 설정(선택사항)

현재 시스템의 설정을 남겨두고 외부에서 kibana를 접근하기 위해서는 다른 포트를 사용해야 합니다. 먼저 kibana를 접근하기 위한 사용자와 암호를 만듭니다.

  • sudo -v
  • echo "kibanaadmin:`openssl passwd -apr1`" | sudo tee -a /etc/nginx/htpasswd.users

이제 nginx의 설정 /etc/nginx/sites-available/kibana을 만들어서 기동합니다.

server {
    listen 8000;

    server_name elk_server_name;

    auth_basic "Restricted Access";
    auth_basic_user_file /etc/nginx/htpasswd.users;

    location / {
        proxy_pass http://elk_server_ip:5601;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

설정을 연결하고 nginx를 새롭게 기동합니다.

  • cd /etc/nginx/sites-enabled
  • sudo ln -sf /etc/nginx/sites-available/kibana .
  • sudo systemctl restart nginx
  • sudo ufw allow 8000

http://FQDN:8000 으로 접근하시면, http://localhost:5601 로 연결이 됩니다.

사용해 보기

http://localhost:5601 로 접근하셔서 Management->Index patterns->Add new에서 filebeat-*, packetbeat-*, 또는 metricbeat-*중에 하나를 입력한 후에 Time-field name@timestamp를 선택하고 Create를 누르면 데이터가 생성됩니다.

이후에 Discover를 누르면 데이터를 볼 수 있습니다.

Dashboard에서는 Open을 누르면 기존에 로딩되었던 MetricbeatPacketbeat dashboard를 불러올 수 있습니다.

X-pack 설치

  • cd /usr/share/elasticsearch
  • sudo bin/elasticsearch-plugin install x-pack
-> Downloading x-pack from elastic
[=================================================] 100%   
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.lang.RuntimePermission accessClassInPackage.com.sun.activation.registries
* java.lang.RuntimePermission getClassLoader
* java.lang.RuntimePermission setContextClassLoader
* java.lang.RuntimePermission setFactory
* java.security.SecurityPermission createPolicy.JavaPolicy
* java.security.SecurityPermission getPolicy
* java.security.SecurityPermission putProviderProperty.BC
* java.security.SecurityPermission setPolicy
* java.util.PropertyPermission * read,write
* java.util.PropertyPermission sun.nio.ch.bugLevel write
* javax.net.ssl.SSLPermission setHostnameVerifier
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed x-pack

설정 /etc/elasticsearch/elasticsearch.yml을 추가합니다.

action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*
  • cd /usr/share/kibana
  • sudo bin/kibana-plugin install x-pack
...
Retrieving metadata from plugin archive
Extracting plugin archive
Extraction complete
Optimizing and caching browser bundles...
Plugin installation complete
  • sudo systemctl restart elasticsearch
  • sudo systemctl restart kibana

http://localhost:5601 로 접근해서 user: elastic passwd: changeme 를 입력한 후에 passwd를 바꾸어서 사용해 봅니다.

X-pack을 설치하면, 데이터가 삽입이 되지 않습니다. 사용자와 암호가 생겼기 때문에 이를 적절히 추가해 주어야 합니다. X-pack 설치시에 elastic, kibana라는 2개의 사용자와 암호는 changeme로 생성이 됩니다. 암호는 Management에서 바꿀 수 있습니다만 데이터 삽입과 관련된 정보가 명확하지 않습니다. 우선은 파일에 사용자를 생성하는 방법에 대해 읽어볼 수 있습니다.

x-pack 제거

  • cd /usr/share/elasticsearch
  • sudo systemctl stop elasticsearch
  • sudo bin/elasticsearch-plugin remove x-pack
  • sudo rm -rf /etc/elasticsearch/x-pack
  • cd /usr/share/kibana
  • sudo systemctl stop kibana
  • sudo bin/kibana-plugin remove x-pack
제거한 후에 재설치하면 로긴을 할 수 없습니다. 좀 더 정보가 필요합니다. 브라우저에서 세션 유지 시간이 지나면 접속이 됩니다.

External Resources