Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wjx0912/03779bf38dff53e72fae2ae2a2104ce1 to your computer and use it in GitHub Desktop.

Select an option

Save wjx0912/03779bf38dff53e72fae2ae2a2104ce1 to your computer and use it in GitHub Desktop.
Cross-compile Elastic Filebeat for ARM with docker. Works on Raspberry Pi 2 and 3.

Elastic does not provide Filebeat binaries for ARMv7. Luckily, Filebeat can easily be cross-compiled with:

# ----- Instantiate an immutable Go container for cross-compilation ----- #
mkdir build && cd $_
docker run -it --rm -v `pwd`:/build golang:1.11.4 /bin/bash

# ----- Inside Go container ----- #
go get github.com/elastic/beats
cd /go/src/github.com/elastic/beats/filebeat/
git checkout -b v6.5.4
GOARCH=arm go build
GOARCH=arm64 go build
cp filebeat /build
exit

# ----- Verify the output file ----- #
file filebeat
#filebeat: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped

The newly built Filebeat binary can then be uploaded to the remote PCM3, for example with http://transfer.sh

On the PCM3:

@wjx0912
Copy link
Copy Markdown
Author

wjx0912 commented Dec 20, 2018

before go get, set proxy for docker
export https_proxy=192.168.1.93:1080
export http_proxy=192.168.1.93:1080

@romnovi
Copy link
Copy Markdown

romnovi commented Nov 19, 2019

I got error:

root@6b3f8de648f0:/go/src/github.com/elastic/beats/filebeat# GOARCH=arm go build
# github.com/elastic/beats/filebeat/input/kafka
input/kafka/input.go:201:10: undefined: strings.ReplaceAll

How did you compile?

@chapinb
Copy link
Copy Markdown

chapinb commented Jan 7, 2020

Looks like its an issue where golang in apt repos is currently v1.11.6, where strings.ReplaceAll became available in go v1.12 (per codewars/codewars.com#1861). Following this gist, I was able to get things working: https://gist.github.com/bigsan/c936451ed1a5b18bb8b0d7e8cc3e7212

@joariasl
Copy link
Copy Markdown

joariasl commented Jul 3, 2020

I have extended the file with the systemd configuration to start as service https://gist.github.com/joariasl/153a1d5253dc938429e2e5936339959a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment