Forem

Beatriz Oliveira for Sysadminas

Posted on

Como coletar logs do NGINX com o Filebeat

O que é o NGINX?

O NGINX é um servidor web open source que também pode ser utilizado como load balancer HTTP, proxy de e-mail (IMAP, POP3 e SMTP) e também como proxy reverso.

Para conhecer mais sobre o projeto, acesse a sua página oficial aqui.

Utilizando o Filebeat para coletar os logs do NGINX

Ao utilizar o módulo NGINX do Filebeat você consegue coletar e analisar os logs de erro e acesso que são criados pelo NGINX.
Para saber mais sobre esse módulo, acesse a documentação aqui

Instalação e configuração do Filebeat

  • Instale o Filebeat:

Windows: PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-filebeat.ps1
Linux: sudo rpm -vi filebeat-7.10.1-x86_64.rpm

  • Acesse o arquivo de configuração do Filebeat:

Windows: C:\Program Files\Filebeat\filebeat.yml
Linux: /etc/filebeat/filebeat.yml

Insira nele as informações de conexão com o Elasticsearch e com o Kibana:

output.elasticsearch:
  hosts: ["url_do_elasticsearch:9200"]
setup.kibana:
  host: ["url_do_kibana:5601"]
Enter fullscreen mode Exit fullscreen mode
  • Habilite e configure o módulo :
    Windows: .\filebeat.exe modules enable nginx
    Linux: sudo filebeat modules enable nginx

  • Habilite e configure o módulo :
    Windows: .\filebeat.exe modules enable nginx
    Linux: sudo filebeat modules enable nginx

  • Para modificar as configurações do módulo, altere o arquivo nginx.yml:

Windows: modules.d/nginx.yml
Linux: /etc/filebeat/modules.d/nginx.yml

Por padrão, o arquivo vem com as seguintes informações e é aqui que você especifica o caminho para o seu diretório de logs:

# Module: nginx
# Docs: https://www.elastic.co/guide/en/beats/filebeat/7.10/filebeat-module-nginx.html
- module: nginx
  # Access logs
  access:
    enabled: true
# Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    #var.paths: ["/diretório/do/log/nginx/access.log*"]
# Error logs
  error:
    enabled: true
# Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    #var.paths: ["/diretório/do/log/nginx/error.log*"]
# Ingress-nginx controller logs. This is disabled by default. It could be used in Kubernetes environments to parse ingress-nginx logs
  ingress_controller:
    enabled: false
# Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    #var.paths: ["/diretório/do/log/nginx/ingress.log"]
Enter fullscreen mode Exit fullscreen mode
  • Carregue os dashboards do módulo:

Windows: .\filebeat.exe setup
Linux: sudo filebeat setup

  • Inicie o serviço do Filebeat:

Windows: Start-Service filebeat
Linux: sudo service filebeat start

Depois disso, você conseguirá ver os logs do seu ambiente no discover, além de ter dashboards com informações e métricas do seu NGINX.

Alt Text

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay