init
This commit is contained in:
commit
7b4a7ae250
18 changed files with 252 additions and 0 deletions
4
README.md
Normal file
4
README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# elk stack for opeenstack env
|
||||
|
||||
based on article
|
||||
https://habr.com/ru/articles/671344/
|
10
elk.yml
Normal file
10
elk.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
- name: elk
|
||||
hosts:
|
||||
- elk
|
||||
# vars:
|
||||
# SERVER_NAME: www.procdn.net
|
||||
gather_facts: no
|
||||
roles:
|
||||
- elk
|
||||
tags:
|
||||
- elk
|
4
inv.ini
Normal file
4
inv.ini
Normal file
|
@ -0,0 +1,4 @@
|
|||
host192-168-71-44 ansible_host=192.168.71.44 ansible_user=root ansible_port=22 ansible_python_interpreter=python3
|
||||
|
||||
[elk]
|
||||
host192-168-71-44
|
38
roles/elk/README.md
Normal file
38
roles/elk/README.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
Role Name
|
||||
=========
|
||||
|
||||
A brief description of the role goes here.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
|
||||
|
||||
Example Playbook
|
||||
----------------
|
||||
|
||||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
||||
|
||||
- hosts: servers
|
||||
roles:
|
||||
- { role: username.rolename, x: 42 }
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
BSD
|
||||
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
|
2
roles/elk/defaults/main.yml
Normal file
2
roles/elk/defaults/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# defaults file for roles/elk
|
0
roles/elk/files/.env
Normal file
0
roles/elk/files/.env
Normal file
50
roles/elk/files/compose.yml
Normal file
50
roles/elk/files/compose.yml
Normal file
|
@ -0,0 +1,50 @@
|
|||
services:
|
||||
elasticsearch:
|
||||
image: elasticsearch:7.16.1
|
||||
volumes:
|
||||
- ./configs/elasticsearch/config.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
|
||||
- ./docker_volumes/elasticsearch/data:/usr/share/elasticsearch/data
|
||||
environment:
|
||||
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
|
||||
ELASTIC_USERNAME: "elastic"
|
||||
ELASTIC_PASSWORD: "MyPw123"
|
||||
discovery.type: single-node
|
||||
# networks:
|
||||
# - elk
|
||||
ports:
|
||||
- "9200:9200"
|
||||
- "9300:9300"
|
||||
|
||||
logstash:
|
||||
image: logstash:7.16.2
|
||||
volumes:
|
||||
- ./configs/logstash/config.yml:/usr/share/logstash/config/logstash.yml:ro
|
||||
# volumes:
|
||||
# - ./configs/logstash/config.yml:/usr/share/logstash/config/logstash.yml:ro
|
||||
# - ./configs/logstash/pipelines.yml:/usr/share/logstash/config/pipelines.yml:ro
|
||||
# - ./configs/logstash/pipelines:/usr/share/logstash/config/pipelines:ro
|
||||
environment:
|
||||
LS_JAVA_OPTS: "-Xmx512m -Xms512m"
|
||||
ports:
|
||||
- "5044:5044"
|
||||
- "5000:5000"
|
||||
- "9600:9600"
|
||||
# networks:
|
||||
# - elk
|
||||
depends_on:
|
||||
- elasticsearch
|
||||
|
||||
kibana:
|
||||
image: kibana:7.16.1
|
||||
depends_on:
|
||||
- elasticsearch
|
||||
volumes:
|
||||
- ./configs/kibana/config.yml:/usr/share/kibana/config/kibana.yml:ro
|
||||
# networks:
|
||||
# - elk
|
||||
ports:
|
||||
- "5601:5601"
|
||||
|
||||
# networks:
|
||||
# elk:
|
||||
# driver: bridge
|
5
roles/elk/files/configs/elasticsearch/config.yml
Normal file
5
roles/elk/files/configs/elasticsearch/config.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
cluster.name: "elk"
|
||||
network.host: 0.0.0.0 # Для корректной работы внутри контейнера
|
||||
|
||||
xpack.security.enabled: true # Для поддержки функционала, обеспечивающего безопасность кластера
|
||||
xpack.license.self_generated.type: basic # Типа лицензии "basic" для наших нужд хватит с головой
|
15
roles/elk/files/configs/filebeat/config.yml
Normal file
15
roles/elk/files/configs/filebeat/config.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
filebeat.inputs:
|
||||
- type: log
|
||||
enabled: true
|
||||
# Я запущу filebeat в докере и проброшу логи приложения по данному пути
|
||||
paths:
|
||||
- /host_metrics_app/host_metrics_app.log
|
||||
# В fields мы можем указать дополнительные поля, а затем в logstash вытаскивать их
|
||||
# и делать какую-нибудь дополнительную работу с логами
|
||||
fields:
|
||||
# Название нашего сервиса
|
||||
service: host_metrics_app
|
||||
|
||||
output.logstash:
|
||||
# Будьте внимательны при запуске вне докера и вместо logstash укажите правильный адрес хоста с logstash.
|
||||
hosts: ["logstash:5044"]
|
8
roles/elk/files/configs/kibana/config.yml
Normal file
8
roles/elk/files/configs/kibana/config.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
server.name: kibana
|
||||
server.host: 0.0.0.0
|
||||
server.publicBaseUrl: "http://localhost:5601"
|
||||
monitoring.ui.container.elasticsearch.enabled: true # Для корректного сбора метрик с elastic search, запущенного в контейнере
|
||||
|
||||
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
|
||||
elasticsearch.username: elastic
|
||||
elasticsearch.password: MyPw123
|
1
roles/elk/files/configs/logstash/config.yml
Normal file
1
roles/elk/files/configs/logstash/config.yml
Normal file
|
@ -0,0 +1 @@
|
|||
http.host: "0.0.0.0"
|
|
@ -0,0 +1,42 @@
|
|||
# Логи будут прилетать из beats'ов по порту 5044
|
||||
input {
|
||||
beats {
|
||||
port => 5044
|
||||
}
|
||||
}
|
||||
|
||||
filter {
|
||||
# Дропаем лог, если он пришел от неизвестного нам сервиса (по желанию)
|
||||
# Ниже я два раза указал host_metrics_app в списке - это не опечатка. Какого-то лешего в условии, в массиве должно быть минимум 2 элемента.
|
||||
# Так как приложение у нас одно - просто дублируем
|
||||
# Поле service у нас появится благодаря конфигурированию Filebeat
|
||||
if [fields][service] not in ["host_metrics_app", "host_metrics_app"] {
|
||||
drop {}
|
||||
}
|
||||
# Оригинальный json-лог, который был сгенерирован вашим приложением, будет лежать по ключу message
|
||||
# (из filebeat'а логи прилетают не в чистом виде)
|
||||
json {
|
||||
source => "message"
|
||||
}
|
||||
# Говорим logstash'у, чтобы в качестве timestamp'а лога он брал именно наш timestamp
|
||||
# (в моем случае поле asctime в теле сообщения в формате "yyyy-MM-dd HH:mm:ss.SSS" и часовом поясе UTC)
|
||||
# и затем подтирал поле asctime.
|
||||
date {
|
||||
match => ["asctime", "yyyy-MM-dd HH:mm:ss.SSS"]
|
||||
timezone => "UTC"
|
||||
target => "@timestamp"
|
||||
remove_field => ["asctime"]
|
||||
}
|
||||
}
|
||||
|
||||
output {
|
||||
# Отображаем лог в stdout (поиграйтесь и удалите данную строку)
|
||||
stdout {}
|
||||
# Пушим лог в elasticsearch, индекс будет создан автоматически по названию сервиса и текущей дате
|
||||
elasticsearch {
|
||||
hosts => "elasticsearch:9200"
|
||||
index => "logs_%{[fields][service]}-%{+YYYY.MM.dd}"
|
||||
user => "elastic"
|
||||
password => "MyPw123"
|
||||
}
|
||||
}
|
2
roles/elk/handlers/main.yml
Normal file
2
roles/elk/handlers/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# handlers file for roles/elk
|
34
roles/elk/meta/main.yml
Normal file
34
roles/elk/meta/main.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
galaxy_info:
|
||||
author: your name
|
||||
description: your role description
|
||||
company: your company (optional)
|
||||
|
||||
# If the issue tracker for your role is not on github, uncomment the
|
||||
# next line and provide a value
|
||||
# issue_tracker_url: http://example.com/issue/tracker
|
||||
|
||||
# Choose a valid license ID from https://spdx.org - some suggested licenses:
|
||||
# - BSD-3-Clause (default)
|
||||
# - MIT
|
||||
# - GPL-2.0-or-later
|
||||
# - GPL-3.0-only
|
||||
# - Apache-2.0
|
||||
# - CC-BY-4.0
|
||||
license: license (GPL-2.0-or-later, MIT, etc)
|
||||
|
||||
min_ansible_version: 2.1
|
||||
|
||||
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||
# min_ansible_container_version:
|
||||
|
||||
galaxy_tags: []
|
||||
# List tags for your role here, one per line. A tag is a keyword that describes
|
||||
# and categorizes the role. Users find roles by searching for tags. Be sure to
|
||||
# remove the '[]' above, if you add tags to this list.
|
||||
#
|
||||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||
# Maximum 20 tags per role.
|
||||
|
||||
dependencies: []
|
||||
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||
# if you add dependencies to this list.
|
28
roles/elk/tasks/main.yml
Normal file
28
roles/elk/tasks/main.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
- name: Creates directory
|
||||
file:
|
||||
path: /opt/elk/{{ item }}
|
||||
state: directory
|
||||
recurse: yes
|
||||
loop:
|
||||
- configs/elasticsearch
|
||||
- configs/kibana
|
||||
- configs/logstash
|
||||
|
||||
- name: copy Docker Compose files
|
||||
copy:
|
||||
src: files/{{ item }}
|
||||
dest: /opt/elk/{{ item }}
|
||||
loop:
|
||||
- compose.yml
|
||||
- configs/elasticsearch/config.yml
|
||||
- configs/kibana/config.yml
|
||||
- configs/logstash/config.yml
|
||||
|
||||
# use files parameter to use multiple docker-compose.yml files
|
||||
# mind the _v2 suffix
|
||||
- name: deploy Docker Compose stack
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /opt/elk
|
||||
files:
|
||||
- compose.yml
|
2
roles/elk/tests/inventory
Normal file
2
roles/elk/tests/inventory
Normal file
|
@ -0,0 +1,2 @@
|
|||
localhost
|
||||
|
5
roles/elk/tests/test.yml
Normal file
5
roles/elk/tests/test.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
roles:
|
||||
- roles/elk
|
2
roles/elk/vars/main.yml
Normal file
2
roles/elk/vars/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# vars file for roles/elk
|
Loading…
Add table
Reference in a new issue