Created
January 28, 2025 20:14
-
-
Save eryabyshev/4b68716add0a61ada4b583bd1e70452d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Вот исправленный текст с добавлением структуры в первый абзац: | |
| --- | |
| **Как объединить Ubuntu WSL, Docker и Filebeat** | |
| Этот гайд поможет вам объединить Ubuntu WSL, Docker и Filebeat. Иногда бывает полезно развернуть что-нибудь внутри WSL и отправить логи в Elasticsearch. Для этого мы выполним следующие шаги: | |
| 1. Смонтируем UNC-путь к Docker Desktop. | |
| 2. Установим и настроим Filebeat. | |
| 3. Проверим, что Filebeat работает корректно. | |
| **Дано:** | |
| - Windows 11 | |
| - WSL 2 | |
| - Docker Desktop 4.37.1 | |
| --- | |
| **1. Смонтируйте UNC-путь к Docker Desktop** | |
| ``` | |
| sudo mkdir /mnt/docker-desktop-data | |
| sudo mount -t drvfs '\\wsl.localhost\docker-desktop\mnt' /mnt/docker-desktop-data/ | |
| ``` | |
| **2. Установите Filebeat** | |
| **3. Сконфигурируйте `filebeat.yaml`** | |
| ```yaml | |
| filebeat.autodiscover: # Filebeat сам будет искать контейнеры | |
| providers: | |
| - type: docker | |
| templates: | |
| - condition.contains: | |
| docker.container.name: super_backend # название контейнера, с которого хотим собирать логи | |
| config: | |
| - type: container | |
| paths: | |
| - "/mnt/docker-desktop-data/docker-desktop-disk/data/docker/containers/${data.docker.container.id}/*.log" | |
| containers.ids: | |
| - "${data.docker.container.id}" | |
| exclude_lines: [ "^\\s+[\\-`('.|_]" ] | |
| fields: | |
| app_name: super_backend | |
| - condition.contains: | |
| docker.container.name: mega_parser | |
| config: | |
| - type: container | |
| paths: | |
| - "/mnt/docker-desktop-data/docker-desktop-disk/data/docker/containers/${data.docker.container.id}/*.log" | |
| containers.ids: | |
| - "${data.docker.container.id}" | |
| exclude_lines: [ "^\\s+[\\-`('.|_]" ] | |
| fields: | |
| app_name: mega_parser | |
| # тут может быть сколько угодно контейнеров | |
| processors: | |
| - drop_fields: | |
| fields: [ 'docker.container.labels' ] | |
| - decode_json_fields: | |
| fields: [ 'message' ] | |
| target: "" | |
| overwrite_keys: true | |
| setup.kibana.host: "kibana.your-host.ru/" # URL вашей Kibana | |
| setup.kibana.protocol: "http" | |
| #================================ Outputs ====================================== | |
| # Configure what output to use when sending the data collected by the beat. | |
| #-------------------------- Elasticsearch output ------------------------------- | |
| output.elasticsearch: | |
| enabled: true | |
| hosts: ["http://elasticsearch.your-host.ru"] | |
| username: "elastic" | |
| password: "на_горшке_сидел_король" | |
| indices: | |
| - index: "%{[fields.app_name]}-%{+yyyy.MM.dd}" | |
| ``` | |
| **4. Перезапустите Filebeat** | |
| ``` | |
| systemctl restart filebeat | |
| ``` | |
| **5. Проверьте, что Filebeat работает корректно** | |
| ``` | |
| cat /var/log/filebeat/filebeat | |
| ``` | |
| --- | |
| **Это всё!** | |
| Я потратил на это половину рабочего дня и надеюсь, что этот гайд сэкономит ваше время. 😊 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment