Installing the Graylog Collector Sidecar
Container logs are scattered across the filesystem and don’t make their way into Graylog on their own. To bridge that gap, this post walks through configuring the Graylog Collector Sidecar so the logs under /var/log/containers end up in Graylog.
We start on the Graylog side. Connect to a running Graylog2 server at graylog:9000, then open:
System -> Inputs -> Beats, and after selecting it:
- Bind 0.0.0.0
- Port 5044 (the chosen port needs to be opened in the environment where Graylog2 runs. For Docker and k8s, the port must be exposed.)
This input is what the collector-sidecar will forward the logs from /var/log/containers into, which is exactly why we set it up first.
With the input ready, we move on to the collector-sidecar settings:
System -> Collectors -> Manage Configuration -> Create Configuration, where we create a collector.
Add docker to the Tag field and update it.
Within this collector’s settings, in the Beats tab, we define where the logs go and where they come from:
- Configure beats outputs -> create output
- Type: Filebeat beats output
- Hosts: the Graylog2 public IP and port
- Configure beats inputs -> create input
- Forward to: the beats output we created above
- Type: filebeat file input
- Path to logfile: [’/var/log/containers/*.log']
Since the collection is handled by filebeat, we also give it a filebeat.yml through a snippet:
- Define beats snippets -> create snippet
- Backend: filebeat
The snippet itself looks like this:
filebeat:
prospectors:
- document_type: log
encoding: plain
fields:
collector_node_id: graylog-collector-sidecar
gl2_source_collector: df679aa2-ecdf-477a-9bf1-0bbd5e80b163
ignore_older: 0
input_type: log
paths:
- /var/log/containers/*.log
scan_frequency: 10s
tail_files: true
symlinks: true ## symlink olmazsa container logları okunamıyor.
output:
logstash:
hosts:
- graylogipadresi:5044 ## 5044 üstte oluşturduğumuz system-input port adresi
path:
data: /var/cache/graylog/collector-sidecar/filebeat/data
logs: /var/log/graylog/collector-sidecar
tags:
- linux
- docker
Now we need the sidecar itself so it can actually pick up the container logs and apply everything configured above. Grab it from the releases page:
https://github.com/Graylog2/collector-sidecar/releases
collector-sidecar-0.1.3.tar.gz
tar -xvf collector-sidecar-0.1.3.tar.gz
Inside the resulting folder, we create collector-sidecar.yml under /graylog/collector-sidecar/0.1.3/linux/amd64/.
collector-sidecar.yml
************************************************************************************************
server_url: http://graylogserverip:9000/api/
update_interval: 30
tls_skip_verify: true
send_status: true
list_log_files:
- /var/log
node_id: graylog-collector-sidecar
collector_id: file:/etc/graylog/collector-sidecar/collector-id
log_path: /var/log/graylog/collector-sidecar
log_rotation_time: 86400
log_max_age: 604800
tags:
- linux
- docker ##BURADAKİ TAG BEATS INPUT OLUŞTURURKEN EKLEDİĞİMİZ TAG OLMALI
backends:
- name: winlogbeat
enabled: false
binary_path: C:\Program Files\graylog\collector-sidecar\winlogbeat.exe
configuration_path: C:\Program Files\graylog\collector-sidecar\generated\winlogbeat.yml
- name: filebeat
enabled: true
binary_path: /usr/bin/filebeat ##filebeat binary dosyasının yeri
configuration_path: /root/graylog/collector-sidecar/0.1.3/linux/amd64/filebeat.yml
###FILEBEAT CONF DOSYASININ YERINI BELİRTMEK İÇİN. HER NE KADAR YUKARIDA SNIPPET EKLESEKTE KENDISI OVERRIDE EDEREK OLUŞTURMASI GEREKİYOR.
With the config in place, we can run the Graylog collector from the /graylog/collector-sidecar/0.1.3/linux/amd64 folder:
./graylog-collector -c collector-sidecar.yml // use -c to select collector-sidecar.yml
To confirm everything is working, head to Graylog -> System -> Collectors, where a “running” status will appear.
– Turkish Version –
Graylog Collector Sidecar Kurulumu
Container logları dosya sisteminin içine dağılmış durumda ve kendiliğinden Graylog’a ulaşmıyor. Bu boşluğu kapatmak için bu yazımızda Graylog Collector Sidecar yapılandırmasını yapıyor, /var/log/containers altındaki logları Graylog üzerine taşıyoruz.
İşe Graylog tarafından başlıyoruz. Çalışan bir Graylog2 server adresine graylog:9000 ile bağlanıp şu yolu açıyoruz:
System -> Inputs -> Beats seçtikten sonra
- Bind 0.0.0.0
- Port 5044 (burada seçilen port için Graylog2’nin çalıştığı ortamda port açılıyor. Docker ve k8s için port belirtilmeli.)
collector-sidecar, /var/log/containers içerisindeki logları işte bu input’a iletecek; bu yüzden onu en başta oluşturduk.
Input hazır olduğuna göre collector-sidecar ayarlarına geçiyoruz:
System -> Collectors -> Manage Configuration -> Create Configuration ile bir collector oluşturuyoruz.
Tag kısmına docker ekleyip update ediyoruz.
Bu collector’ün ayarları içerisinde, Beats sekmesinde logların nereye gideceğini ve nereden geleceğini tanımlıyoruz:
- Configure beats outputs -> create output
- Type: Filebeat beats output
- Hosts: Graylog2 public IP ve portu
- Configure beats inputs -> create input
- Forward to: üstte oluşturduğumuz beats output
- Type: filebeat file input
- Path to logfile: [’/var/log/containers/*.log']
Logları çekme işini filebeat yaptığı için ona bir snippet üzerinden filebeat.yml de veriyoruz:
- Define beats snippets -> create snippet
- Backend: filebeat
Snippet’in kendisi şöyle:
filebeat:
prospectors:
- document_type: log
encoding: plain
fields:
collector_node_id: graylog-collector-sidecar
gl2_source_collector: df679aa2-ecdf-477a-9bf1-0bbd5e80b163
ignore_older: 0
input_type: log
paths:
- /var/log/containers/*.log
scan_frequency: 10s
tail_files: true
symlinks: true ## symlink olmazsa container logları okunamıyor.
output:
logstash:
hosts:
- graylogipadresi:5044 ## 5044 üstte oluşturduğumuz system-input port adresi
path:
data: /var/cache/graylog/collector-sidecar/filebeat/data
logs: /var/log/graylog/collector-sidecar
tags:
- linux
- docker
Şimdi container loglarının çekilebilmesi ve üstte yapılan ayarların uygulanabilmesi için sidecar’ın kendisine ihtiyacımız var. Onu releases sayfasından alıyoruz:
https://github.com/Graylog2/collector-sidecar/releases
collector-sidecar-0.1.3.tar.gz
tar -xvf collector-sidecar-0.1.3.tar.gz
Çıkan klasörde /graylog/collector-sidecar/0.1.3/linux/amd64/ altında collector-sidecar.yml oluşturuyoruz.
collector-sidecar.yml
************************************************************************************************
server_url: http://graylogserverip:9000/api/
update_interval: 30
tls_skip_verify: true
send_status: true
list_log_files:
- /var/log
node_id: graylog-collector-sidecar
collector_id: file:/etc/graylog/collector-sidecar/collector-id
log_path: /var/log/graylog/collector-sidecar
log_rotation_time: 86400
log_max_age: 604800
tags:
- linux
- docker ##BURADAKİ TAG BEATS INPUT OLUŞTURURKEN EKLEDİĞİMİZ TAG OLMALI
backends:
- name: winlogbeat
enabled: false
binary_path: C:\Program Files\graylog\collector-sidecar\winlogbeat.exe
configuration_path: C:\Program Files\graylog\collector-sidecar\generated\winlogbeat.yml
- name: filebeat
enabled: true
binary_path: /usr/bin/filebeat ##filebeat binary dosyasının yeri
configuration_path: /root/graylog/collector-sidecar/0.1.3/linux/amd64/filebeat.yml
###FILEBEAT CONF DOSYASININ YERINI BELİRTMEK İÇİN. HER NE KADAR YUKARIDA SNIPPET EKLESEKTE KENDISI OVERRIDE EDEREK OLUŞTURMASI GEREKİYOR.
Config yerine oturduğuna göre Graylog collector’ü /graylog/collector-sidecar/0.1.3/linux/amd64 klasörünün altından çalıştırabiliriz:
./graylog-collector -c collector-sidecar.yml // -c ile collector-sidecar.yml seçilmeli
Her şeyin çalıştığını doğrulamak için Graylog -> System -> Collectors altına bakıyoruz; burada “running” ibaresi çıkacaktır.